diff --git a/hosts/nixos/apollo/configuration.nix b/hosts/nixos/apollo/configuration.nix index 6977a0b..f77da2a 100644 --- a/hosts/nixos/apollo/configuration.nix +++ b/hosts/nixos/apollo/configuration.nix @@ -6,7 +6,6 @@ osbmModules = { machineType = "server"; - users = [ "osbm" ]; services = { glance.enable = true; # anubis.enable = true; diff --git a/hosts/nixos/pochita/configuration.nix b/hosts/nixos/pochita/configuration.nix index 25ac796..a5b6bd7 100644 --- a/hosts/nixos/pochita/configuration.nix +++ b/hosts/nixos/pochita/configuration.nix @@ -14,6 +14,7 @@ osbmModules = { machineType = "server"; hardware.systemd-boot.enable = false; # Raspberry Pi uses init-script bootloader + familyUser.enable = true; services = { wanikani-bypass-lessons.enable = true; wanikani-fetch-data.enable = true; diff --git a/hosts/nixos/tartarus/configuration.nix b/hosts/nixos/tartarus/configuration.nix index f0eba85..0a862f5 100644 --- a/hosts/nixos/tartarus/configuration.nix +++ b/hosts/nixos/tartarus/configuration.nix @@ -7,6 +7,7 @@ osbmModules = { desktopEnvironment.plasma.enable = true; machineType = "laptop"; + familyUser.enable = true; emulation.aarch64.enable = true; hardware.sound.enable = true; programs.steam.enable = true; diff --git a/hosts/nixos/ymir/configuration.nix b/hosts/nixos/ymir/configuration.nix index 539f10c..75d6eb1 100644 --- a/hosts/nixos/ymir/configuration.nix +++ b/hosts/nixos/ymir/configuration.nix @@ -7,6 +7,7 @@ osbmModules = { desktopEnvironment.plasma.enable = true; machineType = "desktop"; + familyUser.enable = true; programs = { adbFastboot.enable = true; steam.enable = true; diff --git a/modules/nixos/options.nix b/modules/nixos/options.nix index 5a8d68c..7b998c2 100644 --- a/modules/nixos/options.nix +++ b/modules/nixos/options.nix @@ -32,24 +32,18 @@ description = "Type of machine for appropriate defaults"; }; - # Users - users = lib.mkOption { - type = lib.types.listOf lib.types.str; - default = [ - "osbm" - ] - ++ lib.optionals ( - config.osbmModules.machineType == "desktop" || config.osbmModules.machineType == "laptop" - ) [ "bayram" ]; - description = "List of users to create. `osbm` is my main user, and `bayram` is for my family (only on desktop/laptop)."; - }; - defaultUser = lib.mkOption { type = lib.types.str; default = "osbm"; description = "Default user for the system"; }; + familyUser.enable = lib.mkOption { + type = lib.types.bool; + default = false; + description = "Enable family user account"; + }; + # Home Manager homeManager = { enable = lib.mkOption { diff --git a/modules/nixos/system/home-manager.nix b/modules/nixos/system/home-manager.nix index 9eda20c..2b3cbf9 100644 --- a/modules/nixos/system/home-manager.nix +++ b/modules/nixos/system/home-manager.nix @@ -34,8 +34,13 @@ let # Capture the NixOS system config before entering the home-manager scope systemConfig = config; + # Build list of regular users based on defaultUser and familyUser options + regularUsers = [ + systemConfig.osbmModules.defaultUser + ] + ++ lib.optional systemConfig.osbmModules.familyUser.enable "bayram"; in - lib.genAttrs (builtins.filter (u: u != "root") config.osbmModules.users) (_username: { + lib.genAttrs regularUsers (_username: { # Use the system's stateVersion for home-manager home.stateVersion = lib.mkDefault systemConfig.system.stateVersion; imports = [ diff --git a/modules/nixos/system/impermanence.nix b/modules/nixos/system/impermanence.nix index c97f947..eea80b5 100644 --- a/modules/nixos/system/impermanence.nix +++ b/modules/nixos/system/impermanence.nix @@ -6,8 +6,11 @@ ... }: let - # Filter out 'root' from the users list since it's a special system user - regularUsers = builtins.filter (u: u != "root") config.osbmModules.users; + # Build list of regular users based on defaultUser and familyUser options + regularUsers = [ + config.osbmModules.defaultUser + ] + ++ lib.optional config.osbmModules.familyUser.enable "bayram"; # Generate user persistence configuration userPersistence = lib.genAttrs regularUsers (_username: { diff --git a/modules/nixos/system/users.nix b/modules/nixos/system/users.nix index 643aa4d..72df34d 100644 --- a/modules/nixos/system/users.nix +++ b/modules/nixos/system/users.nix @@ -1,33 +1,40 @@ { lib, config, ... }: -let - # Filter out 'root' from the users list since it's a special system user - regularUsers = builtins.filter (u: u != "root") config.osbmModules.users; -in { - config = lib.mkIf (config.osbmModules.users != [ ]) { + config = { users.users = lib.mkMerge [ - # Create users based on the list (excluding root) - (lib.genAttrs regularUsers (username: { - isNormalUser = true; - description = username; - initialPassword = "changeme"; - extraGroups = [ - "networkmanager" - ] - ++ lib.optional (username == config.osbmModules.defaultUser) "wheel" - ++ lib.optional config.osbmModules.virtualisation.docker.enable "docker" - ++ lib.optional config.osbmModules.programs.adbFastboot.enable "adbusers"; - })) - - # Additional configuration for default user (including root if it's default) + # Default user { ${config.osbmModules.defaultUser} = { + isNormalUser = true; + description = config.osbmModules.defaultUser; + initialPassword = "changeme"; + extraGroups = [ + "wheel" + "networkmanager" + ] + ++ lib.optional config.osbmModules.virtualisation.docker.enable "docker" + ++ lib.optional config.osbmModules.programs.adbFastboot.enable "adbusers"; openssh.authorizedKeys.keys = lib.mkDefault [ "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPfnV+qqUCJf92npNW4Jy0hIiepCJFBDJHXBHnUlNX0k" ]; }; } + # Family user (bayram) + (lib.mkIf config.osbmModules.familyUser.enable { + bayram = { + isNormalUser = true; + description = "bayram"; + initialPassword = "changeme"; + extraGroups = [ + "networkmanager" + ] + ++ lib.optional config.osbmModules.virtualisation.docker.enable "docker" + ++ lib.optional config.osbmModules.programs.adbFastboot.enable "adbusers"; + }; + }) + + # Root user { root = { initialPassword = "changeme"; @@ -36,8 +43,6 @@ in ]; }; } - ]; - }; }