From ce69116c39cfc42cd27161814b03fbcef041138e Mon Sep 17 00:00:00 2001 From: Chris Kruining Date: Sun, 23 Mar 2025 20:27:14 +0100 Subject: [PATCH] almost there for multiple users???? --- lib/_root.nix | 22 ++++++++++++ lib/modules.nix | 6 ++-- lib/nixos.nix | 9 ++--- lib/user.nix | 15 ++++---- modules/home/shell/toolset/starship.nix | 46 +++++++++++-------------- modules/home/shell/toolset/yazi.nix | 14 ++++---- modules/home/user.nix | 2 +- shell.nix | 4 +++ 8 files changed, 68 insertions(+), 50 deletions(-) create mode 100644 lib/_root.nix create mode 100644 shell.nix diff --git a/lib/_root.nix b/lib/_root.nix new file mode 100644 index 0000000..fc4a10e --- /dev/null +++ b/lib/_root.nix @@ -0,0 +1,22 @@ +args@{ self, inputs, lib, pkgs, system ? "", config, options, ... }: let + inherit (lib.my) mapModulesRec'; +in +{ + imports = [ + # (import ../modules/home/shell/default.nix (args // { user = "root"; })) + ] + ++(mapModulesRec' ../modules/home (file: (import file (args // { user = "root"; })))); + + config = { + modules.root = { + user = { + full_name = "__ROOT__"; + email = "__ROOT__@${config.networking.hostName}"; + }; + + shell = { + default = "zsh"; + }; + }; + }; +} diff --git a/lib/modules.nix b/lib/modules.nix index 59bff3f..8240c6a 100644 --- a/lib/modules.nix +++ b/lib/modules.nix @@ -8,10 +8,10 @@ let in rec { mapModules = dir: fn: - mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in + mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in if v == "directory" && pathExists "${path}/default.nix" then nameValuePair n (fn path) - else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n + else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n && !(hasPrefix "_" n) then nameValuePair (removeSuffix ".nix" n) (fn path) else nameValuePair "" null ) (readDir dir); @@ -19,7 +19,7 @@ in rec mapModules' = dir: fn: attrValues (mapModules dir fn); mapModulesRec = dir: fn: - mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in + mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (n: v: let path = "${toString dir}/${n}"; in if v == "directory" && pathExists "${path}/default.nix" then nameValuePair n (mapModulesRec path fn) else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n diff --git a/lib/nixos.nix b/lib/nixos.nix index 071cbd7..f3959f4 100644 --- a/lib/nixos.nix +++ b/lib/nixos.nix @@ -6,8 +6,8 @@ args@{ ... }: let inherit (inputs.nixpkgs.lib) nixosSystem; - inherit (builtins) baseNameOf elem map mapAttrs; - inherit (lib) filterAttrs attrValues attrNames; + inherit (builtins) baseNameOf elem map listToAttrs; + inherit (lib) filterAttrs nameValuePair attrNames; inherit (lib.modules) mkAliasOptionModule mkDefault mkIf; inherit (lib.strings) removeSuffix; inherit (self.modules) mapModules mapModulesRec'; @@ -38,6 +38,7 @@ in rec imports = [ inputs.home-manager.nixosModules.home-manager "${path}/hardware.nix" + ./_root.nix ] ++ (mapModulesRec' ../modules/system import); @@ -47,13 +48,13 @@ in rec }; home-manager = { + backupFileExtension = "bak"; useGlobalPkgs = true; - useUserPackages = true; sharedModules = [ inputs.plasma-manager.homeManagerModules.plasma-manager ]; - users = mapModules "${path}/users" (p: mkHmUser p { inherit inputs lib options config system pkgs self stateVersion; }); + users = listToAttrs (map (user: (nameValuePair user { home = { inherit stateVersion; }; })) (users ++ [ "root" ])); }; }) (filterAttrs (n: v: !elem n ["system"]) attrs) diff --git a/lib/user.nix b/lib/user.nix index b2dcc00..3e1eb2b 100644 --- a/lib/user.nix +++ b/lib/user.nix @@ -16,14 +16,11 @@ in rec group = "users"; }; - mkHmUser = path: args@{stateVersion, ...}: let - name = removeSuffix ".nix" (baseNameOf path); - in - { - # imports = (mapModulesRec' ../modules/home (file: import file (args // { user = name; }))); - home = { - inherit stateVersion; - sessionPath = [ "$XDG_BIN_HOME" "$PATH" ]; # Pretty sure I don't need this. - }; + mkHmUser = path: {stateVersion, ...}: + { + home = { + inherit stateVersion; + sessionPath = [ "$XDG_BIN_HOME" "$PATH" ]; # Pretty sure I don't need this. }; + }; } diff --git a/modules/home/shell/toolset/starship.nix b/modules/home/shell/toolset/starship.nix index dd648d6..d614301 100644 --- a/modules/home/shell/toolset/starship.nix +++ b/modules/home/shell/toolset/starship.nix @@ -12,27 +12,17 @@ in home-manager.users.${user}.programs.starship = { enable = true; settings = { - scan_timeout = 10; - - # Inserts a blank line between shell prompts - add_newline = true; - - line_break.disabled = true; - - format = "[┌ ](bold green)$os$username$hostname$nix_shell$git_branch$git_commit$git_state$git_status$directory$jobs$cmd_duration\n$character"; + format = "[╭](bold green) $username@$hostname$nix_shell: $directory$cmd_duration$git_branch$git_commit$git_state$git_status$line_break[╰](green bold)$character"; username = { - style_user = "cyan bold"; - style_root = "red bold"; - format = "[$user]($style) "; - disabled = false; + format = "[$user]($style)"; show_always = true; }; hostname = { ssh_only = false; ssh_symbol = "🌐 "; - format = "on [$hostname](bold red) "; + format = "[$hostname](bold red)"; trim_at = ".local"; disabled = false; }; @@ -51,9 +41,7 @@ in }; git_commit = { - only_detached = true; - format = "[ﰖ$hash]($style) "; - style = "yellow bold"; + tag_disabled = false; }; git_state = { @@ -61,12 +49,23 @@ in }; git_status = { - style = "green bold"; + format = "[$all_status $ahead_behind]($style) "; + style = "bold green"; + conflicted = "🏳"; + up_to_date = ""; + untracked = " "; + ahead = "⇡\${count}"; + diverged = "⇕⇡\${ahead_count}⇣\${behind_count}"; + behind = "⇣\${count}"; + stashed = " "; + modified = " "; + staged = "[++\($count\)](green)"; + renamed = "襁 "; + deleted = " "; }; directory = { read_only = " 󰌾"; - truncation_length = 0; }; cmd_duration = { @@ -74,12 +73,8 @@ in style = "blue"; }; - jobs = { - style = "green bold"; - }; - os = { - format = "[$symbol](bold white) "; + format = "[$symbol](bold white)"; disabled = false; symbols = { @@ -93,9 +88,8 @@ in }; }; - character = { - success_symbol = "[└>](green bold)"; - error_symbol = "[└x](red bold)"; + fill = { + symbol = " "; }; }; }; diff --git a/modules/home/shell/toolset/yazi.nix b/modules/home/shell/toolset/yazi.nix index 27f0f51..ce96e8a 100644 --- a/modules/home/shell/toolset/yazi.nix +++ b/modules/home/shell/toolset/yazi.nix @@ -1,16 +1,16 @@ -{ config, options, lib, pkgs, user, ... }: +{ config, lib, user, ... }: let inherit (lib.modules) mkIf; - inherit (lib.strings) concatStringsSep; + inherit (lib.options) mkEnableOption; + + cfg = config.modules.${user}.shell.toolset.yazi; in { - options.modules.${user}.shell.toolset.yazi = let - inherit (lib.options) mkEnableOption; - in { - enable = mkEnableOption "system-monitor"; + options.modules.${user}.shell.toolset.yazi = { + enable = mkEnableOption "system-monitor"; }; - config = mkIf config.modules.${user}.shell.toolset.yazi.enable { + config = mkIf cfg.enable { home-manager.users.${user}.programs.yazi = { enable = true; }; diff --git a/modules/home/user.nix b/modules/home/user.nix index c746631..4fa3d0e 100644 --- a/modules/home/user.nix +++ b/modules/home/user.nix @@ -39,7 +39,7 @@ in }; }; - config = { + config = mkIf (user != "root") { users.users.${user} = { description = (cfg.full_name or user); extraGroups = cfg.groups ++ (if cfg.is_trusted then [ "wheel" ] else []); diff --git a/shell.nix b/shell.nix new file mode 100644 index 0000000..59e0938 --- /dev/null +++ b/shell.nix @@ -0,0 +1,4 @@ +{}: +{ + +}