From efbe1383e64585ebc0303f4703e7e582aaf6b933 Mon Sep 17 00:00:00 2001 From: Erik Arvstedt Date: Sun, 1 Mar 2020 17:06:20 +0100 Subject: [PATCH] nixos integration: add option 'useGlobalPkgs' PR #1059 --- doc/installation.xml | 17 +++++++++++++++++ modules/misc/news.nix | 15 +++++++++++++++ modules/modules.nix | 18 ++++++++++++------ nixos/default.nix | 7 +++++++ 4 files changed, 51 insertions(+), 6 deletions(-) diff --git a/doc/installation.xml b/doc/installation.xml index 521198868..9c5d24b3d 100644 --- a/doc/installation.xml +++ b/doc/installation.xml @@ -225,6 +225,23 @@ home-manager.useUserPackages = true; become the default value in the future. + + + + By default, Home Manager uses a private pkgs instance + that is configured via the options. + To instead use the global pkgs that is configured via + the system level options, set + + +home-manager.useGlobalPkgs = true; + + + This saves an extra Nixpkgs evaluation, adds consistency, and removes the + dependency on NIX_PATH, which is otherwise used for + importing Nixpkgs. + +
nix-darwin module diff --git a/modules/misc/news.nix b/modules/misc/news.nix index 0f0c2ac16..cc2892e87 100644 --- a/modules/misc/news.nix +++ b/modules/misc/news.nix @@ -1351,6 +1351,21 @@ in '--description', '--on-event', and more. ''; } + + { + time = "2020-03-07T13:11:43+00:00"; + condition = hostPlatform.isLinux; + message = '' + The NixOS module has a new option: 'home-manager.useGlobalPkgs'. + + This enables using the system configuration's 'pkgs' + argument in Home Manager. + + To learn more, see the installation section of the manual + + https://rycee.gitlab.io/home-manager/#sec-install-nixos-module + ''; + } ]; }; } diff --git a/modules/modules.nix b/modules/modules.nix index 9d741016f..263c1176c 100644 --- a/modules/modules.nix +++ b/modules/modules.nix @@ -5,6 +5,9 @@ # Whether to enable module type checking. , check ? true + +# If disabled, the pkgs attribute passed to this function is used instead. +, useNixpkgsModule ? true }: with lib; @@ -27,7 +30,7 @@ let (loadModule ./misc/gtk.nix { }) (loadModule ./misc/lib.nix { }) (loadModule ./misc/news.nix { }) - (loadModule ./misc/nixpkgs.nix { }) + (loadModule ./misc/nixpkgs.nix { condition = useNixpkgsModule; }) (loadModule ./misc/numlock.nix { condition = hostPlatform.isLinux; }) (loadModule ./misc/pam.nix { }) (loadModule ./misc/qt.nix { }) @@ -170,11 +173,14 @@ let modules = map (getAttr "file") (filter (getAttr "condition") allModules); pkgsModule = { - config._module.args.baseModules = modules; - config._module.args.pkgs = lib.mkDefault pkgs; - config._module.check = check; - config.lib = lib.hm; - config.nixpkgs.system = mkDefault pkgs.system; + config = { + _module.args.baseModules = modules; + _module.args.pkgs = lib.mkDefault pkgs; + _module.check = check; + lib = lib.hm; + } // optionalAttrs useNixpkgsModule { + nixpkgs.system = mkDefault pkgs.system; + }; }; in diff --git a/nixos/default.nix b/nixos/default.nix index f4e417bda..4f7f18683 100644 --- a/nixos/default.nix +++ b/nixos/default.nix @@ -15,6 +15,7 @@ let imports = import ../modules/modules.nix { inherit pkgs; lib = extendedLib; + useNixpkgsModule = !cfg.useGlobalPkgs; }; config = { @@ -45,6 +46,12 @@ in { option. ''; + useGlobalPkgs = mkEnableOption '' + using the system configuration's pkgs + argument in Home Manager. This disables the Home Manager + options + ''; + backupFileExtension = mkOption { type = types.nullOr types.str; default = null;