2017-10-14 20:56:02 +02:00
|
|
|
{ config, lib, pkgs, utils, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.home-manager;
|
|
|
|
|
|
|
|
hmModule = types.submodule ({name, ...}: {
|
2019-02-09 15:08:16 +01:00
|
|
|
imports = import ../modules/modules.nix { inherit lib pkgs; };
|
2017-10-14 20:56:02 +02:00
|
|
|
|
|
|
|
config = {
|
2019-02-09 15:08:16 +01:00
|
|
|
submoduleSupport.enable = true;
|
2017-12-19 15:43:40 +01:00
|
|
|
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
2017-12-21 12:19:07 +01:00
|
|
|
|
|
|
|
# The per-user directory inside /etc/profiles is not known by
|
|
|
|
# fontconfig by default.
|
|
|
|
fonts.fontconfig.enableProfileFonts =
|
|
|
|
cfg.useUserPackages && config.fonts.fontconfig.enable;
|
|
|
|
|
2017-10-14 20:56:02 +02:00
|
|
|
home.username = config.users.users.${name}.name;
|
|
|
|
home.homeDirectory = config.users.users.${name}.home;
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
options = {
|
2017-12-19 15:43:40 +01:00
|
|
|
home-manager = {
|
|
|
|
useUserPackages = mkEnableOption ''
|
|
|
|
installation of user packages through the
|
|
|
|
<option>users.users.<name?>.packages</option> option.
|
2017-10-14 20:56:02 +02:00
|
|
|
'';
|
2017-12-19 15:43:40 +01:00
|
|
|
|
|
|
|
users = mkOption {
|
|
|
|
type = types.attrsOf hmModule;
|
|
|
|
default = {};
|
|
|
|
description = ''
|
|
|
|
Per-user Home Manager configuration.
|
|
|
|
'';
|
|
|
|
};
|
2017-10-14 20:56:02 +02:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
config = mkIf (cfg.users != {}) {
|
2019-02-28 01:52:48 +01:00
|
|
|
assertions =
|
|
|
|
flatten (flip mapAttrsToList cfg.users (user: config:
|
|
|
|
flip map config.assertions (assertion:
|
|
|
|
{
|
|
|
|
inherit (assertion) assertion;
|
|
|
|
message = "${user} profile: ${assertion.message}";
|
|
|
|
}
|
|
|
|
)
|
|
|
|
));
|
|
|
|
|
2017-12-19 15:43:40 +01:00
|
|
|
users.users = mkIf cfg.useUserPackages (
|
|
|
|
mapAttrs (username: usercfg: {
|
|
|
|
packages = usercfg.home.packages;
|
|
|
|
}) cfg.users
|
|
|
|
);
|
|
|
|
|
2017-10-14 20:56:02 +02:00
|
|
|
systemd.services = mapAttrs' (username: usercfg:
|
|
|
|
nameValuePair ("home-manager-${utils.escapeSystemdPath username}") {
|
|
|
|
description = "Home Manager environment for ${username}";
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2018-07-21 13:15:34 +02:00
|
|
|
wants = [ "nix-daemon.socket" ];
|
|
|
|
after = [ "nix-daemon.socket" ];
|
2017-10-14 20:56:02 +02:00
|
|
|
|
|
|
|
serviceConfig = {
|
2019-02-08 19:58:26 +01:00
|
|
|
User = usercfg.home.username;
|
2017-10-14 20:56:02 +02:00
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
SyslogIdentifier = "hm-activate-${username}";
|
|
|
|
|
|
|
|
# The activation script is run by a login shell to make sure
|
|
|
|
# that the user is given a sane Nix environment.
|
|
|
|
ExecStart = pkgs.writeScript "activate-${username}" ''
|
|
|
|
#! ${pkgs.stdenv.shell} -el
|
|
|
|
echo Activating home-manager configuration for ${username}
|
|
|
|
exec ${usercfg.home.activationPackage}/activate
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
}
|
|
|
|
) cfg.users;
|
|
|
|
};
|
|
|
|
}
|