config/modules/base/users/default.nix

93 lines
2.1 KiB
Nix
Raw Permalink Normal View History

2023-07-20 15:02:38 +03:00
{
config,
lib,
myData,
...
2024-07-29 15:39:54 +03:00
}:
let
2023-10-01 23:14:05 +03:00
cfg = config.mj.base.users;
props = with lib.types; {
hashedPasswordFile = lib.mkOption {
type = nullOr path;
default = null;
};
initialPassword = lib.mkOption {
type = nullOr str;
default = null;
};
initialHashedPassword = lib.mkOption {
type = nullOr str;
default = null;
};
extraGroups = lib.mkOption {
type = listOf str;
2024-07-29 15:39:54 +03:00
default = [ ];
};
};
2024-07-29 15:39:54 +03:00
in
{
2023-07-20 15:02:38 +03:00
options.mj.base.users = with lib.types; {
2024-02-04 16:18:47 +02:00
enable = lib.mkEnableOption "enable motiejus and root";
2024-02-04 22:05:44 +02:00
devTools = lib.mkOption {
2023-10-09 22:07:42 +03:00
type = bool;
default = false;
};
2024-03-13 09:53:48 +02:00
email = lib.mkOption {
2024-05-06 14:42:46 +03:00
type = nullOr str;
2024-03-13 09:53:48 +02:00
default = "motiejus@jakstys.lt";
};
user = props;
root = props;
2023-07-20 15:02:38 +03:00
};
2024-02-04 16:18:47 +02:00
config = lib.mkIf cfg.enable {
2023-07-20 15:02:38 +03:00
users = {
mutableUsers = false;
2023-10-01 23:14:05 +03:00
users = {
2024-07-29 15:39:54 +03:00
${config.mj.username} = {
isNormalUser = true;
extraGroups = [
"wheel"
"dialout"
"video"
2024-08-12 21:52:38 +03:00
"audio"
2024-07-29 15:39:54 +03:00
] ++ cfg.user.extraGroups;
uid = myData.uidgid.motiejus;
openssh.authorizedKeys.keys =
let
fqdn = "${config.networking.hostName}.${config.networking.domain}";
in
2024-07-29 15:39:54 +03:00
lib.mkMerge [
[
myData.people_pubkeys.motiejus
myData.people_pubkeys.motiejus_work
]
2024-07-29 15:39:54 +03:00
(lib.mkIf (builtins.hasAttr fqdn myData.hosts) [
(''from="127.0.0.1,::1" '' + myData.hosts.${fqdn}.publicKey)
])
];
} // lib.filterAttrs (n: v: n != "extraGroups" && v != null) cfg.user or { };
2023-07-20 15:02:38 +03:00
root = lib.filterAttrs (_: v: v != null) cfg.root;
2023-07-20 15:02:38 +03:00
};
};
2024-08-22 13:17:39 +03:00
home-manager = {
useGlobalPkgs = true;
backupFileExtension = "bk";
users.${config.mj.username} =
{ pkgs, ... }:
import ../../../shared/home {
inherit lib;
inherit pkgs;
inherit (config.mj) stateVersion username;
inherit (cfg) devTools email;
hmOnly = false;
};
};
2023-07-20 15:02:38 +03:00
};
}