switch to cap based home configs

This commit is contained in:
Jana Dönszelmann 2026-01-20 16:57:10 +01:00
parent 50ee9aac83
commit 49b6f5bde0
No known key found for this signature in database
64 changed files with 2064 additions and 1779 deletions

10
modules/capabilities.nix Normal file
View file

@ -0,0 +1,10 @@
[
# needs configs for cli access
"cli"
# needs configs for ui like a desktop manager and login manager
"graphical"
# needs configs for work computers like libreoffice etc
"work"
# needs configs for fun use, like steam
"fun"
]

16
modules/home-info.nix Normal file
View file

@ -0,0 +1,16 @@
{
lib,
...
}:
with lib;
{
options = {
custom.home-info = mkOption {
type = types.submodule {
options = {
};
};
};
};
}

25
modules/machine-type.nix Normal file
View file

@ -0,0 +1,25 @@
{
lib,
...
}:
with lib;
{
options = {
custom.machine = mkOption {
type = types.submodule {
options = {
type = mkOption {
type = types.enum [
"server"
"pc"
];
};
capabilities = mkOption {
type = types.listOf (types.enum (import ./capabilities.nix));
default = [ "cli" ];
};
};
};
};
};
}

36
modules/program.nix Normal file
View file

@ -0,0 +1,36 @@
{
lib,
options,
...
}:
with lib;
{
options = {
custom.program = mkOption {
type = types.attrsOf (
types.submodule (
{ config, ... }:
{
options = {
name = mkOption {
type = types.string;
};
requirements = mkOption {
type = types.listOf (types.enum (import ./capabilities.nix));
default = [ "cli" ];
};
home-config = mkOption {
type = types.deferredModule;
};
system-config = mkOption {
# type = types.attrs;
type = types.deferredModule;
default = { };
};
};
}
)
);
};
};
}

109
modules/users.nix Normal file
View file

@ -0,0 +1,109 @@
{
lib,
pkgs,
config,
...
}:
with lib;
let
cfg = config.custom.users;
machine = config.custom.machine;
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;
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 =
let
userType = types.submodule {
options = {
name = mkOption {
type = types.str;
default = [ ];
};
groups = mkOption {
type = types.listOf types.str;
default = [ ];
};
keys = mkOption {
type = types.listOf types.str;
default = [ ];
};
shell = mkOption {
type = types.package;
default = pkgs.fish;
};
on = mkOption {
type = types.submodule {
options = {
server = mkOption {
type = types.bool;
default = true;
};
pc = mkOption {
type = types.bool;
default = false;
};
};
};
default = { };
};
apply-home-configs = mkOption {
type = types.bool;
default = false;
};
};
};
in
{
custom.users = mkOption {
type = types.attrsOf userType;
};
};
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:
(
{ pkgs, lib, ... }:
{
imports = (
[
./home-info.nix
]
++ (map (program: program.home-config) valid-programs)
);
home = {
inherit stateVersion;
username = name;
homeDirectory = "/home/${name}";
};
}
)
) home-users;
}
]);
}