diff --git a/modules/flake-parts/setups/home-manager.nix b/modules/flake-parts/setups/home-manager.nix index 2b4eebf1..99e89995 100644 --- a/modules/flake-parts/setups/home-manager.nix +++ b/modules/flake-parts/setups/home-manager.nix @@ -19,7 +19,7 @@ let modules = extraModules; }; - deploySettingsType = { config, lib, ... }: { + deploySettingsType = { config, lib, username, ... }: { freeformType = with lib.types; attrsOf anything; options = { @@ -30,26 +30,30 @@ let profiles = lib.mkOption { type = with lib.types; functionTo (attrsOf anything); default = os: { - sshUser = "root"; - user = "admin"; - path = inputs.deploy-rs.lib.${os.system}.activate.nixos os.config; + home = { + sshUser = username; + user = username; + path = inputs.deploy.lib.${os.system}.activate.home-manager os.config; + }; }; defaultText = lib.literalExpression '' os: { - sshUser = "root"; - user = "admin"; - path = inputs.deploy-rs.lib.''${os.system}.activate.nixos os.config; + home = { + sshUser = "$USERNAME"; + user = "$USERNAME"; + path = .lib.''${os.system}.activate.home-manager os.config; + }; } ''; description = '' A set of profiles for the resulting deploy node. - Since each config can result in more than one NixOS system, it has to - be a function where the passed argument is an attribute set with the - following values: + Since each config can result in more than one home-manager + environment, it has to be a function where the passed argument is an + attribute set with the following values: * `name` is the attribute name from `configs`. - * `config` is the NixOS configuration itself. + * `config` is the home-manager configuration itself. * `system` is a string indicating the platform of the NixOS system. If unset, it will create a deploy-rs node profile called `home` @@ -129,10 +133,16 @@ let }; deploy = lib.mkOption { - type = with lib.types; nullOr (submodule deploySettingsType); + type = with lib.types; nullOr (submoduleWith { + specialArgs = { + username = name; + }; + modules = [ deploySettingsType ]; + }); default = null; description = '' - deploy-rs settings to be passed onto the home-manager configuration node. + deploy-rs settings to be passed onto the home-manager configuration + node. ''; }; }; @@ -218,10 +228,7 @@ in lib.listToAttrs (builtins.map (system: - let - name = "${username}-${system}"; - in - lib.nameValuePair name (mkHome { + lib.nameValuePair system (mkHome { inherit (metadata) nixpkgs-branch home-manager-branch; inherit system; extraModules = @@ -257,7 +264,20 @@ in (name: configs: lib.mapAttrs' (system: config: lib.nameValuePair "home-manager-${name}-${system}" - (cfg.configs.${name}.deploy.profiles { inherit name config system; }))) + ( + let + deployConfig = cfg.configs.${name}.deploy; + deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ]; + in + deployConfig' + // { + profiles = + cfg.configs.${name}.deploy.profiles { + inherit name config system; + }; + } + )) + configs) validConfigs; }; }; diff --git a/modules/flake-parts/setups/nixos.nix b/modules/flake-parts/setups/nixos.nix index 0fa2f2eb..bcf8af0c 100644 --- a/modules/flake-parts/setups/nixos.nix +++ b/modules/flake-parts/setups/nixos.nix @@ -59,15 +59,19 @@ let profiles = lib.mkOption { type = with lib.types; functionTo (attrsOf anything); default = os: { - sshUser = "root"; - user = "admin"; - path = inputs.deploy.lib.${os.system}.activate.nixos os.config; + system = { + sshUser = "root"; + user = "admin"; + path = inputs.deploy.lib.${os.system}.activate.nixos os.config; + }; }; defaultText = lib.literalExpression '' os: { - sshUser = "root"; - user = "admin"; - path = inputs.deploy-rs.lib.''${os.system}.activate.nixos os.config; + system = { + sshUser = "root"; + user = "admin"; + path = .lib.''${os.system}.activate.nixos os.config; + }; } ''; description = '' @@ -178,7 +182,10 @@ let type = with lib.types; nullOr (submodule deployNodeType); default = null; description = '' - deploy-rs node settings for the resulting NixOS configuration. + deploy-rs node settings for the resulting NixOS configuration. When + this attribute is given with a non-null value, it will be included in + `nixosConfigurations` even if + {option}`setups.nixos.configs..formats` is set. ''; example = { hostname = "work1.example.com"; @@ -327,7 +334,19 @@ in (name: configs: lib.mapAttrs' (system: config: lib.nameValuePair "nixos-${name}-${system}" - (cfg.configs.${name}.deploy.profiles { inherit name config system; })) + ( + let + deployConfig = cfg.configs.${name}.deploy; + deployConfig' = lib.attrsets.removeAttrs deployConfig [ "profiles" ]; + in + deployConfig' + // { + profiles = + cfg.configs.${name}.deploy.profiles { + inherit name config system; + }; + } + )) configs) validConfigs; };