FAQ/Pinning Nixpkgs: Difference between revisions
imported>Lheckemann Describe use of builtins.fetchTarball |
imported>Lheckemann |
||
Line 6: | Line 6: | ||
== Nix 2.0 onwards == | == Nix 2.0 onwards == | ||
Nix 2.0 introduces new builtins, <code>fetchTarball</code> and <code>fetchGit</code>, which make it possible to fetch a version of nixpkgs without depending on an existing one: | Nix 2.0 introduces new builtins, <code>fetchTarball</code> and <code>fetchGit</code>, which make it possible to fetch a specific version of nixpkgs without depending on an existing one: | ||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
Line 16: | Line 16: | ||
# Hash obtained using `nix-prefetch-url --unpack <url>` | # Hash obtained using `nix-prefetch-url --unpack <url>` | ||
sha256 = "1jg7g6cfpw8qvma0y19kwyp549k1qyf11a5sg6hvn6awvmkny47v"; | sha256 = "1jg7g6cfpw8qvma0y19kwyp549k1qyf11a5sg6hvn6awvmkny47v"; | ||
}) {} | |||
</syntaxhighlight> | |||
Or, to use git for fetching (this has the advantage of being somewhat faster for updates, but is slower for the initial fetch): | |||
<syntaxhighlight lang="nix"> | |||
import (builtins.fetchGit { | |||
# Descriptive name to make the store path easier to identify | |||
name = "nixos-unstable-2018-09-12"; | |||
url = https://github.com/nixos/nixpkgs/; | |||
# Commit hash for nixos-unstable as of 2018-09-12 | |||
rev = "ca2ba44cab47767c8127d1c8633e2b581644eb8f"; | |||
}) {} | }) {} | ||
</syntaxhighlight> | </syntaxhighlight> |