Skip to content

Instantly share code, notes, and snippets.

@CMCDragonkai
Last active February 24, 2023 09:34
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save CMCDragonkai/b5a37367094223e2d3c26b96644340f3 to your computer and use it in GitHub Desktop.
Save CMCDragonkai/b5a37367094223e2d3c26b96644340f3 to your computer and use it in GitHub Desktop.
Nix Fetching Functions #nix

Found all these from nix-repl. Use builtins.fetchTarball for nixpkgs pinning!

builtins.fetchurl
builtins.fetchTarball
pkgs.fetchFromBitbucket
pkgs.fetchFromGitHub
pkgs.fetchFromGitLab
pkgs.fetchFromRepoOrCz
pkgs.fetchFromSavannah
pkgs.fetchHex
pkgs.fetchMavenArtifact
pkgs.fetchNuGet
pkgs.fetchadc
pkgs.fetchbower
pkgs.fetchbzr
pkgs.fetchcvs
pkgs.fetchdarcs
pkgs.fetchegg
pkgs.fetchfossil
pkgs.fetchgit
pkgs.fetchgitLocal
pkgs.fetchgitPrivate
pkgs.fetchgitrevision
pkgs.fetchgx
pkgs.fetchhg
pkgs.fetchmail
pkgs.fetchmtn
pkgs.fetchpatch
pkgs.fetchsvn
pkgs.fetchsvnrevision
pkgs.fetchsvnssh
pkgs.fetchurl
pkgs.fetchurlBoot
pkgs.fetchzip

In order to use the above easily, make use of these convenience shell commands:

nix-prefetch-bzr
nix-prefetch-git
nix-prefetch-svn
nix-prefetch-cvs
nix-prefetch-hg
nix-prefetch-url

For example:

nix-prefetch-git https://github.com/iterative/dvc --rev 0.24.3

Pinning

You should be able to do this:

# use the resulting hash for fetchTarball
nix-prefetch-url --unpack https://github.com/NixOS/nixpkgs-channels/archive/00e56fbbee06088bf3bf82169032f5f5778588b7.tar.gz

Then in your shell.nix:

{
  pkgs ? import (fetchTarball {
    url = https://github.com/NixOS/nixpkgs-channels/archive/00e56fbbee06088bf3bf82169032f5f5778588b7.tar.gz;
    sha256 = "15pl5p3f14rw477qg316gjp9mqpvrr6501hqv3f50fzlcxn9d1b4";
  }) {}
}:
  with pkgs;
  stdenv.mkDerivation {
    name = "my-pinned-project";
  }

And how do you find the right hash to use? Just do this: http 'https://api.github.com/repos/NixOS/nixpkgs-channels/branches?per_page=100'. It will show you all the latest commit hash from each released channel (including the unstable channel).

@toraritte
Copy link

This NixOS discourse thread may also be helpful to get the right tarball URL for fetchTarball... and thanks a lot for this write-up! Had no clue that there are so many fetch... functions...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment