2017-10-14 20:56:02 +02:00
|
|
|
|
{ config, lib, pkgs, utils, ... }:
|
|
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
|
|
cfg = config.home-manager;
|
|
|
|
|
|
2020-01-16 23:41:14 +01:00
|
|
|
|
extendedLib = import ../modules/lib/stdlib-extended.nix pkgs.lib;
|
|
|
|
|
|
|
|
|
|
hmModule = types.submoduleWith {
|
|
|
|
|
specialArgs = { lib = extendedLib; };
|
|
|
|
|
modules = [(
|
|
|
|
|
{name, ...}: {
|
|
|
|
|
imports = import ../modules/modules.nix {
|
|
|
|
|
inherit pkgs;
|
|
|
|
|
lib = extendedLib;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
config = {
|
|
|
|
|
submoduleSupport.enable = true;
|
|
|
|
|
submoduleSupport.externalPackageInstall = cfg.useUserPackages;
|
|
|
|
|
|
|
|
|
|
# The per-user directory inside /etc/profiles is not known by
|
|
|
|
|
# fontconfig by default.
|
|
|
|
|
fonts.fontconfig.enable =
|
|
|
|
|
cfg.useUserPackages && config.fonts.fontconfig.enable;
|
|
|
|
|
|
|
|
|
|
home.username = config.users.users.${name}.name;
|
|
|
|
|
home.homeDirectory = config.users.users.${name}.home;
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
)];
|
|
|
|
|
};
|
2017-10-14 20:56:02 +02:00
|
|
|
|
|
2019-08-08 18:24:08 +02:00
|
|
|
|
serviceEnvironment =
|
|
|
|
|
optionalAttrs (cfg.backupFileExtension != null) {
|
|
|
|
|
HOME_MANAGER_BACKUP_EXT = cfg.backupFileExtension;
|
|
|
|
|
}
|
|
|
|
|
// optionalAttrs cfg.verbose {
|
|
|
|
|
VERBOSE = "1";
|
|
|
|
|
};
|
|
|
|
|
|
2017-10-14 20:56:02 +02:00
|
|
|
|
in
|
|
|
|
|
|
|
|
|
|
{
|
|
|
|
|
options = {
|
2017-12-19 15:43:40 +01:00
|
|
|
|
home-manager = {
|
|
|
|
|
useUserPackages = mkEnableOption ''
|
|
|
|
|
installation of user packages through the
|
2019-09-01 21:28:40 +02:00
|
|
|
|
<option>users.users.‹name?›.packages</option> option.
|
2017-10-14 20:56:02 +02:00
|
|
|
|
'';
|
2017-12-19 15:43:40 +01:00
|
|
|
|
|
2019-08-08 18:24:08 +02:00
|
|
|
|
backupFileExtension = mkOption {
|
|
|
|
|
type = types.nullOr types.str;
|
|
|
|
|
default = null;
|
|
|
|
|
example = "backup";
|
|
|
|
|
description = ''
|
|
|
|
|
On activation move existing files by appending the given
|
|
|
|
|
file extension rather than exiting with an error.
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
verbose = mkEnableOption "verbose output on activation";
|
|
|
|
|
|
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-08-18 17:33:25 +02:00
|
|
|
|
warnings =
|
|
|
|
|
flatten (flip mapAttrsToList cfg.users (user: config:
|
|
|
|
|
flip map config.warnings (warning:
|
|
|
|
|
"${user} profile: ${warning}"
|
|
|
|
|
)
|
|
|
|
|
));
|
|
|
|
|
|
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
|
|
|
|
|
);
|
|
|
|
|
|
2019-05-24 09:17:25 +02:00
|
|
|
|
systemd.services = mapAttrs' (_: usercfg:
|
|
|
|
|
let
|
|
|
|
|
username = usercfg.home.username;
|
|
|
|
|
in
|
|
|
|
|
nameValuePair ("home-manager-${utils.escapeSystemdPath username}") {
|
|
|
|
|
description = "Home Manager environment for ${username}";
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
|
wants = [ "nix-daemon.socket" ];
|
|
|
|
|
after = [ "nix-daemon.socket" ];
|
2017-10-14 20:56:02 +02:00
|
|
|
|
|
2019-08-08 18:24:08 +02:00
|
|
|
|
environment = serviceEnvironment;
|
|
|
|
|
|
2019-05-24 09:17:25 +02:00
|
|
|
|
serviceConfig = {
|
|
|
|
|
User = usercfg.home.username;
|
|
|
|
|
Type = "oneshot";
|
|
|
|
|
RemainAfterExit = "yes";
|
|
|
|
|
SyslogIdentifier = "hm-activate-${username}";
|
2017-10-14 20:56:02 +02:00
|
|
|
|
|
2019-05-24 09:17:25 +02:00
|
|
|
|
# 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}" ''
|
2019-08-22 08:35:06 +02:00
|
|
|
|
#! ${pkgs.runtimeShell} -el
|
2019-05-24 09:17:25 +02:00
|
|
|
|
echo Activating home-manager configuration for ${username}
|
|
|
|
|
exec ${usercfg.home.activationPackage}/activate
|
|
|
|
|
'';
|
|
|
|
|
};
|
|
|
|
|
}
|
2017-10-14 20:56:02 +02:00
|
|
|
|
) cfg.users;
|
|
|
|
|
};
|
|
|
|
|
}
|