Illegal character error trying to use fetchurl

I’m trying to download a script from my Google Drive in configuration.nix. This is what it looks like:

enableSpeakersScript = builtins.fetchurl "";

However, I’m getting this error:

error: store path 'lc14bkx0v21irrc5j9538gvmvcyvgj0b-uc?export=download&id=1ncXzzwVGRL44RyUeRkBdglxByYqXJWNW' contains illegal character '&'

What am I doing wrong?

The resulting store path name is taken from the last URL component. This is the same issue as nix-prefetch-url - error: store path '<any-string>' contains illegal character '&' · Issue #8921 · NixOS/nix · GitHub

A reliable workaround (and a healthy pattern generally) is to specify the name explicitly as described here: Tilde (~) in path literal is illegal · Issue #7742 · NixOS/nix · GitHub


Just give it a name:

builtins.fetchurl { 
  url = "";
  name = "foo"; 

This way the store-path name is not computed based on the URL and you don’t get the invalid character in the store path.

1 Like