refactor: abstract app user creation via custom options

This commit is contained in:
Tibo De Peuter 2026-07-17 23:26:03 +02:00
parent 1403b1f9c0
commit d742671460
Signed by: tdpeuter
SSH key fingerprint: SHA256:u/h/LVoqKF1Iz02uOyxe6hcjmoZASCGV2HM0TG9ZMoU
7 changed files with 52 additions and 36 deletions

View file

@ -3,6 +3,7 @@
./docker.nix
./monitoring.nix
./nfs.nix
./users.nix
];
config = {

37
modules/common/users.nix Normal file
View file

@ -0,0 +1,37 @@
{ config, lib, ... }:
{
options.homelab.appUsers = lib.mkOption {
type = lib.types.attrsOf (lib.types.submodule {
options = {
uid = lib.mkOption {
type = lib.types.int;
description = "The user ID for the app user";
};
group = lib.mkOption {
type = lib.types.str;
default = config.users.groups.apps.name;
description = "The primary group for the app user";
};
extraGroups = lib.mkOption {
type = lib.types.listOf lib.types.str;
default = [];
description = "Extra groups for the app user";
};
};
});
default = {};
description = "App users to automatically create with standard homelab options";
};
config = {
users.users = lib.mapAttrs (name: cfg: {
uid = lib.mkForce cfg.uid;
isSystemUser = true;
group = cfg.group;
extraGroups = cfg.extraGroups;
home = "/var/empty";
shell = null;
}) config.homelab.appUsers;
};
}