Difference between revisions of "How to fetch Nixpkgs with an empty NIX PATH"
From NixOS Wiki
Gabriel439 (talk | contribs) (Show how to simplify the recipe if one doesn't need to support pre-2.0 Nix) |
m (rollback unauthorized mass edits) Tag: Rollback |
||
(4 intermediate revisions by 3 users not shown) | |||
Line 1: | Line 1: | ||
− | + | You can fetch Nixpkgs with an empty <code>NIX_PATH</code>. This | |
comes in handy if you want to remove impure references to the <code>NIX_PATH</code> from | comes in handy if you want to remove impure references to the <code>NIX_PATH</code> from | ||
− | your code base | + | your code base. |
− | + | To do so, you can use <code>builtins.fetchTarball</code>, like this: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
<syntaxhighlight lang="nix"> | <syntaxhighlight lang="nix"> | ||
let | let | ||
− | + | nixpkgs = builtins.fetchTarball { | |
− | + | url = "https://github.com/NixOS/nixpkgs/archive/3389f23412877913b9d22a58dfb241684653d7e9.tar.gz"; | |
− | |||
− | |||
sha256 = "0wgm7sk9fca38a50hrsqwz6q79z35gqgb9nw80xz7pfdr4jy9pf8"; | sha256 = "0wgm7sk9fca38a50hrsqwz6q79z35gqgb9nw80xz7pfdr4jy9pf8"; | ||
}; | }; | ||
Line 73: | Line 18: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | + | … replacing <code>3389f2…</code> with the desired revision of Nixpkgs and replacing <code>0wgm7s…</code> with the corresponding SHA256 hash. | |
− | + | You can use the following command to obtain the correct SHA256 hash to use if you prefer not to use trial and error: | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | <syntaxhighlight lang=" | + | <syntaxhighlight lang="bash"> |
− | + | $ nix-prefetch-url --unpack "https://github.com/NixOS/nixpkgs/archive/${REVISION}.tar.gz" | |
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
− | |||
</syntaxhighlight> | </syntaxhighlight> | ||
[[Category:Nix]] [[Category:Nixpkgs]] [[Category:Cookbook]] | [[Category:Nix]] [[Category:Nixpkgs]] [[Category:Cookbook]] |
Latest revision as of 10:55, 6 April 2024
You can fetch Nixpkgs with an empty NIX_PATH
. This
comes in handy if you want to remove impure references to the NIX_PATH
from
your code base.
To do so, you can use builtins.fetchTarball
, like this:
let
nixpkgs = builtins.fetchTarball {
url = "https://github.com/NixOS/nixpkgs/archive/3389f23412877913b9d22a58dfb241684653d7e9.tar.gz";
sha256 = "0wgm7sk9fca38a50hrsqwz6q79z35gqgb9nw80xz7pfdr4jy9pf8";
};
pkgs = import nixpkgs { config = {}; };
in
...
… replacing 3389f2…
with the desired revision of Nixpkgs and replacing 0wgm7s…
with the corresponding SHA256 hash.
You can use the following command to obtain the correct SHA256 hash to use if you prefer not to use trial and error:
$ nix-prefetch-url --unpack "https://github.com/NixOS/nixpkgs/archive/${REVISION}.tar.gz"