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
This commit is contained in:
Julia Lange 2024-11-26 08:42:01 -08:00
parent 6124a298eb
commit d994e11918
Signed by: Julia
SSH key fingerprint: SHA256:KI8YxpkPRbnDRkXPgCuQCVz181++Vy7NAvmQj8alOhM
8 changed files with 71 additions and 55 deletions

View file

@ -17,18 +17,8 @@
pkgs = nixpkgs.legacyPackages.${system}; pkgs = nixpkgs.legacyPackages.${system};
fs = pkgs.lib.fileset; fs = pkgs.lib.fileset;
st = pkgs.lib.strings; 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 hosts = let
hostFilter = { name, ...}: name == "host.nix"; hostFilter = { name, ...}: name == "host.nix";
hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts); hostPaths = fs.toList (fs.fileFilter hostFilter ./hosts);
@ -43,17 +33,6 @@
name = extractHostName path; name = extractHostName path;
}) hostPaths); }) hostPaths);
userConfig = usernameAtHostname: userpath: home-manager.lib.homeManagerConfiguration {
inherit pkgs;
extraSpecialArgs = {
inherit inputs;
inherit usernameAtHostname;
};
modules = [
./hmModules
userpath
];
};
users = let users = let
userFilter = { name, ...}: name == "user.nix"; userFilter = { name, ...}: name == "user.nix";
userPaths = fs.toList (fs.fileFilter userFilter ./hosts); userPaths = fs.toList (fs.fileFilter userFilter ./hosts);
@ -70,6 +49,41 @@
value = path; value = path;
} }
) userPaths); ) 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 { in {
nixosConfigurations = builtins.mapAttrs (name: path: hostConfig name path) hosts; nixosConfigurations = builtins.mapAttrs (name: path: hostConfig name path) hosts;
homeConfigurations = builtins.mapAttrs (name: path: userConfig name path) users; homeConfigurations = builtins.mapAttrs (name: path: userConfig name path) users;

View file

@ -22,8 +22,7 @@
}; };
}; };
user.name = "pan"; system.timezone = "America/Los_Angeles";
user.timezone = "America/Los_Angeles";
tuigreet.enable = true; tuigreet.enable = true;
hyprland.enable = true; hyprland.enable = true;
@ -31,5 +30,4 @@
librewolf.enable = true; librewolf.enable = true;
fish.enable = true; fish.enable = true;
fish.setDefault = true; fish.setDefault = true;
syncthing.enable = true;
} }

View file

@ -9,7 +9,7 @@
config = lib.mkIf config.fish.enable { config = lib.mkIf config.fish.enable {
programs.fish.enable = true; 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 ]; environment.shells = with pkgs; [ fish ];
}; };
} }

View file

@ -9,7 +9,7 @@
config = lib.mkIf config.xonsh.enable { config = lib.mkIf config.xonsh.enable {
programs.xonsh.enable = true; 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 ]; environment.shells = with pkgs; [ xonsh ];
}; };
} }

View file

@ -14,7 +14,7 @@
histFile = "$HOME/.config/zsh/history"; histFile = "$HOME/.config/zsh/history";
histSize = 2000; 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 ]; environment.shells = with pkgs; [ zsh ];
}; };
} }

View file

@ -1,4 +1,4 @@
{ config, pkgs, lib, ... }: { config, lib, ... }:
{ {
options = { options = {
@ -8,18 +8,18 @@
config = lib.mkIf config.syncthing.enable { config = lib.mkIf config.syncthing.enable {
services.syncthing = { services.syncthing = {
enable = true; enable = true;
user = config.user.name; # user = config.user.name;
dataDir = "/home/" + config.user.name + "/dox/Sync"; # dataDir = "/home/" + config.user.name + "/dox/Sync";
configDir = "/home/" + config.user.name + "/.config/syncthing"; # configDir = "/home/" + config.user.name + "/.config/syncthing";
overrideFolders = true; # overrideFolders = true;
overrideDevices = true; # overrideDevices = true;
#
settings = { # settings = {
gui = { # gui = {
user = config.user.name; # user = config.user.name;
password = "password"; # password = "password";
}; # };
}; # };
}; };
}; };
} }

View file

@ -15,7 +15,7 @@
}; };
default_session = lib.mkIf config.hyprland.enable { default_session = lib.mkIf config.hyprland.enable {
command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd Hyprland"; command = "${pkgs.greetd.tuigreet}/bin/tuigreet --time --cmd Hyprland";
user = config.user.name; user = "greeter";
}; };
}; };
}; };

View file

@ -1,9 +1,8 @@
{ config, inputs, pkgs, lib, hostname, ... }: { config, inputs, pkgs, lib, hostname, usernameList, ... }:
{ {
options = { options = {
user.name = lib.mkOption { default = "pan"; }; system.timezone = lib.mkOption { default = "America/Los_Angeles"; };
user.timezone = lib.mkOption { default = "America/Los_Angeles"; };
system.extraFonts = lib.mkOption { default = []; }; system.extraFonts = lib.mkOption { default = []; };
system.doAutoUpgrade = lib.mkEnableOption "Enable auto upgrading system"; system.doAutoUpgrade = lib.mkEnableOption "Enable auto upgrading system";
}; };
@ -19,7 +18,7 @@
nixpkgs.config.allowUnfree = true; nixpkgs.config.allowUnfree = true;
system.stateVersion = "23.05"; system.stateVersion = "23.05";
time.timeZone = config.user.timezone; time.timeZone = config.system.timezone;
i18n.defaultLocale = "en_US.UTF-8"; i18n.defaultLocale = "en_US.UTF-8";
@ -45,15 +44,20 @@
}; };
nix.settings.use-xdg-base-directories = true; nix.settings.use-xdg-base-directories = true;
users.groups = { users = {
wheel = { }; users = builtins.listToAttrs (map (
network = { }; user: {
}; name = user;
value = {
users.users.defaultUser = { name = user;
name = config.user.name; isNormalUser = true;
isNormalUser = true; };
extraGroups = [ "wheel" "network" ]; }
) usernameList);
groups = {
wheel = { };
network = { };
};
}; };
fonts = { fonts = {