nmattia / niv

Easy dependency management for Nix projects
https://github.com/nmattia/niv
MIT License
1.55k stars 77 forks source link

Avoid invalid characters in file name (sanitise, or allow override) #262

Closed chriswarbo closed 4 years ago

chriswarbo commented 4 years ago

I've been porting my manual calls to fetchurl and fetchgit with niv and it works really well, but I've encountered the following problem when fetching Firefox:

$ niv add firefox -v 78.0.2 -t 'https://ftp.mozilla.org/pub/firefox/releases/<version>/mac-EME-free/en-GB/Firefox%20<version>.dmg'
Adding package firefox
  Writing new sources file
Done: Adding package firefox

The resulting sources.json gets this added:

    "firefox": {
        "sha256": "1l1b6m1i9hya4awsp6pwkjlpbpk2mnlcpnmll45dxb8qcc2dn6gx",
        "type": "file",
        "url": "https://ftp.mozilla.org/pub/firefox/releases/78.0.2/mac-EME-free/en-GB/Firefox%2078.0.2.dmg",
        "url_template": "https://ftp.mozilla.org/pub/firefox/releases/<version>/mac-EME-free/en-GB/Firefox%20<version>.dmg",
        "version": "78.0.2"
    },

However, the filename Firefox%2078.0.2.dmg fails when we try to use it from Nix:

nix-repl> with import <darwin> {}; pkgs.sources.firefox
error: The path name 'Firefox%2078.0.2.dmg' is invalid: the '%' character is invalid. Path names are alphanumeric and can include the symbols +-._?= and must not begin with a period. Note: If 'Firefox%2078.0.2.dmg' is a source file and you cannot rename it on disk, builtins.path { name = ... } can be used to give it an alternative name.

Swapping the %20 for a space also fails for the same reason.

This could be avoided by allowing the resulting name to be overridden via sources.json, but the default sources.nix doesn't seem to allow this at the moment. Alternatively, the name could be sanitised like the tarball type does (switching to that type doesn't work in this case, since it's not a tarball, so tar dies).

nmattia commented 4 years ago

Thanks! Can you try https://github.com/nmattia/niv/pull/265 ? this will set the name to firefox.