aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/home-environment.nix36
-rw-r--r--modules/misc/news.nix18
-rw-r--r--modules/misc/submodule-support.nix13
-rw-r--r--nixos/default.nix24
4 files changed, 82 insertions, 9 deletions
diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index c98cb9ea966..6e8c7cf9620 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -269,7 +269,11 @@ in
home.username = mkDefault (builtins.getEnv "USER");
home.homeDirectory = mkDefault (builtins.getEnv "HOME");
- home.profileDirectory = cfg.homeDirectory + "/.nix-profile";
+ home.profileDirectory =
+ if config.submoduleSupport.enable
+ && config.submoduleSupport.externalPackageInstall
+ then config.home.path
+ else cfg.homeDirectory + "/.nix-profile";
home.sessionVariables =
let
@@ -307,9 +311,33 @@ in
home.activation.writeBoundary = dag.entryAnywhere "";
# Install packages to the user environment.
- home.activation.installPackages = dag.entryAfter ["writeBoundary"] ''
- $DRY_RUN_CMD nix-env -i ${cfg.path}
- '';
+ #
+ # Note, sometimes our target may not allow modification of the Nix
+ # store and then we cannot rely on `nix-envย -i`. This is the case,
+ # for example, if we are running as a NixOS module and building a
+ # virtual machine. Then we must instead rely on an external
+ # mechanism for installing packages, which in NixOS is provided by
+ # the `users.users.<name?>.packages` option. The activation
+ # command is still needed since some modules need to run their
+ # activation commands after the packages are guaranteed to be
+ # installed.
+ #
+ # In case the user has moved from a user-install of Home Manager
+ # to a submodule managed one we attempt to uninstall the
+ # `home-manager-path` package if it is installed.
+ home.activation.installPackages = dag.entryAfter ["writeBoundary"] (
+ if config.submoduleSupport.externalPackageInstall
+ then
+ ''
+ if nix-env -q | grep '^home-manager-path$'; then
+ $DRY_RUN_CMD nix-env -e home-manager-path
+ fi
+ ''
+ else
+ ''
+ $DRY_RUN_CMD nix-env -i ${cfg.path}
+ ''
+ );
home.activationPackage =
let
diff --git a/modules/misc/news.nix b/modules/misc/news.nix
index 9405e4c2c17..ee09b9ad826 100644
--- a/modules/misc/news.nix
+++ b/modules/misc/news.nix
@@ -966,6 +966,24 @@ in
as an Emacs daemon.
'';
}
+
+ {
+ time = "2019-02-16T20:33:56+00:00";
+ condition = hostPlatform.isLinux;
+ message = ''
+ When using Home Manager as a NixOS submodule it is now
+ possible to install packages using the NixOS
+
+ users.users.<name?>.packages
+
+ option. This is enabled by adding
+
+ home-manager.useUserPackages = true;
+
+ to your NixOS system configuration. This mode of operation
+ is necessary if you want to use 'nixos-rebuild build-vm'.
+ '';
+ }
];
};
}
diff --git a/modules/misc/submodule-support.nix b/modules/misc/submodule-support.nix
index cffdcb9e95c..d6138c7ccd8 100644
--- a/modules/misc/submodule-support.nix
+++ b/modules/misc/submodule-support.nix
@@ -15,5 +15,18 @@ with lib;
in, for example, NixOS or nix-darwin.
'';
};
+
+ externalPackageInstall = mkOption {
+ type = types.bool;
+ default = false;
+ internal = true;
+ description = ''
+ Whether the packages of <option>home.packages</option> are
+ installed separately from the Home Manager activation script.
+ In NixOS, for example, this may be accomplished by installing
+ the packages through
+ <option>users.users.&lt;name?&gt;.packages</option>.
+ '';
+ };
};
}
diff --git a/nixos/default.nix b/nixos/default.nix
index 1e1131f9cc7..5dec943b946 100644
--- a/nixos/default.nix
+++ b/nixos/default.nix
@@ -11,6 +11,7 @@ let
config = {
submoduleSupport.enable = true;
+ submoduleSupport.externalPackageInstall = cfg.useUserPackages;
home.username = config.users.users.${name}.name;
home.homeDirectory = config.users.users.${name}.home;
};
@@ -20,16 +21,29 @@ in
{
options = {
- home-manager.users = mkOption {
- type = types.attrsOf hmModule;
- default = {};
- description = ''
- Per-user Home Manager configuration.
+ home-manager = {
+ useUserPackages = mkEnableOption ''
+ installation of user packages through the
+ <option>users.users.&lt;name?&gt;.packages</option> option.
'';
+
+ users = mkOption {
+ type = types.attrsOf hmModule;
+ default = {};
+ description = ''
+ Per-user Home Manager configuration.
+ '';
+ };
};
};
config = mkIf (cfg.users != {}) {
+ users.users = mkIf cfg.useUserPackages (
+ mapAttrs (username: usercfg: {
+ packages = usercfg.home.packages;
+ }) cfg.users
+ );
+
systemd.services = mapAttrs' (username: usercfg:
nameValuePair ("home-manager-${utils.escapeSystemdPath username}") {
description = "Home Manager environment for ${username}";