aboutsummaryrefslogtreecommitdiff
path: root/nixos
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2017-12-19 15:43:40 +0100
committerRobert Helgesson <robert@rycee.net>2019-02-16 21:42:47 +0100
commitef168979bf88310459464e5fe3fbcf2d3cbe49b5 (patch)
treef9325ae5a5262e681b79c3858935e085cdba22c2 /nixos
parent2093cf425ff6af786a2effc776d3ac89b6787c0a (diff)
nixos module: support NixOS user packages install
When using the NixOS module we cannot guarantee that the Nix store will be writable during startup. Installing the user packages through `nix-env -i` will fail in these cases. This commit adds a NixOS option `home-manager.useUserPackages` that, when enabled, installs user packages through the NixOS users.users.<name?>.packages option. Note, when submodule support and external package install is enabled then the installed packages are not available in `~/.nix-profile`. We therefore set `home.profileDirectory` directly to the HM profile packages.
Diffstat (limited to 'nixos')
-rw-r--r--nixos/default.nix24
1 files changed, 19 insertions, 5 deletions
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}";