From d994e119183c51745136a1a323737c54aa9316c3 Mon Sep 17 00:00:00 2001 From: Julia Lange Date: Tue, 26 Nov 2024 08:42:01 -0800 Subject: [PATCH] System, dynamic users for host, removes user.name adds a new specialArg to hosts: usernameList, which is a list of users determined through user/user.nix in the host/hostname dir. This touches syncthing, tuigreet, jibril, shells, and system removes the user.name field, and converts user.timezone to system.timezone. This is to move user content off of the host. This old system is replaced with dynamic user creation based on the usernameList variable Because this removes the users.users.defaultUser shells now use the (more appropriate) users.defaultUserShell --- flake.nix | 58 ++++++++++++------- hosts/jibril/host.nix | 4 +- nixosModules/apps/shells/fish/default.nix | 2 +- nixosModules/apps/shells/xonsh/default.nix | 2 +- nixosModules/apps/shells/zsh/default.nix | 2 +- nixosModules/apps/syncthing/default.nix | 26 ++++----- .../graphics/display_manager/default.nix | 2 +- nixosModules/services/system/default.nix | 30 +++++----- 8 files changed, 71 insertions(+), 55 deletions(-) diff --git a/flake.nix b/flake.nix index 679d075..ea26eec 100644 --- a/flake.nix +++ b/flake.nix @@ -17,18 +17,8 @@ pkgs = nixpkgs.legacyPackages.${system}; fs = pkgs.lib.fileset; st = pkgs.lib.strings; + as = pkgs.lib.attrsets; - hostConfig = hostname: hostpath: nixpkgs.lib.nixosSystem { - specialArgs = { - inherit inputs; - inherit hostname; - }; - system = system; - modules = [ - ./nixosModules - hostpath - ]; - }; hosts = let hostFilter = { name, ...}: name == "host.nix"; hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts); @@ -43,17 +33,6 @@ name = extractHostName path; }) hostPaths); - userConfig = usernameAtHostname: userpath: home-manager.lib.homeManagerConfiguration { - inherit pkgs; - extraSpecialArgs = { - inherit inputs; - inherit usernameAtHostname; - }; - modules = [ - ./hmModules - userpath - ]; - }; users = let userFilter = { name, ...}: name == "user.nix"; userPaths = fs.toList (fs.fileFilter userFilter ./hosts); @@ -70,6 +49,41 @@ value = path; } ) userPaths); + + userConfig = usernameAtHostname: userpath: home-manager.lib.homeManagerConfiguration { + inherit pkgs; + extraSpecialArgs = { + inherit inputs; + inherit usernameAtHostname; + }; + modules = [ + ./hmModules + userpath + ]; + }; + + hostConfig = hostname: hostpath: nixpkgs.lib.nixosSystem { + specialArgs = let + hostFilteredUsers = as.filterAttrs ( + name: value: let + userHostname = builtins.elemAt (st.splitString "@" name) 1; + in userHostname == hostname + ) users; + + hostUsers = as.mapAttrsToList ( + name: value: builtins.elemAt (st.splitString "@" name) 0 + ) hostFilteredUsers; + in { + inherit inputs; + inherit hostname; + "usernameList" = hostUsers; + }; + system = system; + modules = [ + ./nixosModules + hostpath + ]; + }; in { nixosConfigurations = builtins.mapAttrs (name: path: hostConfig name path) hosts; homeConfigurations = builtins.mapAttrs (name: path: userConfig name path) users; diff --git a/hosts/jibril/host.nix b/hosts/jibril/host.nix index 249e9aa..cce879f 100644 --- a/hosts/jibril/host.nix +++ b/hosts/jibril/host.nix @@ -22,8 +22,7 @@ }; }; - user.name = "pan"; - user.timezone = "America/Los_Angeles"; + system.timezone = "America/Los_Angeles"; tuigreet.enable = true; hyprland.enable = true; @@ -31,5 +30,4 @@ librewolf.enable = true; fish.enable = true; fish.setDefault = true; - syncthing.enable = true; } diff --git a/nixosModules/apps/shells/fish/default.nix b/nixosModules/apps/shells/fish/default.nix index d4885f9..1e17b4e 100644 --- a/nixosModules/apps/shells/fish/default.nix +++ b/nixosModules/apps/shells/fish/default.nix @@ -9,7 +9,7 @@ config = lib.mkIf config.fish.enable { programs.fish.enable = true; - users.users.defaultUser.shell = lib.mkIf config.fish.setDefault pkgs.fish; + users.defaultUserShell = lib.mkIf config.fish.setDefault pkgs.fish; environment.shells = with pkgs; [ fish ]; }; } diff --git a/nixosModules/apps/shells/xonsh/default.nix b/nixosModules/apps/shells/xonsh/default.nix index 644e14e..4d4215c 100644 --- a/nixosModules/apps/shells/xonsh/default.nix +++ b/nixosModules/apps/shells/xonsh/default.nix @@ -9,7 +9,7 @@ config = lib.mkIf config.xonsh.enable { programs.xonsh.enable = true; - users.users.defaultUser.shell = lib.mkIf config.xonsh.setDefault pkgs.xonsh; + users.defaultUserShell = lib.mkIf config.xonsh.setDefault pkgs.xonsh; environment.shells = with pkgs; [ xonsh ]; }; } diff --git a/nixosModules/apps/shells/zsh/default.nix b/nixosModules/apps/shells/zsh/default.nix index 5ede3d1..93d33f7 100644 --- a/nixosModules/apps/shells/zsh/default.nix +++ b/nixosModules/apps/shells/zsh/default.nix @@ -14,7 +14,7 @@ histFile = "$HOME/.config/zsh/history"; histSize = 2000; }; - users.users.defaultUser.shell = lib.mkIf config.zsh.setDefault pkgs.zsh; + users.defaultUserShell = lib.mkIf config.zsh.setDefault pkgs.zsh; environment.shells = with pkgs; [ zsh ]; }; } diff --git a/nixosModules/apps/syncthing/default.nix b/nixosModules/apps/syncthing/default.nix index 69cea88..fee80a5 100644 --- a/nixosModules/apps/syncthing/default.nix +++ b/nixosModules/apps/syncthing/default.nix @@ -1,4 +1,4 @@ -{ config, pkgs, lib, ... }: +{ config, lib, ... }: { options = { @@ -8,18 +8,18 @@ config = lib.mkIf config.syncthing.enable { services.syncthing = { enable = true; - user = config.user.name; - dataDir = "/home/" + config.user.name + "/dox/Sync"; - configDir = "/home/" + config.user.name + "/.config/syncthing"; - overrideFolders = true; - overrideDevices = true; - - settings = { - gui = { - user = config.user.name; - password = "password"; - }; - }; + # user = config.user.name; + # dataDir = "/home/" + config.user.name + "/dox/Sync"; + # configDir = "/home/" + config.user.name + "/.config/syncthing"; + # overrideFolders = true; + # overrideDevices = true; + # + # settings = { + # gui = { + # user = config.user.name; + # password = "password"; + # }; + # }; }; }; } diff --git a/nixosModules/services/graphics/display_manager/default.nix b/nixosModules/services/graphics/display_manager/default.nix index 8e0c4c1..3e4dab2 100644 --- a/nixosModules/services/graphics/display_manager/default.nix +++ b/nixosModules/services/graphics/display_manager/default.nix @@ -15,7 +15,7 @@ }; default_session = lib.mkIf config.hyprland.enable { command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd Hyprland"; - user = config.user.name; + user = "greeter"; }; }; }; diff --git a/nixosModules/services/system/default.nix b/nixosModules/services/system/default.nix index 5780ea3..252a8f9 100644 --- a/nixosModules/services/system/default.nix +++ b/nixosModules/services/system/default.nix @@ -1,9 +1,8 @@ -{ config, inputs, pkgs, lib, hostname, ... }: +{ config, inputs, pkgs, lib, hostname, usernameList, ... }: { options = { - user.name = lib.mkOption { default = "pan"; }; - user.timezone = lib.mkOption { default = "America/Los_Angeles"; }; + system.timezone = lib.mkOption { default = "America/Los_Angeles"; }; system.extraFonts = lib.mkOption { default = []; }; system.doAutoUpgrade = lib.mkEnableOption "Enable auto upgrading system"; }; @@ -19,7 +18,7 @@ nixpkgs.config.allowUnfree = true; system.stateVersion = "23.05"; - time.timeZone = config.user.timezone; + time.timeZone = config.system.timezone; i18n.defaultLocale = "en_US.UTF-8"; @@ -45,15 +44,20 @@ }; nix.settings.use-xdg-base-directories = true; - users.groups = { - wheel = { }; - network = { }; - }; - - users.users.defaultUser = { - name = config.user.name; - isNormalUser = true; - extraGroups = [ "wheel" "network" ]; + users = { + users = builtins.listToAttrs (map ( + user: { + name = user; + value = { + name = user; + isNormalUser = true; + }; + } + ) usernameList); + groups = { + wheel = { }; + network = { }; + }; }; fonts = {