From 618429e3c0cdb01d68f3979582d6da6e35315e52 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Fri, 9 Aug 2024 21:40:07 -0400 Subject: [PATCH 1/8] moving home-manager stuff to one sharable file --- .tmp/flake.nix | 30 ++++++ .tmp/home.nix | 76 +++++++++++++ hosts/fwbook.nix | 2 +- .../scripts}/fwbook/functions.sh | 0 modules/{skyg => }/gitconfigs/alias.conf | 0 modules/home-manager.nix | 101 ++++++++++++++++++ modules/os/default.nix | 1 - modules/os/rootUser.nix | 4 - modules/skyg/core.nix | 1 + modules/skyg/user.nix | 101 +----------------- 10 files changed, 212 insertions(+), 104 deletions(-) create mode 100644 .tmp/flake.nix create mode 100644 .tmp/home.nix rename {configs => hosts/scripts}/fwbook/functions.sh (100%) rename modules/{skyg => }/gitconfigs/alias.conf (100%) create mode 100644 modules/home-manager.nix delete mode 100644 modules/os/rootUser.nix diff --git a/.tmp/flake.nix b/.tmp/flake.nix new file mode 100644 index 0000000..426c05b --- /dev/null +++ b/.tmp/flake.nix @@ -0,0 +1,30 @@ +{ + description = "Home Manager configuration of ari"; + + inputs = { + # Specify the source of Home Manager and Nixpkgs. + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + outputs = { nixpkgs, home-manager, ... }: + let + system = "x86_64-linux"; + pkgs = nixpkgs.legacyPackages.${system}; + in + { + homeConfigurations."ari" = home-manager.lib.homeManagerConfiguration { + inherit pkgs; + + # Specify your home configuration modules here, for example, + # the path to your home.nix. + modules = [ ./home.nix ]; + + # Optionally use extraSpecialArgs + # to pass through arguments to home.nix + }; + }; +} diff --git a/.tmp/home.nix b/.tmp/home.nix new file mode 100644 index 0000000..b889661 --- /dev/null +++ b/.tmp/home.nix @@ -0,0 +1,76 @@ +{ config, pkgs, ... }: + +{ + # Home Manager needs a bit of information about you and the paths it should + # manage. + home.username = "ari"; + home.homeDirectory = "/home/ari"; + + # This value determines the Home Manager release that your configuration is + # compatible with. This helps avoid breakage when a new Home Manager release + # introduces backwards incompatible changes. + # + # You should not change this value, even if you update Home Manager. If you do + # want to update the value, then make sure to first check the Home Manager + # release notes. + home.stateVersion = "24.05"; # Please read the comment before changing. + + # The home.packages option allows you to install Nix packages into your + # environment. + home.packages = [ + # # Adds the 'hello' command to your environment. It prints a friendly + # # "Hello, world!" when run. + # pkgs.hello + + # # It is sometimes useful to fine-tune packages, for example, by applying + # # overrides. You can do that directly here, just don't forget the + # # parentheses. Maybe you want to install Nerd Fonts with a limited number of + # # fonts? + # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) + + # # You can also create simple shell scripts directly inside your + # # configuration. For example, this adds a command 'my-hello' to your + # # environment: + # (pkgs.writeShellScriptBin "my-hello" '' + # echo "Hello, ${config.home.username}!" + # '') + ]; + + # Home Manager is pretty good at managing dotfiles. The primary way to manage + # plain files is through 'home.file'. + home.file = { + # # Building this configuration will create a copy of 'dotfiles/screenrc' in + # # the Nix store. Activating the configuration will then make '~/.screenrc' a + # # symlink to the Nix store copy. + # ".screenrc".source = dotfiles/screenrc; + + # # You can also set the file content immediately. + # ".gradle/gradle.properties".text = '' + # org.gradle.console=verbose + # org.gradle.daemon.idletimeout=3600000 + # ''; + }; + + # Home Manager can also manage your environment variables through + # 'home.sessionVariables'. These will be explicitly sourced when using a + # shell provided by Home Manager. If you don't want to manage your shell + # through Home Manager then you have to manually source 'hm-session-vars.sh' + # located at either + # + # ~/.nix-profile/etc/profile.d/hm-session-vars.sh + # + # or + # + # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh + # + # or + # + # /etc/profiles/per-user/ari/etc/profile.d/hm-session-vars.sh + # + home.sessionVariables = { + # EDITOR = "emacs"; + }; + + # Let Home Manager install and manage itself. + programs.home-manager.enable = true; +} diff --git a/hosts/fwbook.nix b/hosts/fwbook.nix index 41d57bd..fc790f5 100644 --- a/hosts/fwbook.nix +++ b/hosts/fwbook.nix @@ -1,7 +1,7 @@ { user, dataDir ? "/mnt/Data", unstable }: { pkgs, lib, config, ... }: let - zshFWBook = builtins.filterSource (p: t: true) ../configs/fwbook; + zshFWBook = builtins.filterSource (p: t: true) ./scripts/fwbook; zshFunctions = zshFWBook + "/functions.sh"; in { diff --git a/configs/fwbook/functions.sh b/hosts/scripts/fwbook/functions.sh similarity index 100% rename from configs/fwbook/functions.sh rename to hosts/scripts/fwbook/functions.sh diff --git a/modules/skyg/gitconfigs/alias.conf b/modules/gitconfigs/alias.conf similarity index 100% rename from modules/skyg/gitconfigs/alias.conf rename to modules/gitconfigs/alias.conf diff --git a/modules/home-manager.nix b/modules/home-manager.nix new file mode 100644 index 0000000..6728394 --- /dev/null +++ b/modules/home-manager.nix @@ -0,0 +1,101 @@ +{ stateVersion +, enableDevelopmentKit +, name +, fullName +, email +, extraGitConfigs ? [ ] +}: +let + gitconfigs = + (builtins.filterSource (path: type: type != "directory") ./gitconfigs); + gitconfigFiles = builtins.attrNames (builtins.readDir gitconfigs); + commonGitConfigs = { + delta = { enable = true; }; + extraConfig = { + color = { ui = "auto"; }; + push = { + default = "upstream"; + autoSetupRemote = true; + }; + init = { defaultBranch = "main"; }; + }; + includes = + (builtins.map (f: { path = gitconfigs + "/" + f; }) gitconfigFiles) + ++ extraGitConfigs; + }; + commonProgramsConfig = { pkgs }: { + bat.enable = true; + neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + }; + direnv.enable = true; + lsd = { + enable = true; + enableAliases = true; + }; + zsh = { + enable = true; + autosuggestion.enable = true; + initExtra = '' + export PROMPT='%(!.%{%F{yellow}%}.)$USER@%{$fg[white]%}%M %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' + ''; + }; + zsh.oh-my-zsh = { + enable = true; + plugins = [ "git" "sudo" ]; + theme = "robbyrussell"; + }; + tmux = { + enable = true; + clock24 = true; + mouse = true; + plugins = with pkgs.tmuxPlugins; [ nord cpu battery sidebar ]; + }; + }; +in +{ + makeRootUser = { pkgs, ... }: { + home = { + stateVersion = stateVersion; + shellAliases = { + cat = "bat"; + }; + }; + programs = { + git = { + enable = true; + userName = "root"; + } // commonGitConfigs; + } // (commonProgramsConfig { pkgs = pkgs; }); + }; + + makeCommonUser = { pkgs, ... }: { + home = { + stateVersion = stateVersion; + shellAliases = { + cat = "bat"; + }; + packages = with pkgs; + [ jq nixpkgs-fmt ipfetch nixd ] + ++ (if enableDevelopmentKit then [ + rye + devenv + uv + devbox + terraform + kubectl + ] else + [ ]); + }; + programs = { + git = { + enable = true; + userName = fullName; + userEmail = email; + } // commonGitConfigs; + } // (commonProgramsConfig { pkgs = pkgs; }); + }; +} diff --git a/modules/os/default.nix b/modules/os/default.nix index b7b034c..1607245 100644 --- a/modules/os/default.nix +++ b/modules/os/default.nix @@ -12,7 +12,6 @@ { pkgs, ... }: { imports = [ (import ./core.nix { user = user; }) - ./rootUser.nix (import ./user.nix { user = user; }) (import ./containers/default.nix ({ user = user; diff --git a/modules/os/rootUser.nix b/modules/os/rootUser.nix deleted file mode 100644 index 7cab540..0000000 --- a/modules/os/rootUser.nix +++ /dev/null @@ -1,4 +0,0 @@ -{ pkgs, ... }: -{ - users.users.root.shell = pkgs.zsh; -} diff --git a/modules/skyg/core.nix b/modules/skyg/core.nix index 558cfd6..5c85ba6 100644 --- a/modules/skyg/core.nix +++ b/modules/skyg/core.nix @@ -16,6 +16,7 @@ in }; config = { + users.users.root.shell = pkgs.zsh; home-manager.users.root.programs.git.userEmail = "root@${cfg.hostName}"; networking.hostName = cfg.hostName; }; diff --git a/modules/skyg/user.nix b/modules/skyg/user.nix index cc2cefe..62549c0 100644 --- a/modules/skyg/user.nix +++ b/modules/skyg/user.nix @@ -4,10 +4,7 @@ with lib; let cfg = config.skyg; - gitconfigs = - (builtins.filterSource (path: type: type != "directory") ./gitconfigs); - gitconfigFiles = builtins.attrNames (builtins.readDir gitconfigs); - + hm = (import ../home-manager.nix cfg.user); in { options = { @@ -41,99 +38,7 @@ in config = { programs.zsh.enable = true; - home-manager.users.root = { - home.stateVersion = cfg.home-manager.version; - programs.git = { - enable = true; - userName = "root"; - }; - programs.zsh = { - enable = true; - autosuggestion.enable = true; - }; - programs.zsh.oh-my-zsh.enable = true; - }; - home-manager.users.${cfg.user.name} = { - home = { - sessionVariables = { }; - stateVersion = cfg.home-manager.version; - shellAliases = { - cat = "bat"; - }; - packages = with pkgs; - [ jq nixfmt-classic devenv ipfetch nixd ] - ++ (if cfg.user.enableDevelopmentKit then [ - rye - uv - devbox - terraform - kubectl - ] else - [ ]); - }; - programs = { - bat.enable = true; - neovim = { - enable = true; - defaultEditor = true; - viAlias = true; - vimAlias = true; - }; - direnv.enable = true; - lsd = { - enable = true; - enableAliases = true; - }; - git = { - enable = true; - userName = cfg.user.fullName; - userEmail = cfg.user.email; - delta = { enable = true; }; - extraConfig = { - color = { ui = "auto"; }; - push = { - default = "upstream"; - autoSetupRemote = true; - }; - init = { defaultBranch = "main"; }; - }; - includes = - (builtins.map (f: { path = gitconfigs + "/" + f; }) gitconfigFiles) - ++ cfg.user.extraGitConfigs; - }; - zsh = { - enable = true; - autosuggestion.enable = true; - initExtra = '' - export PROMPT='%(!.%{%F{yellow}%}.)$USER@%{$fg[white]%}%M %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' - ''; - }; - zsh.oh-my-zsh = { - enable = true; - plugins = [ "git" "sudo" ]; - theme = "robbyrussell"; - }; - tmux = { - enable = true; - clock24 = true; - mouse = true; - plugins = with pkgs.tmuxPlugins; [ nord cpu battery sidebar ]; - }; - }; - }; + home-manager.users.root = hm.makeRootUser { pkgs = pkgs; }; + home-manager.users.${cfg.user.name} = hm.makeCommonUser { pkgs = pkgs; }; }; } - - -# user = { -# name = "ari"; -# fullName = "Ari Sosnovsky"; -# email = "ariel@sosnovsky.ca"; -# }; -# sumoUser = rec { -# name = "asosnovsky"; -# fullName = user.fullName; -# email = "${name}@sumologic.com"; -# homepath = "/Users/${name}"; -# extraGitConfigs = [{ path = "${homepath}/.config/mysumo/gitconfig"; }]; -# }; From 66a876ee7290d38123c6045ce769d986367bfde6 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Fri, 9 Aug 2024 21:54:40 -0400 Subject: [PATCH 2/8] Moved home-manager work to a place I can use with other linuxes --- hosts/fwbook.nix | 1 + hosts/hl-bigbox1.nix | 5 +-- hosts/hl-fws1.nix | 1 + hosts/hl-minipc1.nix | 2 ++ hosts/hl-minipc2.nix | 1 + hosts/hl-terra1.nix | 1 + modules/home-manager.nix | 66 ++++++++++++++++++++-------------------- modules/skyg/core.nix | 2 +- modules/skyg/user.nix | 19 ++++++++---- 9 files changed, 56 insertions(+), 42 deletions(-) diff --git a/hosts/fwbook.nix b/hosts/fwbook.nix index fc790f5..43f1252 100644 --- a/hosts/fwbook.nix +++ b/hosts/fwbook.nix @@ -6,6 +6,7 @@ let in { imports = [ ./fwbook.hardware-configuration.nix ]; + skyg.user.enabled = true; services.fwupd.enable = true; services.fwupd.package = (import (builtins.fetchTarball { diff --git a/hosts/hl-bigbox1.nix b/hosts/hl-bigbox1.nix index 27d730e..3c14849 100644 --- a/hosts/hl-bigbox1.nix +++ b/hosts/hl-bigbox1.nix @@ -1,6 +1,7 @@ { user }: { pkgs, lib, config, ... }: { imports = [ ./hl-bigbox1.hardware-configuration.nix ]; + skyg.user.enabled = true; # firmware updater services.fwupd.enable = true; virtualisation.docker.enableNvidia = true; @@ -69,6 +70,6 @@ steam-tui steam-run steamPackages.steamcmd - ollama - ]; + ollama + ]; } diff --git a/hosts/hl-fws1.nix b/hosts/hl-fws1.nix index 695bd4a..bbc3787 100644 --- a/hosts/hl-fws1.nix +++ b/hosts/hl-fws1.nix @@ -1,6 +1,7 @@ { user }: { pkgs, lib, config, ... }: { imports = [ ./hl-minipc1.hardware-configuration.nix ]; + skyg.user.enabled = true; # firmware updater services.fwupd.enable = true; diff --git a/hosts/hl-minipc1.nix b/hosts/hl-minipc1.nix index 9ee8186..30be545 100644 --- a/hosts/hl-minipc1.nix +++ b/hosts/hl-minipc1.nix @@ -1,6 +1,8 @@ { user }: { pkgs, lib, config, ... }: { imports = [ ./hl-minipc1.hardware-configuration.nix ]; + skyg.user.enabled = true; + # Nix Stores services.nix-serve = { enable = true; diff --git a/hosts/hl-minipc2.nix b/hosts/hl-minipc2.nix index d47b33b..0a17591 100644 --- a/hosts/hl-minipc2.nix +++ b/hosts/hl-minipc2.nix @@ -1,6 +1,7 @@ { user }: { pkgs, lib, config, ... }: { imports = [ ./hl-minipc2.hardware-configuration.nix ]; + skyg.user.enabled = true; # firmware updater services.fwupd.enable = true; # Bootloader. diff --git a/hosts/hl-terra1.nix b/hosts/hl-terra1.nix index 5d7926d..43275ef 100644 --- a/hosts/hl-terra1.nix +++ b/hosts/hl-terra1.nix @@ -2,6 +2,7 @@ { pkgs, lib, config, ... }: { imports = [ ./hl-terra1.hardware-configuration.nix ]; + skyg.user.enabled = true; # firmware updater services.fwupd.enable = true; # Bootloader. diff --git a/modules/home-manager.nix b/modules/home-manager.nix index 6728394..7aaf6d4 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -1,15 +1,9 @@ -{ stateVersion -, enableDevelopmentKit -, name -, fullName -, email -, extraGitConfigs ? [ ] -}: +{ stateVersion }: let gitconfigs = (builtins.filterSource (path: type: type != "directory") ./gitconfigs); gitconfigFiles = builtins.attrNames (builtins.readDir gitconfigs); - commonGitConfigs = { + makeCommonGitConfigs = { extraGitConfigs }: { delta = { enable = true; }; extraConfig = { color = { ui = "auto"; }; @@ -68,34 +62,40 @@ in git = { enable = true; userName = "root"; - } // commonGitConfigs; + } // (makeCommonGitConfigs { extraGitConfigs = [ ]; }); } // (commonProgramsConfig { pkgs = pkgs; }); }; - makeCommonUser = { pkgs, ... }: { - home = { - stateVersion = stateVersion; - shellAliases = { - cat = "bat"; + makeCommonUser = + { enableDevelopmentKit + , fullName + , email + , extraGitConfigs ? [ ] + , ... + }: { pkgs, ... }: { + home = { + stateVersion = stateVersion; + shellAliases = { + cat = "bat"; + }; + packages = with pkgs; + [ jq nixpkgs-fmt ipfetch nixd ] + ++ (if enableDevelopmentKit then [ + rye + devenv + uv + devbox + terraform + kubectl + ] else + [ ]); }; - packages = with pkgs; - [ jq nixpkgs-fmt ipfetch nixd ] - ++ (if enableDevelopmentKit then [ - rye - devenv - uv - devbox - terraform - kubectl - ] else - [ ]); + programs = { + git = { + enable = true; + userName = fullName; + userEmail = email; + } // (makeCommonGitConfigs { extraGitConfigs = extraGitConfigs; }); + } // (commonProgramsConfig { pkgs = pkgs; }); }; - programs = { - git = { - enable = true; - userName = fullName; - userEmail = email; - } // commonGitConfigs; - } // (commonProgramsConfig { pkgs = pkgs; }); - }; } diff --git a/modules/skyg/core.nix b/modules/skyg/core.nix index 5c85ba6..812bfba 100644 --- a/modules/skyg/core.nix +++ b/modules/skyg/core.nix @@ -1,4 +1,4 @@ -{ config, lib, ... }: +{ config, lib, pkgs, ... }: with lib; diff --git a/modules/skyg/user.nix b/modules/skyg/user.nix index 62549c0..897e982 100644 --- a/modules/skyg/user.nix +++ b/modules/skyg/user.nix @@ -4,7 +4,6 @@ with lib; let cfg = config.skyg; - hm = (import ../home-manager.nix cfg.user); in { options = { @@ -12,6 +11,7 @@ in type = types.str; }; skyg.user = { + enabled = mkEnableOption ""; name = mkOption { type = types.str; }; @@ -36,9 +36,16 @@ in }; }; - config = { - programs.zsh.enable = true; - home-manager.users.root = hm.makeRootUser { pkgs = pkgs; }; - home-manager.users.${cfg.user.name} = hm.makeCommonUser { pkgs = pkgs; }; - }; + config = + let + hm = (import ../home-manager.nix { + stateVersion = cfg.home-manager.version; + }); + in + mkIf cfg.user.enabled + { + programs.zsh.enable = true; + home-manager.users.root = hm.makeRootUser { pkgs = pkgs; }; + home-manager.users.${cfg.user.name} = (hm.makeCommonUser cfg.user) { pkgs = pkgs; }; + }; } From 73013afe1c47b710fe8e4a4bce82e6d672ba74e3 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Fri, 9 Aug 2024 22:00:37 -0400 Subject: [PATCH 3/8] Added home manager configs --- .tmp/flake.nix | 30 ------------------- .tmp/home.nix | 76 ------------------------------------------------- flake.nix | 4 +++ modules/lib.nix | 17 +++++++++++ 4 files changed, 21 insertions(+), 106 deletions(-) delete mode 100644 .tmp/flake.nix delete mode 100644 .tmp/home.nix diff --git a/.tmp/flake.nix b/.tmp/flake.nix deleted file mode 100644 index 426c05b..0000000 --- a/.tmp/flake.nix +++ /dev/null @@ -1,30 +0,0 @@ -{ - description = "Home Manager configuration of ari"; - - inputs = { - # Specify the source of Home Manager and Nixpkgs. - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; - }; - - outputs = { nixpkgs, home-manager, ... }: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - in - { - homeConfigurations."ari" = home-manager.lib.homeManagerConfiguration { - inherit pkgs; - - # Specify your home configuration modules here, for example, - # the path to your home.nix. - modules = [ ./home.nix ]; - - # Optionally use extraSpecialArgs - # to pass through arguments to home.nix - }; - }; -} diff --git a/.tmp/home.nix b/.tmp/home.nix deleted file mode 100644 index b889661..0000000 --- a/.tmp/home.nix +++ /dev/null @@ -1,76 +0,0 @@ -{ config, pkgs, ... }: - -{ - # Home Manager needs a bit of information about you and the paths it should - # manage. - home.username = "ari"; - home.homeDirectory = "/home/ari"; - - # This value determines the Home Manager release that your configuration is - # compatible with. This helps avoid breakage when a new Home Manager release - # introduces backwards incompatible changes. - # - # You should not change this value, even if you update Home Manager. If you do - # want to update the value, then make sure to first check the Home Manager - # release notes. - home.stateVersion = "24.05"; # Please read the comment before changing. - - # The home.packages option allows you to install Nix packages into your - # environment. - home.packages = [ - # # Adds the 'hello' command to your environment. It prints a friendly - # # "Hello, world!" when run. - # pkgs.hello - - # # It is sometimes useful to fine-tune packages, for example, by applying - # # overrides. You can do that directly here, just don't forget the - # # parentheses. Maybe you want to install Nerd Fonts with a limited number of - # # fonts? - # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; }) - - # # You can also create simple shell scripts directly inside your - # # configuration. For example, this adds a command 'my-hello' to your - # # environment: - # (pkgs.writeShellScriptBin "my-hello" '' - # echo "Hello, ${config.home.username}!" - # '') - ]; - - # Home Manager is pretty good at managing dotfiles. The primary way to manage - # plain files is through 'home.file'. - home.file = { - # # Building this configuration will create a copy of 'dotfiles/screenrc' in - # # the Nix store. Activating the configuration will then make '~/.screenrc' a - # # symlink to the Nix store copy. - # ".screenrc".source = dotfiles/screenrc; - - # # You can also set the file content immediately. - # ".gradle/gradle.properties".text = '' - # org.gradle.console=verbose - # org.gradle.daemon.idletimeout=3600000 - # ''; - }; - - # Home Manager can also manage your environment variables through - # 'home.sessionVariables'. These will be explicitly sourced when using a - # shell provided by Home Manager. If you don't want to manage your shell - # through Home Manager then you have to manually source 'hm-session-vars.sh' - # located at either - # - # ~/.nix-profile/etc/profile.d/hm-session-vars.sh - # - # or - # - # ~/.local/state/nix/profiles/profile/etc/profile.d/hm-session-vars.sh - # - # or - # - # /etc/profiles/per-user/ari/etc/profile.d/hm-session-vars.sh - # - home.sessionVariables = { - # EDITOR = "emacs"; - }; - - # Let Home Manager install and manage itself. - programs.home-manager.enable = true; -} diff --git a/flake.nix b/flake.nix index 526deec..157565b 100644 --- a/flake.nix +++ b/flake.nix @@ -132,6 +132,10 @@ (import ./hosts/asosnovsky-mac.nix { user = sumoUser; }); }; + homeConfigurations."${user.name}" = lib.makeHomeManagerUsers { + user = user; + homeManagerVersion = homeManagerVersion; + }; nixosConfigurations = { # NIXOS Framework Setups diff --git a/modules/lib.nix b/modules/lib.nix index 48926b4..7e499ad 100644 --- a/modules/lib.nix +++ b/modules/lib.nix @@ -59,6 +59,22 @@ let }) ]; }; + makeHomeManagerUsers = + { modules ? [ ] + , homeManagerVersion + , user + }: + let + hm = (import ../home-manager.nix { + stateVersion = homeManagerVersion; + }); + in + home-manager.lib.homeManagerConfiguration { + inherit pkgs; + modules = [ + (hm.makeCommonUser user) + ] ++ modules; + }; in { eachSystem = eachSystem; @@ -66,6 +82,7 @@ in makeNixOsModule = makeNixOsModule; makeHLService = makeHLService; makeDarwinModule = makeDarwinModule; + makeHomeManagerUsers = makeHomeManagerUsers; makeHLServices = { nodeNames ? [ ] , systemStateVersion ? "24.05" From 63bdca6f54a9692e872f243a1fd25017ce53b76e Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sat, 10 Aug 2024 12:57:23 -0400 Subject: [PATCH 4/8] homemanager support v0 --- modules/home-manager.nix | 2 +- modules/lib.nix | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/modules/home-manager.nix b/modules/home-manager.nix index 7aaf6d4..317a12d 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -3,7 +3,7 @@ let gitconfigs = (builtins.filterSource (path: type: type != "directory") ./gitconfigs); gitconfigFiles = builtins.attrNames (builtins.readDir gitconfigs); - makeCommonGitConfigs = { extraGitConfigs }: { + makeCommonGitConfigs = { extraGitConfigs ? [ ] }: { delta = { enable = true; }; extraConfig = { color = { ui = "auto"; }; diff --git a/modules/lib.nix b/modules/lib.nix index 7e499ad..4519200 100644 --- a/modules/lib.nix +++ b/modules/lib.nix @@ -14,7 +14,7 @@ let (import ./main.nix attrs) ] ++ extraConfiguration; eachSystem = nixpkgs.lib.genAttrs (import systems); - pkgs = eachSystem (system: + allPkgs = eachSystem (system: import nixpkgs { system = system; config = { allowUnfree = true; }; @@ -63,11 +63,13 @@ let { modules ? [ ] , homeManagerVersion , user + , system ? "x86_64-linux" }: let hm = (import ../home-manager.nix { stateVersion = homeManagerVersion; }); + pkgs = allPkgs."${system}"; in home-manager.lib.homeManagerConfiguration { inherit pkgs; @@ -78,7 +80,7 @@ let in { eachSystem = eachSystem; - pkgs = pkgs; + pkgs = allPkgs; makeNixOsModule = makeNixOsModule; makeHLService = makeHLService; makeDarwinModule = makeDarwinModule; From c56f06bbfbaa419205479e0a6b21845cdab039a5 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sat, 10 Aug 2024 13:01:56 -0400 Subject: [PATCH 5/8] Decoupled home-manager --- modules/home-manager.nix | 6 +++++- modules/lib.nix | 2 +- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/modules/home-manager.nix b/modules/home-manager.nix index 317a12d..f226ca1 100644 --- a/modules/home-manager.nix +++ b/modules/home-manager.nix @@ -67,13 +67,17 @@ in }; makeCommonUser = - { enableDevelopmentKit + { enableDevelopmentKit ? false , fullName , email , extraGitConfigs ? [ ] + , name + , homeDirectory ? null , ... }: { pkgs, ... }: { home = { + username = name; + homeDirectory = if (builtins.isNull homeDirectory) then "/home/${name}" else homeDirectory; stateVersion = stateVersion; shellAliases = { cat = "bat"; diff --git a/modules/lib.nix b/modules/lib.nix index 4519200..8aa92c0 100644 --- a/modules/lib.nix +++ b/modules/lib.nix @@ -66,7 +66,7 @@ let , system ? "x86_64-linux" }: let - hm = (import ../home-manager.nix { + hm = (import ./home-manager.nix { stateVersion = homeManagerVersion; }); pkgs = allPkgs."${system}"; From afaacd003d80337484f9b74eab8b13a0de05eb5d Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sat, 10 Aug 2024 22:32:57 -0400 Subject: [PATCH 6/8] moved hm to home/ --- modules/home-manager.nix | 105 ----------------------- modules/home/default.nix | 55 ++++++++++++ modules/home/git.nix | 29 +++++++ modules/{ => home}/gitconfigs/alias.conf | 0 modules/home/programs.nix | 33 +++++++ modules/home/services.nix | 8 ++ modules/lib.nix | 2 +- modules/skyg/user.nix | 2 +- 8 files changed, 127 insertions(+), 107 deletions(-) delete mode 100644 modules/home-manager.nix create mode 100644 modules/home/default.nix create mode 100644 modules/home/git.nix rename modules/{ => home}/gitconfigs/alias.conf (100%) create mode 100644 modules/home/programs.nix create mode 100644 modules/home/services.nix diff --git a/modules/home-manager.nix b/modules/home-manager.nix deleted file mode 100644 index f226ca1..0000000 --- a/modules/home-manager.nix +++ /dev/null @@ -1,105 +0,0 @@ -{ stateVersion }: -let - gitconfigs = - (builtins.filterSource (path: type: type != "directory") ./gitconfigs); - gitconfigFiles = builtins.attrNames (builtins.readDir gitconfigs); - makeCommonGitConfigs = { extraGitConfigs ? [ ] }: { - delta = { enable = true; }; - extraConfig = { - color = { ui = "auto"; }; - push = { - default = "upstream"; - autoSetupRemote = true; - }; - init = { defaultBranch = "main"; }; - }; - includes = - (builtins.map (f: { path = gitconfigs + "/" + f; }) gitconfigFiles) - ++ extraGitConfigs; - }; - commonProgramsConfig = { pkgs }: { - bat.enable = true; - neovim = { - enable = true; - defaultEditor = true; - viAlias = true; - vimAlias = true; - }; - direnv.enable = true; - lsd = { - enable = true; - enableAliases = true; - }; - zsh = { - enable = true; - autosuggestion.enable = true; - initExtra = '' - export PROMPT='%(!.%{%F{yellow}%}.)$USER@%{$fg[white]%}%M %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' - ''; - }; - zsh.oh-my-zsh = { - enable = true; - plugins = [ "git" "sudo" ]; - theme = "robbyrussell"; - }; - tmux = { - enable = true; - clock24 = true; - mouse = true; - plugins = with pkgs.tmuxPlugins; [ nord cpu battery sidebar ]; - }; - }; -in -{ - makeRootUser = { pkgs, ... }: { - home = { - stateVersion = stateVersion; - shellAliases = { - cat = "bat"; - }; - }; - programs = { - git = { - enable = true; - userName = "root"; - } // (makeCommonGitConfigs { extraGitConfigs = [ ]; }); - } // (commonProgramsConfig { pkgs = pkgs; }); - }; - - makeCommonUser = - { enableDevelopmentKit ? false - , fullName - , email - , extraGitConfigs ? [ ] - , name - , homeDirectory ? null - , ... - }: { pkgs, ... }: { - home = { - username = name; - homeDirectory = if (builtins.isNull homeDirectory) then "/home/${name}" else homeDirectory; - stateVersion = stateVersion; - shellAliases = { - cat = "bat"; - }; - packages = with pkgs; - [ jq nixpkgs-fmt ipfetch nixd ] - ++ (if enableDevelopmentKit then [ - rye - devenv - uv - devbox - terraform - kubectl - ] else - [ ]); - }; - programs = { - git = { - enable = true; - userName = fullName; - userEmail = email; - } // (makeCommonGitConfigs { extraGitConfigs = extraGitConfigs; }); - } // (commonProgramsConfig { pkgs = pkgs; }); - }; -} diff --git a/modules/home/default.nix b/modules/home/default.nix new file mode 100644 index 0000000..d8f142f --- /dev/null +++ b/modules/home/default.nix @@ -0,0 +1,55 @@ +{ stateVersion }: +let + makeCommonGitConfigs = (import ./git).makeCommonGitConfigs; + programsModule = (import ./programs); + servicesModule = (import ./services); + homeModule = { + stateVersion = stateVersion; + shellAliases = { + cat = "bat"; + }; + }; +in +{ + makeRootUser = { hostName }: { pkgs, ... }: { + home = homeModule; + programs = (programsModule { pkgs = pkgs; }) // { + git = (makeCommonGitConfigs { + userName = "root"; + userEmail = "root@${hostName}"; + extraGitConfigs = [ ]; + }); + }; + services = servicesModule { pkgs = pkgs; }; + }; + + makeCommonUser = + { enableDevelopmentKit + , fullName + , email + , extraGitConfigs ? [ ] + , ... + }: { pkgs, ... }: { + home = homeModule // { + packages = with pkgs; + [ jq nixpkgs-fmt ipfetch nixd ] + ++ (if enableDevelopmentKit then [ + rye + devenv + uv + devbox + terraform + kubectl + ] else + [ ]); + }; + programs = (programsModule { pkgs = pkgs; }) // { + git = (makeCommonGitConfigs { + userName = fullName; + userEmail = email; + extraGitConfigs = extraGitConfigs; + }); + }; + services = servicesModule { pkgs = pkgs; }; + }; +} diff --git a/modules/home/git.nix b/modules/home/git.nix new file mode 100644 index 0000000..23b6731 --- /dev/null +++ b/modules/home/git.nix @@ -0,0 +1,29 @@ +let + gitconfigs = + (builtins.filterSource (path: type: type != "directory") ./gitconfigs); + gitconfigFiles = builtins.attrNames (builtins.readDir gitconfigs); + makeCommonGitConfigs = + { userName + , userEmail + , extraGitConfigs ? [ ] + }: { + enable = true; + userName = userName; + userEmail = userEmail; + delta = { enable = true; }; + extraConfig = { + color = { ui = "auto"; }; + push = { + default = "upstream"; + autoSetupRemote = true; + }; + init = { defaultBranch = "main"; }; + }; + includes = + (builtins.map (f: { path = gitconfigs + "/" + f; }) gitconfigFiles) + ++ extraGitConfigs; + }; +in +{ + makeCommonGitConfigs = makeCommonGitConfigs; +} diff --git a/modules/gitconfigs/alias.conf b/modules/home/gitconfigs/alias.conf similarity index 100% rename from modules/gitconfigs/alias.conf rename to modules/home/gitconfigs/alias.conf diff --git a/modules/home/programs.nix b/modules/home/programs.nix new file mode 100644 index 0000000..4a48e75 --- /dev/null +++ b/modules/home/programs.nix @@ -0,0 +1,33 @@ +{ pkgs, ... }: +{ + bat.enable = true; + neovim = { + enable = true; + defaultEditor = true; + viAlias = true; + vimAlias = true; + }; + direnv.enable = true; + lsd = { + enable = true; + enableAliases = true; + }; + zsh = { + enable = true; + autosuggestion.enable = true; + initExtra = '' + export PROMPT='%(!.%{%F{yellow}%}.)$USER@%{$fg[white]%}%M %{$fg[cyan]%}%c%{$reset_color%} $(git_prompt_info)' + ''; + oh-my-zsh = { + enable = true; + plugins = [ "git" "sudo" ]; + theme = "robbyrussell"; + }; + }; + tmux = { + enable = true; + clock24 = true; + mouse = true; + plugins = with pkgs.tmuxPlugins; [ nord cpu battery sidebar ]; + }; +} diff --git a/modules/home/services.nix b/modules/home/services.nix new file mode 100644 index 0000000..6a03bed --- /dev/null +++ b/modules/home/services.nix @@ -0,0 +1,8 @@ +{ pkgs, ... }: +{ + gpg-agent = { + enable = true; + defaultCacheTtl = 1800; + enableSshSupport = true; + }; +} diff --git a/modules/lib.nix b/modules/lib.nix index 8aa92c0..d304376 100644 --- a/modules/lib.nix +++ b/modules/lib.nix @@ -66,7 +66,7 @@ let , system ? "x86_64-linux" }: let - hm = (import ./home-manager.nix { + hm = (import ./home { stateVersion = homeManagerVersion; }); pkgs = allPkgs."${system}"; diff --git a/modules/skyg/user.nix b/modules/skyg/user.nix index 897e982..f822ff5 100644 --- a/modules/skyg/user.nix +++ b/modules/skyg/user.nix @@ -38,7 +38,7 @@ in config = let - hm = (import ../home-manager.nix { + hm = (import ../home { stateVersion = cfg.home-manager.version; }); in From 8f8d23fb62b53231563a4cf7d9d39a2b45508b85 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sat, 10 Aug 2024 22:39:54 -0400 Subject: [PATCH 7/8] more refactoring of home manager --- modules/home/default.nix | 11 +++++++---- modules/skyg/core.nix | 1 - modules/skyg/user.nix | 6 ++++-- 3 files changed, 11 insertions(+), 7 deletions(-) diff --git a/modules/home/default.nix b/modules/home/default.nix index d8f142f..365e6b4 100644 --- a/modules/home/default.nix +++ b/modules/home/default.nix @@ -1,8 +1,8 @@ { stateVersion }: let - makeCommonGitConfigs = (import ./git).makeCommonGitConfigs; - programsModule = (import ./programs); - servicesModule = (import ./services); + makeCommonGitConfigs = (import ./git.nix).makeCommonGitConfigs; + programsModule = (import ./programs.nix); + servicesModule = (import ./services.nix); homeModule = { stateVersion = stateVersion; shellAliases = { @@ -24,13 +24,16 @@ in }; makeCommonUser = - { enableDevelopmentKit + { enableDevelopmentKit ? false , fullName , email , extraGitConfigs ? [ ] + , name , ... }: { pkgs, ... }: { home = homeModule // { + username = name; + homeDirectory = "/home/${name}"; packages = with pkgs; [ jq nixpkgs-fmt ipfetch nixd ] ++ (if enableDevelopmentKit then [ diff --git a/modules/skyg/core.nix b/modules/skyg/core.nix index 812bfba..f6ccef7 100644 --- a/modules/skyg/core.nix +++ b/modules/skyg/core.nix @@ -17,7 +17,6 @@ in config = { users.users.root.shell = pkgs.zsh; - home-manager.users.root.programs.git.userEmail = "root@${cfg.hostName}"; networking.hostName = cfg.hostName; }; } diff --git a/modules/skyg/user.nix b/modules/skyg/user.nix index f822ff5..fcd055c 100644 --- a/modules/skyg/user.nix +++ b/modules/skyg/user.nix @@ -45,7 +45,9 @@ in mkIf cfg.user.enabled { programs.zsh.enable = true; - home-manager.users.root = hm.makeRootUser { pkgs = pkgs; }; - home-manager.users.${cfg.user.name} = (hm.makeCommonUser cfg.user) { pkgs = pkgs; }; + home-manager.users.root = + (hm.makeRootUser { hostName = config.skyg.core.hostName; }) { pkgs = pkgs; }; + home-manager.users.${cfg.user.name} = + (hm.makeCommonUser cfg.user) { pkgs = pkgs; }; }; } From 4e25515b14e555d4f93780e89061a53c72ad9265 Mon Sep 17 00:00:00 2001 From: Ari Sosnovsky Date: Sat, 10 Aug 2024 22:41:20 -0400 Subject: [PATCH 8/8] Added comments --- flake.nix | 2 ++ 1 file changed, 2 insertions(+) diff --git a/flake.nix b/flake.nix index 157565b..05fe2e9 100644 --- a/flake.nix +++ b/flake.nix @@ -132,6 +132,8 @@ (import ./hosts/asosnovsky-mac.nix { user = sumoUser; }); }; + # None-NIXOS LINUX Setups + # ------------- homeConfigurations."${user.name}" = lib.makeHomeManagerUsers { user = user; homeManagerVersion = homeManagerVersion;