mirror of
https://github.com/NixOS/nix.dev.git
synced 2024-10-18 14:32:43 -04:00
e47b082d22
make generous use of admonitions
2.2 KiB
2.2 KiB
(ref-pinning-nixpkgs)=
Pinning Nixpkgs
Specifying remote Nix expressions, such as the one provided by Nixpkgs, can be done in several ways:
$NIX_PATH
environment variable-I
option to most of commands likenix-build
,nix-shell
, etc.fetchurl
,fetchTarball
,fetchGit
or Nixpkgs fetchers in Nix expressions
Possible URL values
-
Local file path:
./path/to/expression.nix
Using
./.
means that the expression is located in a filedefault.nix
the current directory. -
Pinned to a specific commit:
https://github.com/NixOS/nixpkgs/archive/eabc38219184cc3e04a974fe31857d8e0eac098d.tar.gz
-
Using the latest channel version, meaning all tests have passed:
http://nixos.org/channels/nixos-22.11/nixexprs.tar.xz
-
Shorthand syntax channels:
channel:nixos-22.11
-
Using the latest channel version, hosted by GitHub:
https://github.com/NixOS/nixpkgs/archive/nixos-22.11.tar.gz
-
Using the latest commit on the release branch, but not tested yet:
https://github.com/NixOS/nixpkgs/archive/release-21.11.tar.gz
Examples
-
$ nix-build -I ~/dev
-
$ nix-build -I nixpkgs=http://nixos.org/channels/nixos-22.11/nixexprs.tar.xz
-
$ nix-build -I nixpkgs=channel:nixos-22.11`
-
$ NIX_PATH=nixpkgs=http://nixos.org/channels/nixos-22.11/nixexprs.tar.xz nix-build ...
-
$ NIX_PATH=nixpkgs=channel:nixos-22.11 nix-build ...
-
In the Nix language:
let pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-22.11.tar.gz") {}; in pkgs.stdenv.mkDerivation { ... }