# The primary (only) interactive user. { config, lib, pkgs, ... }: let cfg = config.my.user; inherit (lib) mkOption types; passwordSecret = "${cfg.name}-password"; hasPasswordSecret = config.age.secrets ? ${passwordSecret}; in { options.my.user = { name = mkOption { type = types.str; example = "faumaray"; description = "Login name of the primary user."; }; fullName = mkOption { type = types.str; description = "Display name (GECOS), also used for git."; }; email = mkOption { type = types.str; description = "E-mail address, used for git."; }; uid = mkOption { type = types.int; default = 1000; description = "Numeric user id."; }; extraGroups = mkOption { type = types.listOf types.str; default = [ ]; description = "Groups in addition to the ones every desktop user gets."; }; sshAuthorizedKeys = mkOption { type = types.listOf types.str; default = [ ]; description = "Public keys allowed to log in over SSH."; }; }; config = { users.mutableUsers = true; users.users.${cfg.name} = { isNormalUser = true; inherit (cfg) uid; description = cfg.fullName; extraGroups = [ "wheel" "networkmanager" "video" "audio" "input" "render" ] ++ lib.optional config.my.gaming.enable "gamemode" ++ cfg.extraGroups; shell = pkgs.zsh; openssh.authorizedKeys.keys = cfg.sshAuthorizedKeys; # Real password comes from agenix; otherwise a throwaway one so the first # boot can never lock the user out. hashedPasswordFile = lib.mkIf hasPasswordSecret config.age.secrets.${passwordSecret}.path; initialPassword = lib.mkIf (!hasPasswordSecret) "changeme"; }; # Required by `shell = pkgs.zsh` (puts zsh into /etc/shells). programs.zsh.enable = true; security.sudo.wheelNeedsPassword = true; warnings = lib.optional (!hasPasswordSecret) '' User "${cfg.name}" has the temporary password "changeme". Run `passwd` after the first login, or add secrets/${passwordSecret}.age (hashed with `mkpasswd -m yescrypt`, encrypted with agenix) and `git add` it. ''; }; }