diff --git a/flake.nix b/flake.nix index 17ed887..3c5ecaa 100644 --- a/flake.nix +++ b/flake.nix @@ -50,6 +50,7 @@ ... } @ inputs: { + hosts = import ./nix/hosts.nix; deploy = import ./nix/deploy.nix inputs; overlays = import ./nix/overlay.nix inputs; homeConfigurations = import ./nix/home-manager.nix inputs; diff --git a/modules/core/rekey.nix b/modules/core/rekey.nix index c409ba3..e343be8 100644 --- a/modules/core/rekey.nix +++ b/modules/core/rekey.nix @@ -35,13 +35,12 @@ with lib; { hasGoodSuffix = x: strings.hasSuffix ".age" x || strings.hasSuffix ".pub" x; in # drv.drvPath doesn't force evaluation, which allows the warning to be displayed - # before the error occurs + # in case the derivation is not built before deploying optional (!pathExists (removeSuffix ".drv" drv.drvPath)) '' - The secrets have not yet been rekeyed! + The secrets for host ${config.networking.hostName} have not yet been rekeyed! Be sure to run `nix run ".#rekey"` after changing your secrets! '' - ++ optional (!all hasGoodSuffix config.rekey.masterIdentityPaths) - '' + ++ optional (!all hasGoodSuffix config.rekey.masterIdentityPaths) '' It seems like at least one of your rekey.masterIdentityPaths contains an unencrypted age identity. These files will be copied to the nix store, so make sure they don't contain any secret information! diff --git a/nix/deploy.nix b/nix/deploy.nix index f6741ab..0a7e400 100644 --- a/nix/deploy.nix +++ b/nix/deploy.nix @@ -5,13 +5,13 @@ ... }: let inherit (nixpkgs) lib; - hosts = (import ./hosts.nix).all; - genNode = hostName: nixosCfg: let - inherit (hosts.${hostName}) hostname hostPlatform remoteBuild; - inherit (deploy-rs.lib.${hostPlatform}) activate; + generateNode = hostName: nixosCfg: let + host = self.hosts.${hostName}; + inherit (deploy-rs.lib.${host.hostPlatform}) activate; in { - inherit remoteBuild hostname; + remoteBuild = host.remoteBuild or true; + hostname = host.address or hostName; profiles.system.path = activate.nixos nixosCfg; }; in { @@ -20,5 +20,5 @@ in { sshUser = "root"; user = "root"; sudo = "runuser -u"; - nodes = lib.mapAttrs genNode self.nixosConfigurations; + nodes = lib.mapAttrs generateNode (self.nixosConfigurations or {}); } diff --git a/nix/home-manager.nix b/nix/home-manager.nix index cfb2852..e3ad1ab 100644 --- a/nix/home-manager.nix +++ b/nix/home-manager.nix @@ -6,12 +6,6 @@ ... }: let inherit (nixpkgs) lib; - hosts = let - hostsNix = import ./hosts.nix; - in - if builtins.hasAttr "homeManager" hostsNix - then hostsNix.homeManager - else {}; genModules = hostName: {homeDirectory, ...}: { config, @@ -51,4 +45,4 @@ modules = [(genModules hostName attrs)]; }; in - lib.mapAttrs genConfiguration hosts + lib.mapAttrs genConfiguration (self.hosts.homeManager or {}) diff --git a/nix/host-drvs.nix b/nix/host-drvs.nix index d94862f..f22caa1 100644 --- a/nix/host-drvs.nix +++ b/nix/host-drvs.nix @@ -1,8 +1,6 @@ {self, ...}: system: let inherit (self.pkgs.${system}) lib linkFarm; - hosts = import ./hosts.nix; - nixosDrvs = lib.mapAttrs (_: nixos: nixos.config.system.build.toplevel) self.nixosConfigurations; homeDrvs = lib.mapAttrs (_: home: home.activationPackage) self.homeConfigurations; hostDrvs = nixosDrvs // homeDrvs; @@ -11,7 +9,7 @@ lib.mapAttrsRecursiveCond (hostAttr: !(hostAttr ? "type" && (lib.elem hostAttr.type ["homeManager" "nixos"]))) (path: _: hostDrvs.${lib.last path}) - hosts; + self.hosts; structuredHostFarms = lib.mapAttrsRecursiveCond diff --git a/nix/hosts.nix b/nix/hosts.nix index 2efdb16..812dd90 100644 --- a/nix/hosts.nix +++ b/nix/hosts.nix @@ -2,13 +2,11 @@ let hosts = { nom = { type = "nixos"; - hostname = "nom"; hostPlatform = "x86_64-linux"; remoteBuild = true; }; ward = { type = "nixos"; - hostname = "ward"; hostPlatform = "x86_64-linux"; remoteBuild = true; }; diff --git a/nix/nixos.nix b/nix/nixos.nix index 2561898..023bc09 100644 --- a/nix/nixos.nix +++ b/nix/nixos.nix @@ -1,7 +1,7 @@ { self, home-manager, - impermanence, + #impermanence, nixos-hardware, nixpkgs, ragenix, @@ -9,7 +9,6 @@ ... }: let inherit (nixpkgs) lib; - hosts = (import ./hosts.nix).nixos; nixRegistry = { nix.registry = { @@ -24,8 +23,8 @@ lib.nixosSystem { modules = [ (../hosts + "/${hostName}") - # Set hostName to same value as key in nixosConfigurations - {networking.hostName = hostName;} + # By default, set networking.hostName to the hostName + { networking.hostName = lib.mkDefault hostName; } # Use correct pkgs definition { nixpkgs.pkgs = self.pkgs.${hostPlatform}; @@ -34,13 +33,13 @@ } nixRegistry home-manager.nixosModules.home-manager - impermanence.nixosModules.impermanence + #impermanence.nixosModules.impermanence ragenix.nixosModules.age ]; specialArgs = { - impermanence = impermanence.nixosModules; + #impermanence = impermanence.nixosModules; nixos-hardware = nixos-hardware.nixosModules; }; }; in - lib.mapAttrs genConfiguration hosts + lib.mapAttrs genConfiguration (self.hosts.nixos or {})