From 68cc6fa178d6598b63567564981ab389538e6998 Mon Sep 17 00:00:00 2001 From: cinereal Date: Mon, 1 Jun 2026 21:38:02 +0200 Subject: [PATCH 1/2] document pinning nixpkgs pin for NixOS by npins from `system.nix` Signed-off-by: cinereal --- .../guides/recipes/dependency-management.md | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/source/guides/recipes/dependency-management.md b/source/guides/recipes/dependency-management.md index 7c4161776..08ce4134c 100644 --- a/source/guides/recipes/dependency-management.md +++ b/source/guides/recipes/dependency-management.md @@ -109,11 +109,26 @@ All the imported entries will be updated, so they won't necessarily point to the ## Managing NixOS configurations -NixOS relies on the `NIX_PATH` environment variable to locate `nixpkgs`, which defaults to using channels. -To instead use a `nixpkgs` version managed by `npins`, one can manually override this environment variable on system rebuilds: +NixOS defaults to using channels to locate `nixpkgs`. +You can instead pin a version using `npins` from the `system.nix` entrypoint: -```bash -sudo NIX_PATH="nixos-config=configuration.nix:nixpkgs=$(nix-instantiate --raw --eval npins -A nixpkgs.outPath)" nixos-rebuild switch +```nix +let + sources = import ./npins; +in +import "${sources.nixpkgs}/nixos" { + configuration = ./configuration.nix; +} +``` + +You can then disable channels in your configuration: + +```nix +# configuration.nix +{ + # ... + nix.channel.enable = false; +} ``` To make such pinned dependencies available as [look-up paths](https://nix.dev/tutorials/nix-language.html#lookup-paths) (like ``) while using the NixOS configuration, one may use: @@ -126,7 +141,6 @@ let in { # ... - nix.channel.enable = false; nix.nixPath = lib.mapAttrsToList (k: v: "${k}=${v}") sources; } ``` From 5416f1220ad37cf17216efd3e4eb6987efcd83cd Mon Sep 17 00:00:00 2001 From: cinereal Date: Wed, 3 Jun 2026 13:47:25 +0200 Subject: [PATCH 2/2] explain npins for both new and old nixos Signed-off-by: cinereal --- source/guides/recipes/dependency-management.md | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/source/guides/recipes/dependency-management.md b/source/guides/recipes/dependency-management.md index 08ce4134c..c1fee0de2 100644 --- a/source/guides/recipes/dependency-management.md +++ b/source/guides/recipes/dependency-management.md @@ -110,7 +110,7 @@ All the imported entries will be updated, so they won't necessarily point to the ## Managing NixOS configurations NixOS defaults to using channels to locate `nixpkgs`. -You can instead pin a version using `npins` from the `system.nix` entrypoint: +You can instead pin a version using `npins` from the `system.nix` entrypoint (available since 26.05): ```nix let @@ -121,7 +121,13 @@ import "${sources.nixpkgs}/nixos" { } ``` -You can then disable channels in your configuration: +Before NixOS 26.05's `system.nix` use: + +```bash +sudo NIX_PATH="nixos-config=configuration.nix:nixpkgs=$(nix-instantiate --raw --eval npins -A nixpkgs.outPath)" nixos-rebuild switch +``` + +If you use npins with `system.nix`, disable channels in your configuration: ```nix # configuration.nix