From 5d2e4f01a5cc8b49c4a16372e8402598601ae0dc Mon Sep 17 00:00:00 2001 From: Konrad Malik Date: Wed, 14 Aug 2024 12:27:20 +0200 Subject: [PATCH] fix: nix-path, registry --- hosts/common/modules/nix/not-hm.nix | 7 +++ hosts/common/modules/nix/shared.nix | 72 +++++++++++++++-------------- 2 files changed, 45 insertions(+), 34 deletions(-) create mode 100644 hosts/common/modules/nix/not-hm.nix diff --git a/hosts/common/modules/nix/not-hm.nix b/hosts/common/modules/nix/not-hm.nix new file mode 100644 index 00000000..d1137077 --- /dev/null +++ b/hosts/common/modules/nix/not-hm.nix @@ -0,0 +1,7 @@ +{ inputs, ... }: +{ + # should be >= max-jobs + nix.nrBuildUsers = 16; + # Make `nix repl ''` use the same nixpkgs as the one used by this flake. + environment.etc."nix/inputs/nixpkgs".source = "${inputs.nixpkgs}"; +} diff --git a/hosts/common/modules/nix/shared.nix b/hosts/common/modules/nix/shared.nix index b3bda435..6eef2ec1 100644 --- a/hosts/common/modules/nix/shared.nix +++ b/hosts/common/modules/nix/shared.nix @@ -1,11 +1,15 @@ { - config, pkgs, lib, inputs, ... }: +let + isHomeManager = builtins.hasAttr "hm" lib; +in { + imports = lib.optionals (!isHomeManager) [ ./not-hm.nix ]; + nixpkgs = { overlays = [ ( @@ -25,38 +29,38 @@ permittedInsecurePackages = [ ]; }; }; - nix = - { - package = pkgs.nixVersions.latest; - settings = { - auto-optimise-store = lib.mkDefault true; - experimental-features = [ - "nix-command" - "flakes" - ]; - keep-derivations = true; - keep-outputs = true; - trusted-users = - [ "root" ] - ++ lib.optional pkgs.stdenvNoCC.isLinux "@wheel" ++ lib.optional pkgs.stdenvNoCC.isDarwin "@admin"; - extra-substituters = [ - "https://konradmalik.cachix.org" - "https://nix-community.cachix.org" - ]; - extra-trusted-public-keys = [ - "konradmalik.cachix.org-1:9REXmCYRwPNL0kAB0IMeTxnMB1Gl9VY5I8w7UVBTtSI=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs" - ]; - min-free = lib.mkDefault (10 * 1000 * 1000 * 1000); # 10gb - cores = lib.mkDefault 0; - max-jobs = lib.mkDefault "auto"; - }; - } - # below does not exist in plain home-manager - # but it will work for nixos config and for nix-darwin config - # this check is needed because of generic linux entry in homeConfigurations - // lib.optionalAttrs (builtins.hasAttr "nrBuildUsers" config.nix) { - # should be >= max-jobs - nrBuildUsers = 16; + nix = { + package = pkgs.nixVersions.latest; + # make `nix run nixpkgs#nixpkgs` use the same nixpkgs as the one used by this flake. + registry = { + nixpkgs.flake = inputs.nixpkgs; + nixpkgs-stable.flake = inputs.nixpkgs-stable; }; + settings = { + # NIX_PATH is still used by many useful tools, so we set it to the same value as the one used by this flake. + # https://github.com/NixOS/nix/issues/9574 + nix-path = lib.mkForce "nixpkgs=/etc/nix/inputs/nixpkgs"; + auto-optimise-store = lib.mkDefault true; + experimental-features = [ + "nix-command" + "flakes" + ]; + keep-derivations = true; + keep-outputs = true; + trusted-users = + [ "root" ] + ++ lib.optional pkgs.stdenvNoCC.isLinux "@wheel" ++ lib.optional pkgs.stdenvNoCC.isDarwin "@admin"; + extra-substituters = [ + "https://konradmalik.cachix.org" + "https://nix-community.cachix.org" + ]; + extra-trusted-public-keys = [ + "konradmalik.cachix.org-1:9REXmCYRwPNL0kAB0IMeTxnMB1Gl9VY5I8w7UVBTtSI=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs" + ]; + min-free = lib.mkDefault (10 * 1000 * 1000 * 1000); # 10gb + cores = lib.mkDefault 0; + max-jobs = lib.mkDefault "auto"; + }; + }; }