fix: rework home-manager modules to allow option merging
This commit is contained in:
parent
165d8bb203
commit
cfaa78937e
4 changed files with 154 additions and 81 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs, lib, options, config, ... }:
|
||||
{ pkgs, lib, options, config, inputs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) types mkOption mkDefault foldl optionalAttrs;
|
||||
|
|
@ -17,14 +17,6 @@ let
|
|||
isHidden = mkDefault false;
|
||||
};
|
||||
});
|
||||
|
||||
create-resolved-home = resolved-homes: name:
|
||||
let
|
||||
user = cfg.user.${name};
|
||||
in
|
||||
resolved-homes // {
|
||||
${name} = user.home.config;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.snowfallorg = {
|
||||
|
|
@ -40,32 +32,51 @@ in
|
|||
};
|
||||
|
||||
home = {
|
||||
enable = mkOption {
|
||||
type = types.bool;
|
||||
default = true;
|
||||
};
|
||||
|
||||
path = mkOption {
|
||||
type = types.str;
|
||||
default = "/Users/${name}";
|
||||
};
|
||||
|
||||
config = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
# HM-compatible options taken from:
|
||||
# https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14
|
||||
type = types.submoduleWith {
|
||||
specialArgs = {
|
||||
osConfig = config;
|
||||
modulesPath = "${inputs.home-manager}/modules";
|
||||
} // config.home-manager.extraSpecialArgs;
|
||||
modules = [
|
||||
({ lib, modulesPath, ... }: {
|
||||
imports = import "${modulesPath}/modules.nix" {
|
||||
inherit pkgs lib;
|
||||
useNixpkgsModule = !config.home-manager.useGlobalPkgs;
|
||||
};
|
||||
|
||||
config = {
|
||||
submoduleSupport.enable = true;
|
||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
||||
|
||||
home.username = config.users.users.${name}.name;
|
||||
home.homeDirectory = config.users.users.${name}.home;
|
||||
|
||||
nix.package = config.nix.package;
|
||||
};
|
||||
})
|
||||
] ++ config.home-manager.sharedModules;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
resolved-homes = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
users.users = (foldl (create-system-users) { } (user-names));
|
||||
|
||||
snowfallorg = {
|
||||
resolved-homes = (foldl (create-resolved-home) { } (user-names));
|
||||
};
|
||||
users.users = (foldl create-system-users { } (user-names));
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@ let
|
|||
# when being used in standalone home-manager. To remedy this, we have to refer to the arguments set directly.
|
||||
os-user-home = inputs.osConfig.users.users.${cfg.name}.home or null;
|
||||
|
||||
has-user-name = (cfg.user.name or null) != null;
|
||||
|
||||
default-home-directory =
|
||||
if (os-user-home != null) then
|
||||
os-user-home
|
||||
|
|
@ -43,8 +45,8 @@ in
|
|||
|
||||
config = mkIf cfg.user.enable {
|
||||
home = {
|
||||
username = mkIf (cfg.user.name or null != null) (mkDefault cfg.user.name);
|
||||
homeDirectory = mkIf (cfg.user.name or null != null) (mkDefault cfg.user.home.directory);
|
||||
username = mkIf has-user-name (mkDefault cfg.user.name);
|
||||
homeDirectory = mkIf has-user-name (mkDefault cfg.user.home.directory);
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ pkgs, lib, options, config, ... }:
|
||||
{ pkgs, lib, options, config, inputs, ... }:
|
||||
|
||||
let
|
||||
inherit (lib) types mkOption mkDefault foldl optionalAttrs optional;
|
||||
|
|
@ -15,22 +15,15 @@ let
|
|||
${name} = {
|
||||
isNormalUser = mkDefault true;
|
||||
|
||||
name = mkDefault cfg.name;
|
||||
name = mkDefault name;
|
||||
|
||||
home = mkDefault user.home.path;
|
||||
group = mkDefault "users";
|
||||
|
||||
extraGroups = (builtins.trace user.admin) optional user.admin "wheel";
|
||||
extraGroups = optional user.admin "wheel";
|
||||
};
|
||||
});
|
||||
|
||||
create-resolved-home = resolved-homes: name:
|
||||
let
|
||||
user = cfg.user.${name};
|
||||
in
|
||||
resolved-homes // {
|
||||
${name} = user.home.config;
|
||||
};
|
||||
in
|
||||
{
|
||||
options.snowfallorg = {
|
||||
|
|
@ -58,26 +51,40 @@ in
|
|||
};
|
||||
|
||||
config = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
# HM-compatible options taken from:
|
||||
# https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14
|
||||
type = types.submoduleWith {
|
||||
specialArgs = {
|
||||
osConfig = config;
|
||||
modulesPath = "${inputs.home-manager}/modules";
|
||||
} // config.home-manager.extraSpecialArgs;
|
||||
modules = [
|
||||
({ lib, modulesPath, ... }: {
|
||||
imports = import "${modulesPath}/modules.nix" {
|
||||
inherit pkgs lib;
|
||||
useNixpkgsModule = !config.home-manager.useGlobalPkgs;
|
||||
};
|
||||
|
||||
config = {
|
||||
submoduleSupport.enable = true;
|
||||
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
||||
|
||||
home.username = config.users.users.${name}.name;
|
||||
home.homeDirectory = config.users.users.${name}.home;
|
||||
|
||||
nix.package = config.nix.package;
|
||||
};
|
||||
})
|
||||
] ++ config.home-manager.sharedModules;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}));
|
||||
};
|
||||
|
||||
resolved-homes = mkOption {
|
||||
type = types.attrs;
|
||||
default = { };
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
|
||||
config = {
|
||||
users.users = (foldl (create-system-users) { } (user-names));
|
||||
|
||||
snowfallorg = {
|
||||
resolved-homes = (foldl (create-resolved-home) { } (user-names));
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue