From 78576b817fdd88a75c6adf512e9ba20551662cef Mon Sep 17 00:00:00 2001 From: Janik <80165193+Janik-Haag@users.noreply.github.com> Date: Tue, 4 Feb 2025 22:29:41 +0100 Subject: [PATCH] home-manager: add lib support for non-flake users (#5429) --- default.nix | 1 + flake.nix | 51 +------------------------------------------------ lib/default.nix | 49 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 51 insertions(+), 50 deletions(-) create mode 100644 lib/default.nix diff --git a/default.nix b/default.nix index 7df2dbd43..abf4e678b 100644 --- a/default.nix +++ b/default.nix @@ -24,6 +24,7 @@ in rec { pkgs.callPackage ./home-manager/install.nix { inherit home-manager; }; nixos = import ./nixos; + lib = import ./lib { inherit (pkgs) lib; }; inherit path; } diff --git a/flake.nix b/flake.nix index 5f9df5825..4b797355e 100644 --- a/flake.nix +++ b/flake.nix @@ -41,56 +41,7 @@ defaultTemplate = self.templates.standalone; - lib = { - hm = (import ./modules/lib/stdlib-extended.nix nixpkgs.lib).hm; - homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib - , extraSpecialArgs ? { }, check ? true - # Deprecated: - , configuration ? null, extraModules ? null, stateVersion ? null - , username ? null, homeDirectory ? null, system ? null }@args: - let - msgForRemovedArg = '' - The 'homeManagerConfiguration' arguments - - - 'configuration', - - 'username', - - 'homeDirectory' - - 'stateVersion', - - 'extraModules', and - - 'system' - - have been removed. Instead use the arguments 'pkgs' and - 'modules'. See the 22.11 release notes for more: https://nix-community.github.io/home-manager/release-notes.xhtml#sec-release-22.11-highlights - ''; - - throwForRemovedArgs = v: - let - used = builtins.filter (n: (args.${n} or null) != null) [ - "configuration" - "username" - "homeDirectory" - "stateVersion" - "extraModules" - "system" - ]; - msg = msgForRemovedArg + '' - - - Deprecated args passed: '' - + builtins.concatStringsSep " " used; - in lib.throwIf (used != [ ]) msg v; - - in throwForRemovedArgs (import ./modules { - inherit pkgs lib check extraSpecialArgs; - configuration = { ... }: { - imports = modules ++ [{ programs.home-manager.path = "${./.}"; }]; - nixpkgs = { - config = nixpkgs.lib.mkDefault pkgs.config; - inherit (pkgs) overlays; - }; - }; - }); - }; + lib = import ./lib { inherit (nixpkgs) lib; }; } // (let forAllSystems = nixpkgs.lib.genAttrs nixpkgs.lib.systems.flakeExposed; in { diff --git a/lib/default.nix b/lib/default.nix new file mode 100644 index 000000000..5d0eb5f41 --- /dev/null +++ b/lib/default.nix @@ -0,0 +1,49 @@ +{ lib }: { + hm = (import ../modules/lib/stdlib-extended.nix lib).hm; + homeManagerConfiguration = { modules ? [ ], pkgs, lib ? pkgs.lib + , extraSpecialArgs ? { }, check ? true + # Deprecated: + , configuration ? null, extraModules ? null, stateVersion ? null + , username ? null, homeDirectory ? null, system ? null }@args: + let + msgForRemovedArg = '' + The 'homeManagerConfiguration' arguments + + - 'configuration', + - 'username', + - 'homeDirectory' + - 'stateVersion', + - 'extraModules', and + - 'system' + + have been removed. Instead use the arguments 'pkgs' and + 'modules'. See the 22.11 release notes for more: https://nix-community.github.io/home-manager/release-notes.xhtml#sec-release-22.11-highlights + ''; + + throwForRemovedArgs = v: + let + used = builtins.filter (n: (args.${n} or null) != null) [ + "configuration" + "username" + "homeDirectory" + "stateVersion" + "extraModules" + "system" + ]; + msg = msgForRemovedArg + '' + + + Deprecated args passed: '' + builtins.concatStringsSep " " used; + in lib.throwIf (used != [ ]) msg v; + + in throwForRemovedArgs (import ../modules { + inherit pkgs lib check extraSpecialArgs; + configuration = { ... }: { + imports = modules ++ [{ programs.home-manager.path = "${../.}"; }]; + nixpkgs = { + config = lib.mkDefault pkgs.config; + inherit (pkgs) overlays; + }; + }; + }); +}