From 2661ed78e2d9d4b70123fe427193a82469219231 Mon Sep 17 00:00:00 2001 From: Ryan Yin Date: Fri, 29 Dec 2023 17:45:47 +0800 Subject: [PATCH] fix: flake registry & NIX_PATH --- docs/best-practices/nix-path-and-flake-registry.md | 10 ++++++---- docs/zh/best-practices/nix-path-and-flake-registry.md | 10 ++++++---- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/docs/best-practices/nix-path-and-flake-registry.md b/docs/best-practices/nix-path-and-flake-registry.md index 70a0ba4..1fff984 100644 --- a/docs/best-practices/nix-path-and-flake-registry.md +++ b/docs/best-practices/nix-path-and-flake-registry.md @@ -26,14 +26,16 @@ In daily use, we typically want the `nixpkgs` used in commands like `nix repl '< In your NixOS configuration, adding the following module will achieve the mentioned requirements: ```nix -{ - # Make `nix run nixpkgs#nixpkgs` use the same nixpkgs as the one used by this flake. +{lib, nixpkgs, ...}: { + # make `nix run nixpkgs#nixpkgs` use the same nixpkgs as the one used by this flake. nix.registry.nixpkgs.flake = nixpkgs; - nix.channel.enable = false; # disable nix-channel, we use flakes instead. + nix.channel.enable = false; # remove nix-channel related tools & configs, we use flakes instead. + # but NIX_PATH is still used by many useful tools, so we set it to the same value as the one used by this flake. # Make `nix repl ''` use the same nixpkgs as the one used by this flake. environment.etc."nix/inputs/nixpkgs".source = "${nixpkgs}"; - nix.nixPath = ["/etc/nix/inputs"]; + # https://github.com/NixOS/nix/issues/9574 + nix.settings.nix-path = lib.mkForce "nixpkgs=/etc/nix/inputs/nixpkgs"; } ``` diff --git a/docs/zh/best-practices/nix-path-and-flake-registry.md b/docs/zh/best-practices/nix-path-and-flake-registry.md index 83b71d4..ee84866 100644 --- a/docs/zh/best-practices/nix-path-and-flake-registry.md +++ b/docs/zh/best-practices/nix-path-and-flake-registry.md @@ -27,14 +27,16 @@ Flake Registry 是一个 Flake 注册中心,它可以帮助我们在使用 `ni 在你的 NixOS 配置中,添加如下 module 即可实现上述需求: ```nix -{ +{lib, nixpkgs, ...}: { # make `nix run nixpkgs#nixpkgs` use the same nixpkgs as the one used by this flake. nix.registry.nixpkgs.flake = nixpkgs; - nix.channel.enable = false; # disable nix-channel, we use flakes instead. + nix.channel.enable = false; # remove nix-channel related tools & configs, we use flakes instead. - # make `nix repl ''` use the same nixpkgs as the one used by this flake. + # but NIX_PATH is still used by many useful tools, so we set it to the same value as the one used by this flake. + # Make `nix repl ''` use the same nixpkgs as the one used by this flake. environment.etc."nix/inputs/nixpkgs".source = "${nixpkgs}"; - nix.nixPath = ["/etc/nix/inputs"]; + # https://github.com/NixOS/nix/issues/9574 + nix.settings.nix-path = lib.mkForce "nixpkgs=/etc/nix/inputs/nixpkgs"; } ```