Compare commits

...

3 commits

Author SHA1 Message Date
Robert Helgesson 259c3db689
home-environment: use generation path as profile path 2019-02-11 22:07:19 +01:00
Robert Helgesson 4b7809efff
fontconfig: make fonts accessible when in NixOS module 2019-02-11 22:07:18 +01:00
Robert Helgesson 127e28c7d8
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.
2019-02-11 21:45:20 +01:00
3 changed files with 61 additions and 14 deletions

View file

@ -269,7 +269,10 @@ 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
then config.home.path
else cfg.homeDirectory + "/.nix-profile";
home.sessionVariables =
let
@ -307,9 +310,31 @@ in
home.activation.writeBoundary = dag.entryAnywhere "";
# Install packages to the user environment.
home.activation.installPackages = dag.entryAfter ["writeBoundary"] ''
#
# 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

View file

@ -28,7 +28,8 @@ in
};
};
config = mkIf cfg.enableProfileFonts {
config = mkMerge [
(mkIf cfg.enableProfileFonts {
xdg.configFile."fontconfig/conf.d/10-nix-profile-fonts.conf".text = ''
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
@ -37,5 +38,22 @@ in
<dir>${config.home.profileDirectory}/share/fonts</dir>
</fontconfig>
'';
};
})
# If we are inside a NixOS system configuration then packages are
# installed through the NixOS `users.users.<name?>.packages`
# option. Unfortunately fontconfig does not know about the
# per-user installation directory so we have to add that directory
# in a extra configuration file.
(mkIf config.submoduleSupport.enable {
xdg.configFile."fontconfig/conf.d/10-nix-per-user-fonts.conf".text = ''
<?xml version='1.0'?>
<!DOCTYPE fontconfig SYSTEM 'fonts.dtd'>
<fontconfig>
<dir>/etc/profiles/per-user/${config.home.username}/lib/X11/fonts</dir>
<dir>/etc/profiles/per-user/${config.home.username}/share/fonts</dir>
</fontconfig>
'';
})
];
}

View file

@ -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}";