FAQ/Pinning Nixpkgs: Difference between revisions
imported>Samueldr m Adds missing `;` |
imported>Lheckemann Describe use of builtins.fetchTarball |
||
Line 4: | Line 4: | ||
not impacted by other systems' requirements. | not impacted by other systems' requirements. | ||
== 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: | |||
<syntaxhighlight lang="nix"> | |||
import (builtins.fetchTarball { | |||
# Descriptive name to make the store path easier to identify | |||
name = "nixos-unstable-2018-09-12"; | |||
# Commit hash for nixos-unstable as of 2018-09-12 | |||
url = https://github.com/nixos/nixpkgs/archive/ca2ba44cab47767c8127d1c8633e2b581644eb8f.tar.gz; | |||
# Hash obtained using `nix-prefetch-url --unpack <url>` | |||
sha256 = "1jg7g6cfpw8qvma0y19kwyp549k1qyf11a5sg6hvn6awvmkny47v"; | |||
}) {} | |||
</syntaxhighlight> | |||
== Before 2.0 == | |||
The following code uses the host's Nixpkgs as a | |||
springboard to fetch and import a specific, pinned version of Nixpkgs. | springboard to fetch and import a specific, pinned version of Nixpkgs. | ||
This is safe because the specific code we're using from the variable | This is safe because the specific code we're using from the variable | ||
Line 25: | Line 42: | ||
sha256 = "0frhc7mnx88sird6ipp6578k5badibsl0jfa22ab9w6qrb88j825"; | sha256 = "0frhc7mnx88sird6ipp6578k5badibsl0jfa22ab9w6qrb88j825"; | ||
}; | }; | ||
in import pinnedPkgs {} | in import pinnedPkgs {} | ||
</syntaxhighlight> | </syntaxhighlight> | ||