make home configs work

This commit is contained in:
Jana Dönszelmann 2026-01-23 13:27:58 +01:00
parent f0c21b2e79
commit 30f81b2b79
No known key found for this signature in database
29 changed files with 2131 additions and 2033 deletions

View file

@ -1,30 +1,31 @@
{
args@{
lib,
pkgs,
config,
machine,
...
}:
with lib;
let
cfg = config.custom.users;
machine = config.custom.machine;
inherit (machine) home-only;
inherit (machine) stateVersion;
valid-on-machine =
on:
# TODO: iterate over possibilities
if machine.type == "server" then
on.server
else if machine.type == "pc" then
on.pc
else
false;
matches-capabilities =
# all requirements are contained in the machine capabilities
requirements: lib.all (req: builtins.elem req machine.capabilities) requirements;
(
if machine.type == "server" then
on.server
else if machine.type == "pc" then
on.pc
else
false
);
users = lib.filterAttrs (_: value: valid-on-machine value.on) cfg;
home-users = lib.filterAttrs (_: value: value.apply-home-configs) users;
stateVersion = config.system.stateVersion;
programs = lib.attrsets.attrValues config.custom.program;
valid-programs = builtins.filter (program: matches-capabilities program.requirements) programs;
in
{
options =
@ -75,32 +76,47 @@ in
};
};
config = lib.mkMerge ([
{
users.extraUsers = lib.mapAttrs (name: value: {
isNormalUser = true;
extraGroups = value.groups;
openssh.authorizedKeys.keys = value.keys;
shell = value.shell;
description = name;
}) users;
home-manager.users = lib.mapAttrs (
name: value:
(_: {
imports = (
[
./home-info.nix
]
++ (map (program: program.home-config) valid-programs)
);
home = {
inherit stateVersion;
username = name;
homeDirectory = "/home/${name}";
};
})
) home-users;
}
]);
config = lib.mkMerge [
(
if (!builtins.isNull home-only) then
lib.mkMerge ([
{
home = {
inherit stateVersion;
username = toString home-only;
homeDirectory = "/home/${toString home-only}";
};
}
]
# ++ map (program: program.home-config) programs
)
else
(lib.mkMerge ([
{
users.extraUsers = lib.mapAttrs (name: value: {
isNormalUser = true;
extraGroups = value.groups;
openssh.authorizedKeys.keys = value.keys;
inherit (value) shell;
description = name;
}) users;
home-manager.users = lib.mapAttrs (
name: value:
(_: {
imports = (
[
]
++ (map (program: program.home-config) programs)
);
home = {
inherit stateVersion;
username = name;
homeDirectory = "/home/${name}";
};
})
) home-users;
}
]))
)
];
}