2022-02-19 23:03:59 +00:00
|
|
|
{ lib, options, config, ... }:
|
|
|
|
let
|
2022-09-09 01:04:25 +01:00
|
|
|
inherit (lib) mkIf mkDefault mkOption mkMerge mkAliasDefinitions optional;
|
2022-05-28 19:02:13 +01:00
|
|
|
inherit (lib.my) mkBoolOpt' mkOpt' mkDefault';
|
2022-02-19 23:03:59 +00:00
|
|
|
|
|
|
|
cfg = config.my.user;
|
|
|
|
user' = cfg.config;
|
2022-03-26 14:20:30 +00:00
|
|
|
user = config.users.users.${user'.name};
|
2022-02-19 23:03:59 +00:00
|
|
|
in
|
|
|
|
{
|
|
|
|
options.my.user = with lib.types; {
|
|
|
|
enable = mkBoolOpt' true "Whether to create a primary user.";
|
2022-05-28 19:02:13 +01:00
|
|
|
passwordSecret = mkOpt' (nullOr str) "user-passwd.txt" "Name of user password secret.";
|
2022-09-08 20:31:44 +01:00
|
|
|
tmphome = mkBoolOpt' true "Whether to persist home directory files under tmproot";
|
2022-02-19 23:03:59 +00:00
|
|
|
config = mkOption {
|
|
|
|
type = options.users.users.type.nestedTypes.elemType;
|
|
|
|
default = { };
|
|
|
|
description = "User definition (as `users.users.*`).";
|
|
|
|
};
|
|
|
|
homeConfig = mkOption {
|
|
|
|
type = options.home-manager.users.type.nestedTypes.elemType;
|
|
|
|
default = { };
|
|
|
|
# Prevent docs traversing into all of home-manager
|
|
|
|
visible = "shallow";
|
|
|
|
description = "Home configuration (as `home-manager.users.*`)";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-05-28 19:02:13 +01:00
|
|
|
config = mkIf cfg.enable (mkMerge [
|
|
|
|
{
|
|
|
|
my = {
|
|
|
|
user = {
|
|
|
|
config = {
|
|
|
|
name = mkDefault' "dev";
|
|
|
|
isNormalUser = true;
|
|
|
|
uid = mkDefault 1000;
|
2022-09-09 01:04:25 +01:00
|
|
|
extraGroups =
|
2023-12-05 23:27:16 +00:00
|
|
|
[ "wheel" "kvm" "dialout" ] ++
|
|
|
|
(optional config.networking.networkmanager.enable "networkmanager") ++
|
2023-12-16 18:50:51 +00:00
|
|
|
(optional config.virtualisation.libvirtd.enable "libvirtd") ++
|
2023-12-19 23:40:54 +00:00
|
|
|
(optional config.programs.wireshark.enable "wireshark") ++
|
|
|
|
(with config.services.headscale; (optional enable group));
|
2022-05-28 19:02:13 +01:00
|
|
|
password = mkIf (cfg.passwordSecret == null) (mkDefault "hunter2");
|
|
|
|
shell =
|
|
|
|
let shell = cfg.homeConfig.my.shell;
|
|
|
|
in mkIf (shell != null) (mkDefault' shell);
|
2023-11-02 13:41:50 +00:00
|
|
|
openssh.authorizedKeys.keyFiles = [ lib.my.c.sshKeyFiles.me ];
|
2022-05-28 19:02:13 +01:00
|
|
|
};
|
|
|
|
homeConfig = {
|
|
|
|
# In order for this option to evaluate on its own, home-manager expects the `name` (which is derived from the
|
|
|
|
# parent attr name) to be the users name, aka `home-manager.users.<name>`
|
|
|
|
_module.args.name = lib.mkForce user'.name;
|
|
|
|
};
|
2022-03-26 14:20:30 +00:00
|
|
|
};
|
2022-09-08 20:31:44 +01:00
|
|
|
tmproot = mkIf cfg.tmphome {
|
2022-05-28 19:02:13 +01:00
|
|
|
unsaved.ignore = [
|
|
|
|
# Auto-generated (on activation?)
|
|
|
|
"/home/${user'.name}/.nix-profile"
|
|
|
|
"/home/${user'.name}/.nix-defexpr"
|
2022-05-28 13:57:01 +01:00
|
|
|
|
2022-05-28 19:02:13 +01:00
|
|
|
"/home/${user'.name}/.config/fish/fish_variables"
|
2022-05-28 13:57:01 +01:00
|
|
|
];
|
2023-12-09 15:22:15 +00:00
|
|
|
persistence.config.users."${user'.name}" = {
|
|
|
|
files = [
|
|
|
|
".bash_history"
|
|
|
|
".lesshst"
|
2022-05-28 19:02:13 +01:00
|
|
|
];
|
2023-12-09 15:22:15 +00:00
|
|
|
directories = [
|
2022-05-28 19:02:13 +01:00
|
|
|
# Persist all of fish; it's not easy to persist just the history fish won't let you move it to a different
|
|
|
|
# directory. Also it does some funny stuff and can't really be a symlink it seems.
|
2023-12-09 15:22:15 +00:00
|
|
|
".local/share/fish"
|
2022-06-17 23:15:39 +01:00
|
|
|
|
2023-12-09 15:22:15 +00:00
|
|
|
".cache/nix"
|
2022-05-28 19:02:13 +01:00
|
|
|
];
|
|
|
|
};
|
2022-05-28 13:57:01 +01:00
|
|
|
};
|
2022-02-19 23:03:59 +00:00
|
|
|
};
|
|
|
|
|
2022-05-28 19:02:13 +01:00
|
|
|
# mkAliasDefinitions will copy the unmerged defintions to allow the upstream submodule to deal with
|
|
|
|
users.users.${user'.name} = mkAliasDefinitions options.my.user.config;
|
2022-02-19 23:03:59 +00:00
|
|
|
|
2022-05-28 19:02:13 +01:00
|
|
|
# NOTE: As the "outermost" module is still being evaluated in NixOS land, special params (e.g. pkgs) won't be
|
|
|
|
# passed to it
|
|
|
|
home-manager.users.${user'.name} = mkAliasDefinitions options.my.user.homeConfig;
|
2024-07-21 12:37:32 +01:00
|
|
|
|
|
|
|
systemd.services.nixfiles-mutable.script = ''
|
|
|
|
chown -R ${user'.name} /run/nixfiles
|
|
|
|
'';
|
2022-05-28 19:02:13 +01:00
|
|
|
}
|
|
|
|
(mkIf (cfg.passwordSecret != null) {
|
|
|
|
my = {
|
|
|
|
secrets.files."${cfg.passwordSecret}" = {};
|
2023-12-03 15:06:11 +00:00
|
|
|
user.config.hashedPasswordFile = config.age.secrets."${cfg.passwordSecret}".path;
|
2022-05-28 19:02:13 +01:00
|
|
|
};
|
|
|
|
})
|
|
|
|
]);
|
2022-02-19 23:03:59 +00:00
|
|
|
}
|