Nurl: Generate Nix fetcher calls from repository URLs

Here is a quick example of what it does:

$ nurl https://github.com/nix-community/patsh v0.2.0 2>/dev/null
fetchFromGitHub {
  owner = "nix-community";
  repo = "patsh";
  rev = "v0.2.0";
  hash = "sha256-7HXJspebluQeejKYmVA7sy/F3dtU1gc4eAbKiPexMMA=";
}
Usage: nurl [OPTIONS] [URL] [REV]

Arguments:
  [URL]
          URL to the repository to be fetched

  [REV]
          The revision or reference to be fetched

Options:
  -S, --submodules[=<SUBMODULES>]
          Fetch submodules instead of using the fetcher's default

          [possible values: true, false]

  -f, --fetcher <FETCHER>
          Specify the fetcher function instead of inferring from the URL

          [possible values: builtins.fetchGit, fetchCrate, fetchFromBitbucket,
          fetchFromGitHub, fetchFromGitLab, fetchFromGitea, fetchFromGitiles,
          fetchFromRepoOrCz, fetchFromSourcehut, fetchHex, fetchPypi, fetchgit, fetchhg,
          fetchpatch, fetchpatch2, fetchsvn, fetchurl, fetchzip]

  -F, --fallback <FALLBACK>
          The fetcher to fall back to when nurl fails to infer it from the URL

          [default: fetchgit]
          [possible values: builtins.fetchGit, fetchCrate, fetchFromBitbucket,
          fetchFromGitHub, fetchFromGitLab, fetchFromGitea, fetchFromGitiles,
          fetchFromRepoOrCz, fetchFromSourcehut, fetchHex, fetchPypi, fetchgit, fetchhg,
          fetchpatch, fetchpatch2, fetchsvn, fetchurl, fetchzip]

  -n, --nixpkgs <NIXPKGS>
          Path to nixpkgs (in nix)

          [default: <nixpkgs>]

  -i, --indent <INDENT>
          Extra indentation (in number of spaces)

          [default: 0]

  -H, --hash
          Only output the hash

  -j, --json
          Output in json format

  -p, --parse
          Parse the url without fetching the hash, output in json format

          Note that --arg(-str) and --overwrite(-str) will be ignored silently

  -a, --arg <NAME> <EXPR>
          Additional arguments to pass to the fetcher

  -A, --arg-str <NAME> <STRING>
          Same as --arg, but accepts strings instead Nix expressions

  -o, --overwrite <NAME> <EXPR>
          Overwrite arguments in the final output, not taken into consideration when
          fetching the hash

          Note that nurl does not verify any of the overwrites, for the final output to
          be valid, the user should not overwrite anything that would change the hash

          Examples:
            --overwrite repo pname
            --overwrite rev version

  -O, --overwrite-str <NAME> <STRING>
          Same as --overwrite, but accepts strings instead Nix expressions

          Examples:
            --overwrite-str rev 'v${version}'
            --overwrite-str meta.homepage https://example.org

      --overwrite-rev <EXPR>
          Same as --overwrite (rev|tag|version) <EXPR>, depending on the rev-like
          attribute the fetcher uses

      --overwrite-rev-str <STRING>
          Same as --overwrite-str (rev|tag|version) <STRING>, depending on the rev-like
          attribute the fetcher uses

  -e, --expr <EXPR>
          Instead of fetching a URL, get the hash of a fixed-output derivation, implies
          --hash and ignores all other options

          Example: --expr '(import <nixpkgs> { }).nurl.src'

  -l, --list-fetchers
          List all available fetchers

  -L, --list-possible-fetchers
          List all fetchers that can be generated without --fetcher

  -s, --list-sep <SEPARATOR>
          Print out the listed fetchers with the specified separator, only used when
          --list-fetchers or --list-possible-fetchers is specified

  -h, --help
          Print help (see a summary with '-h')

  -V, --version
          Print version
32 Likes

Just released 0.4.0 with the long-awaited support for fetchurl and fetchzip! Here is the full changelog for this release:

Changes

  • Output tag = "..."; instead of rev for all supported fetchers (#395).
    To adapt to this change, instead of --overwrite(-str) rev <VALUE>, use --overwrite-rev <VALUE> or --overwrite-rev-str <VALUE>,
    which also works for fetchCrate and fetchHex.
  • fetchhg and fetchsvn now output hash instead of sha256

Features

  • fetchurl, fetchzip, fetchpatch, and fetchpatch2 support (#420)
  • Use a GitHub token for authorization if it exists (#388)
  • --overwrite-rev and --overwrite-rev-str as alternatives to --overwrite-rev(-str) (rev|tag|version) (#419)
  • fetchFromGitLab support for https://framagit.org (#428)
  • fetchFromGitea support for https://git.lix.systems (#428)
  • More colorful errors

Fixes

  • Add flakes to extra experimental features (#220)
  • Support subgroups with fetchFromGitLab (#410)
  • Group escaping with Nix 2.18+ and fetchFromGitLab
  • Fetch submodules correctly with fetchhg
9 Likes