From 40b42028d2e56e091d6b687c252ce2c86fb03f5f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Schwarz=C3=A4ugl?= Date: Sat, 1 Nov 2025 23:56:37 +0100 Subject: [PATCH] feat[client]: make home-manager more convenient to use --- SwarselSystems.org | 149 ++++++++++++++++++------------- modules/home/common/settings.nix | 14 ++- nix/devshell.nix | 10 ++- 3 files changed, 108 insertions(+), 65 deletions(-) diff --git a/SwarselSystems.org b/SwarselSystems.org index 9bfdf82..c614af1 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -1259,10 +1259,18 @@ Lastly, in the =perSystem= attribute set, we see that it is actually passed some pkgs.age pkgs.ssh-to-age pkgs.sops - pkgs.home-manager pkgs.nixpkgs-fmt self.packages.${system}.swarsel-build self.packages.${system}.swarsel-deploy + (pkgs.symlinkJoin { + name = "home-manager"; + buildInputs = [ pkgs.makeWrapper ]; + paths = [ pkgs.home-manager ]; + postBuild = '' + wrapProgram $out/bin/home-manager \ + --append-flags '--flake .#$(hostname)' + ''; + }) ]; commands = [ @@ -11043,81 +11051,96 @@ This section sets up all the imports that are used in the home-manager section. Again, we adapt =nix= to our needs, enable the home-manager command for non-NixOS machines (NixOS machines are using it as a module) and setting user information that I always keep the same. #+begin_src nix-ts :tangle modules/home/common/settings.nix - { self, lib, pkgs, config, ... }: + { self, lib, pkgs, config, ... }: + let + inherit (config.swarselsystems) mainUser; + in + { + options.swarselmodules.general = lib.mkEnableOption "general nix settings"; + config = let - inherit (config.swarselsystems) mainUser; + nix-version = "2_30"; in - { - options.swarselmodules.general = lib.mkEnableOption "general nix settings"; - config = let - nix-version = "2_30"; - in lib.mkIf config.swarselmodules.general { - nix = lib.mkIf (!config.swarselsystems.isNixos) { - package = lib.mkForce pkgs.nixVersions."nix_${nix-version}"; - # extraOptions = '' - # plugin-files = ${pkgs.dev.nix-plugins}/lib/nix/plugins - # extra-builtins-file = ${self + /nix/extra-builtins.nix} - # ''; - extraOptions = let + lib.mkIf config.swarselmodules.general { + nix = lib.mkIf (!config.swarselsystems.isNixos) { + package = lib.mkForce pkgs.nixVersions."nix_${nix-version}"; + # extraOptions = '' + # plugin-files = ${pkgs.dev.nix-plugins}/lib/nix/plugins + # extra-builtins-file = ${self + /nix/extra-builtins.nix} + # ''; + extraOptions = + let nix-plugins = pkgs.nix-plugins.override { nixComponents = pkgs.nixVersions."nixComponents_${nix-version}"; }; in - '' + '' plugin-files = ${nix-plugins}/lib/nix/plugins extra-builtins-file = ${self + /nix/extra-builtins.nix} ''; - settings = { - experimental-features = [ - "nix-command" - "flakes" - "ca-derivations" - "cgroups" - "pipe-operators" - ]; - trusted-users = [ "@wheel" "${mainUser}" ]; - connect-timeout = 5; - bash-prompt-prefix = "$SHLVL:\\w "; - bash-prompt = "$(if [[ $? -gt 0 ]]; then printf \"\"; else printf \"\"; fi)λ "; - fallback = true; - min-free = 128000000; - max-free = 1000000000; - auto-optimise-store = true; - warn-dirty = false; - max-jobs = 1; - use-cgroups = lib.mkIf config.swarselsystems.isLinux true; - }; - }; - - nixpkgs.overlays = lib.mkIf config.swarselsystems.isNixos (lib.mkForce null); - - programs = { - home-manager.enable = lib.mkIf (!config.swarselsystems.isNixos) true; - man = { - enable = true; - generateCaches = true; - }; - }; - - targets.genericLinux.enable = lib.mkIf (!config.swarselsystems.isNixos) true; - - home = { - username = lib.mkDefault mainUser; - homeDirectory = lib.mkDefault "/home/${mainUser}"; - stateVersion = lib.mkDefault "23.05"; - keyboard.layout = "us"; - sessionVariables = { - FLAKE = "/home/${mainUser}/.dotfiles"; - }; - extraOutputsToInstall = [ - "doc" - "info" - "devdoc" + settings = { + experimental-features = [ + "nix-command" + "flakes" + "ca-derivations" + "cgroups" + "pipe-operators" ]; + trusted-users = [ "@wheel" "${mainUser}" ]; + connect-timeout = 5; + bash-prompt-prefix = "$SHLVL:\\w "; + bash-prompt = "$(if [[ $? -gt 0 ]]; then printf \"\"; else printf \"\"; fi)λ "; + fallback = true; + min-free = 128000000; + max-free = 1000000000; + auto-optimise-store = true; + warn-dirty = false; + max-jobs = 1; + use-cgroups = lib.mkIf config.swarselsystems.isLinux true; }; }; - } + nixpkgs.overlays = lib.mkIf config.swarselsystems.isNixos (lib.mkForce null); + + programs = { + home-manager = lib.mkIf (!config.swarselsystems.isNixos) + { + enable = true; + package = pkgs.symlinkJoin { + name = "home-manager"; + buildInputs = [ pkgs.makeWrapper ]; + paths = [ pkgs.home-manager ]; + postBuild = '' + wrapProgram $out/bin/home-manager \ + --append-flags '--flake .#$(hostname)' + ''; + }; + }; + man = { + enable = true; + generateCaches = true; + }; + }; + + targets.genericLinux.enable = lib.mkIf (!config.swarselsystems.isNixos) true; + + home = { + username = lib.mkDefault mainUser; + homeDirectory = lib.mkDefault "/home/${mainUser}"; + stateVersion = lib.mkDefault "23.05"; + keyboard.layout = "us"; + sessionVariables = { + FLAKE = "/home/${mainUser}/.dotfiles"; + }; + extraOutputsToInstall = [ + "doc" + "info" + "devdoc" + ]; + }; + }; + + } #+end_src **** nixGL diff --git a/modules/home/common/settings.nix b/modules/home/common/settings.nix index 50122ce..9138a5e 100644 --- a/modules/home/common/settings.nix +++ b/modules/home/common/settings.nix @@ -50,7 +50,19 @@ in nixpkgs.overlays = lib.mkIf config.swarselsystems.isNixos (lib.mkForce null); programs = { - home-manager.enable = lib.mkIf (!config.swarselsystems.isNixos) true; + home-manager = lib.mkIf (!config.swarselsystems.isNixos) + { + enable = true; + package = pkgs.symlinkJoin { + name = "home-manager"; + buildInputs = [ pkgs.makeWrapper ]; + paths = [ pkgs.home-manager ]; + postBuild = '' + wrapProgram $out/bin/home-manager \ + --append-flags '--flake .#$(hostname)' + ''; + }; + }; man = { enable = true; generateCaches = true; diff --git a/nix/devshell.nix b/nix/devshell.nix index 9d2f62f..2969bcf 100644 --- a/nix/devshell.nix +++ b/nix/devshell.nix @@ -58,10 +58,18 @@ pkgs.age pkgs.ssh-to-age pkgs.sops - pkgs.home-manager pkgs.nixpkgs-fmt self.packages.${system}.swarsel-build self.packages.${system}.swarsel-deploy + (pkgs.symlinkJoin { + name = "home-manager"; + buildInputs = [ pkgs.makeWrapper ]; + paths = [ pkgs.home-manager ]; + postBuild = '' + wrapProgram $out/bin/home-manager \ + --append-flags '--flake .#$(hostname)' + ''; + }) ]; commands = [