nix: avoid sending nixpkgs on non-builder target
authorJulien Moutinho <julm+sourcephile-nix@sourcephile.fr>
Fri, 22 Oct 2021 20:47:24 +0000 (22:47 +0200)
committerJulien Moutinho <julm+sourcephile-nix@sourcephile.fr>
Fri, 22 Oct 2021 20:47:24 +0000 (22:47 +0200)
flake.nix
hosts/losurdo.nix
hosts/losurdo/networking/wireguard/intranet.nix
nixos/defaults.nix
nixos/profiles/systems/builder.nix [new file with mode: 0644]

index b66069db16fa2b1fd95252d8bcd1bcfabf4612bc..d0532c16142fbe3bd0169c2dd9aaad0d1d2add38 100644 (file)
--- a/flake.nix
+++ b/flake.nix
@@ -34,11 +34,13 @@ outputs = inputs: let
   hosts = builtins.mapAttrs (hostName: hostConfig:
     let cfg = import hostConfig { inherit inputs hostName; }; in
     import (nixpkgs + "/nixos/lib/eval-config.nix") (cfg // {
-      extraArgs = {
+      specialArgs = {
         inherit hostName inputs;
+        private = "/root/private"; # Kept out of /nix/store
+      };
+      extraArgs = {
         hosts = inputs.self.nixosConfigurations;
         host = inputs.self.nixosConfigurations.${hostName}.extraArgs;
-        private = "/root/private"; # Kept out of /nix/store
       } // (cfg.extraArgs or {});
       modules = cfg.modules ++ [
         inputs.home-manager.nixosModules.home-manager
@@ -51,10 +53,8 @@ outputs = inputs: let
             inherit hostName;
           };
         }
-        ({pkgs, ...}: {
-          nix.registry.nixpkgs.flake = nixpkgs;
+        ({ pkgs, ... }: {
           nix.package = pkgs.nixUnstable;
-          nix.extraOptions = "experimental-features = nix-command flakes";
           nixpkgs.overlays =
             import nixpkgs/overlays.nix ++
             import (inputs.julm-nix + "/nixpkgs/overlays.nix");
index 67d009e2c2fc7e9e6b861168ba68f69142e01c80..6ac30c34febf3c7fb30287696eaebefa52ba3bbe 100644 (file)
@@ -10,6 +10,7 @@ extraArgs = {
 };
 modules = [
   ../nixos/defaults.nix
+  ../nixos/profiles/systems/builder.nix
   losurdo/acme.nix
   losurdo/apc.nix
   losurdo/debug.nix
index 3a1f58a782beaad7a0cc59de2de84429cd9e4a7f..29761404a2c457954060243c0e7a94184567581c 100644 (file)
@@ -1,4 +1,4 @@
-{ pkgs, lib, config, hosts, inputs, ... }:
+{ pkgs, lib, config, inputs, ... }:
 let
   inherit (config.security) gnupg;
   inherit (config.boot) initrd;
index c4272f142a23529b4b894bda06903e6fbf96edc6..f185ff098e200b4c1b5ee60066033e8e664c57e7 100644 (file)
@@ -1,4 +1,4 @@
-{ inputs, pkgs, lib, config, ... }:
+{ pkgs, lib, config, ... }:
 let inherit (lib) types;
     inherit (config.networking) hostName domain;
 in
@@ -18,20 +18,7 @@ nix = {
     dates = lib.mkDefault "weekly";
     options = lib.mkDefault "--delete-older-than 30d";
   };
-  nixPath = [
-    "nixpkgs=/etc/nixpkgs:nixpkgs-overlays=/etc/nixpkgs-overlays/overlays.nix"
-  ];
 };
-# WARNING: this is a hack to avoid copying Nixpkgs
-# a second time into the Nix store.
-# It makes only sense when Nixpkgs is already in the Nix store,
-# and is registered.
-environment.etc."nixpkgs".source = pkgs.path;
-environment.etc."nixpkgs-overlays".source =
-  pkgs.writeTextDir "overlays.nix" ''
-    import ${inputs.self + "/nixpkgs/overlays.nix"} ++
-    import ${inputs.julm-nix + "/nixpkgs/overlays.nix"}
-  '';
 
 documentation.nixos = {
   enable = false; # NOTE: useless on a server, and CPU intensive.
@@ -56,8 +43,8 @@ systemd.enableEmergencyMode = false;
 # sets this up as soon as the initrd.
 boot.kernelParams = [ "panic=10" ];
 
-boot.cleanTmpDir = true;
-boot.tmpOnTmpfs = true;
+boot.cleanTmpDir = lib.mkDefault true;
+boot.tmpOnTmpfs = lib.mkDefault true;
 
 networking = {
   # Fix hostname --fqdn
diff --git a/nixos/profiles/systems/builder.nix b/nixos/profiles/systems/builder.nix
new file mode 100644 (file)
index 0000000..1bf493e
--- /dev/null
@@ -0,0 +1,19 @@
+{ inputs, pkgs, lib, config, ... }:
+{
+nix.nixPath = [
+  "nixpkgs=/etc/nixpkgs:nixpkgs-overlays=/etc/nixpkgs-overlays/overlays.nix"
+];
+nix.extraOptions = "experimental-features = nix-command flakes";
+# Note that this will make the target system download Nixpkgs.
+nix.registry.nixpkgs.flake = pkgs.path;
+# WARNING: this is a hack to avoid copying Nixpkgs
+# a second time into the Nix store.
+# It makes only sense when Nixpkgs is already in the Nix store,
+# and is registered.
+environment.etc."nixpkgs".source = pkgs.path;
+environment.etc."nixpkgs-overlays".source =
+  pkgs.writeTextDir "overlays.nix" ''
+    import ${inputs.self + "/nixpkgs/overlays.nix"} ++
+    import ${inputs.julm-nix + "/nixpkgs/overlays.nix"}
+  '';
+}