Files
Olympus/system-config/users/default.nix
2025-08-19 01:11:15 -05:00

111 lines
3.8 KiB
Nix

{ config, lib, pkgs, inputs, ... }: {
options.sysconfig = with lib; {
users = let
userType = types.submodule ({ name, ... }: {
options = with lib; {
name = mkOption {
type = with types; passwdEntry str;
default = name;
};
home-manager = {
enable = mkOption {
type = with types; bool;
default = false;
};
standalone = mkOption {
type = with types; bool;
default = false;
description = "is this home-manager standalone?";
};
extraModules = mkOption {
type = with types; listOf raw;
default = [];
};
};
sshKeys = mkOption {
type = with types; listOf str;
default = [];
};
uid = mkOption {
type = with types; nullOr int;
default = null;
};
hashedPasswordFile = mkOption {
type = with types; nullOr str;
default = null;
};
extraGroups = mkOption {
type = with types; listOf str;
default = [];
};
shell = mkOption {
type = with types; package;
default = pkgs.shadow;
};
};
});
in lib.mkOption {
type = lib.types.attrsOf userType;
default = {};
};
};
config = {
users.users = builtins.mapAttrs (x: y: let
cfg = config.homeconfig.users.${x};
in {
name = cfg.name;
isNormalUser = true;
uid = cfg.uid;
hashedPasswordFile = lib.mkIf (cfg.hashedPasswordFile != null) cfg.hashedPasswordFile;
shell = cfg.shell;
extraGroups = cfg.extraGroups;
openssh.authorizedKeys.keys = lib.mkIf config.sysconfig.services.openssh.enable cfg.sshKeys;
packages = with pkgs; lib.mkIf (cfg.home-manager.enable && cfg.home-manager.standalone) [ home-manager ];
}) config.sysconfig.users;
programs.fuse.userAllowOther = true;
home-manager = {
backupFileExtension = "backup";
extraSpecialArgs = { inherit inputs; };
sharedModules = [
inputs.sops-nix.homeManagerModules.sops
inputs.home-manager-config
];
users = builtins.listToAttrs (builtins.map
(x: {
name = x;
value = (lib.mkMerge ([
{
homeconfig = {
host = config.sysconfig.host;
name = x;
graphical = config.sysconfig.graphical;
};
}
] ++ (if inputs ? ${x} then [ (inputs.${x} { config = config.home-manager.users.${x}; inherit lib pkgs inputs; }) ] else [])
++ config.sysconfig.users.${x}.home-manager.extraModules));
})
(builtins.partition
(y: (config.sysconfig.users.${y}.home-manager.enable && !config.sysconfig.users.${y}.home-manager.standalone))
(builtins.attrNames config.sysconfig.users)
).wrong
);
};
};
}