1
0
Fork 0
mirror of https://github.com/NixOS/nix.dev.git synced 2024-10-18 14:32:43 -04:00
nix.dev/source/reference/pinning-nixpkgs.md

76 lines
1.9 KiB
Markdown
Raw Normal View History

2021-12-10 07:24:12 -05:00
(ref-pinning-nixpkgs)=
# Pinning Nixpkgs
Specifying remote Nix expressions, such as the one provided by Nixpkgs, can be done in several ways:
2021-12-10 07:24:12 -05:00
- [`-I` option](https://nixos.org/manual/nix/stable/command-ref/opt-common.html#opt-I) to most of commands like `nix-build`, `nix-shell`, etc.
- [`$NIX_PATH` environment variable](https://nixos.org/manual/nix/stable/command-ref/env-common.html#env-NIX_PATH)
- Using [builtins.fetchTarball](https://nixos.org/manual/nix/stable/expressions/builtins.html) to fetch a Nix expression at evaluation time
2021-12-10 07:24:12 -05:00
## Possible `URL` values
- Local file path.
2023-04-04 04:29:59 -04:00
Using `./.` means that the expression is located in a file `default.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 for `NIX_PATH` and `-I`:
```
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
```
2021-12-10 07:24:12 -05:00
## Examples
- ```shell-session
$ nix-build -I ~/dev
```
2021-12-10 07:24:12 -05:00
- ```shell-session
$ nix-build -I nixpkgs=http://nixos.org/channels/nixos-22.11/nixexprs.tar.xz`
```
2021-12-10 07:24:12 -05:00
- ```shell-session
$ nix-build -I nixpkgs=channel:nixos-22.11`
```
- ```shell-session
$ NIX_PATH=nixpkgs=http://nixos.org/channels/nixos-22.11/nixexprs.tar.xz nix-build ...`
```
2021-12-10 07:24:12 -05:00
- ```shell-session
$ NIX_PATH=nixpkgs=channel:nixos-22.11 nix-build ...`
```
- In the Nix language:
2021-12-10 07:24:12 -05:00
```nix
2021-12-10 07:24:12 -05:00
let
pkgs = import (fetchTarball "https://github.com/NixOS/nixpkgs/archive/nixos-22.11.tar.gz") {};
in pkgs.stdenv.mkDerivation { ... }
2021-12-10 07:24:12 -05:00
```