nixos module: install user packages through NixOS
We cannot guarantee that the Nix store will be writable during startup so installing the user packages through `nix-env -i` may fail. Therefore, when building through the NixOS module install through the `users.users.<name?>.packages` option.
This commit is contained in:
parent
a3462daeb1
commit
127e28c7d8
|
@ -307,9 +307,31 @@ 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, if we are running as a NixOS module then we cannot rely on
|
||||
# `nix-env -i` because our target may not allow modification of
|
||||
# the Nix store. We will instead use the
|
||||
# `users.users.<name?>.packages` NixOS option. We still need this
|
||||
# activation command, however, since some modules need to ensure
|
||||
# that their activation commands are run after packages are
|
||||
# guaranteed to be installed.
|
||||
#
|
||||
# In case the user has moved from a user-install of Home Manager
|
||||
# to one managed through the NixOS module we attempt to uninstall
|
||||
# the `home-manager-path` package if it is installed.
|
||||
home.activation.installPackages = dag.entryAfter ["writeBoundary"] (
|
||||
if config.submoduleSupport.enable
|
||||
then
|
||||
''
|
||||
if nix-env -q | grep '^home-manager-path$'; then
|
||||
nix-env -e home-manager-path
|
||||
fi
|
||||
''
|
||||
else
|
||||
''
|
||||
$DRY_RUN_CMD nix-env -i ${cfg.path}
|
||||
''
|
||||
);
|
||||
|
||||
home.activationPackage =
|
||||
let
|
||||
|
|
|
@ -30,6 +30,10 @@ in
|
|||
};
|
||||
|
||||
config = mkIf (cfg.users != {}) {
|
||||
users.users = 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}";
|
||||
|
|
Loading…
Reference in a new issue