nixos/config/users.nix

63 lines
1.6 KiB
Nix
Raw Normal View History

2023-09-11 20:23:04 +02:00
{
config,
lib,
fn,
pkgs,
...
}:
with lib; let
withDocker = config.virtualisation.docker.enable;
withPodman = config.virtualisation.podman.enable;
2019-04-13 00:05:39 +02:00
administrators = user: {
2023-09-11 21:20:14 +02:00
inherit (user) name;
value = let
cfg = config.services;
passPath = config.sops.secrets."users/${user.name}/password".path;
in {
2019-02-26 13:44:40 +01:00
isNormalUser = true;
2023-09-11 21:20:14 +02:00
inherit (user) name;
2023-09-11 20:23:04 +02:00
uid = user.id;
subUidRanges = optional withPodman {
startUid = 100000;
count = 65536;
};
subGidRanges = optional withPodman {
startGid = 100000;
count = 65536;
};
2019-04-13 00:05:39 +02:00
home = builtins.toPath "/home/${user.name}";
2019-02-26 13:44:40 +01:00
createHome = true;
2019-04-13 00:05:39 +02:00
description = "Administrative user ${user.name}.";
group = user.name;
2023-09-11 20:23:04 +02:00
extraGroups =
["audio" "wheel" "network"]
++ (optionals cfg.xserver.enable ["input" "video"])
2023-09-11 20:23:04 +02:00
++ (optionals cfg.printing.enable ["cups" "lp"])
++ (optional (withDocker && !withPodman) "docker")
++ (optional withPodman "podman");
2019-04-13 00:05:39 +02:00
shell = "${pkgs.zsh}/bin/zsh";
passwordFile = passPath;
2019-02-26 13:44:40 +01:00
};
2019-04-13 00:05:39 +02:00
};
2023-09-11 20:23:04 +02:00
mkusergroup = user: {
2023-09-11 21:20:14 +02:00
inherit (user) name;
2023-09-11 20:23:04 +02:00
value = {
2023-09-11 21:20:14 +02:00
inherit (user) name;
2023-09-11 20:23:04 +02:00
gid = user.id;
members = [user.name];
};
};
2019-04-13 00:05:39 +02:00
in {
2023-09-11 20:23:04 +02:00
sops.secrets =
fn.sopsHelper
2023-08-28 22:05:42 +02:00
(user: "users/${user.name}/password")
config.machine.administrators
2023-09-11 20:23:04 +02:00
{neededForUsers = true;};
2019-04-13 00:05:39 +02:00
users = {
mutableUsers = false;
users = listToAttrs (map administrators config.machine.administrators);
groups = listToAttrs (map mkusergroup config.machine.administrators);
2019-02-26 13:44:40 +01:00
};
}