2017-10-14 20:56:02 +02:00
|
|
|
{ config, lib, pkgs, utils, ... }:
|
|
|
|
|
|
|
|
with lib;
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.home-manager;
|
|
|
|
|
2020-02-02 00:39:17 +01: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
|
|
|
|
2020-02-02 00:39:17 +01:00
|
|
|
in {
|
2022-06-16 12:26:57 +02:00
|
|
|
imports = [ ./common.nix ];
|
2021-02-21 07:02:25 +01:00
|
|
|
|
2024-01-24 22:48:51 +01:00
|
|
|
options.home-manager = {
|
|
|
|
enableLegacyProfileManagement = mkOption {
|
|
|
|
type = types.bool;
|
|
|
|
default = versionOlder config.system.stateVersion "24.05";
|
|
|
|
defaultText = lib.literalMD ''
|
|
|
|
- `true` for `system.stateVersion` < 24.05,
|
|
|
|
- `false` otherwise'';
|
|
|
|
description = ''
|
|
|
|
Whether to enable legacy profile (and garbage collection root)
|
|
|
|
management during activation. When enabled, the Home Manager activation
|
|
|
|
will produce a per-user `home-manager` Nix profile as well as a garbage
|
|
|
|
collection root, just like in the standalone installation of Home
|
|
|
|
Manager. Typically, this is not desired when Home Manager is embedded in
|
|
|
|
the system configuration.
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
2022-06-07 20:45:06 +02:00
|
|
|
config = mkMerge [
|
|
|
|
{
|
|
|
|
home-manager = {
|
|
|
|
extraSpecialArgs.nixosConfig = config;
|
2021-02-21 07:02:25 +01:00
|
|
|
|
2022-06-07 20:45:06 +02:00
|
|
|
sharedModules = [{
|
|
|
|
# The per-user directory inside /etc/profiles is not known by
|
|
|
|
# fontconfig by default.
|
2022-06-14 11:34:44 +02:00
|
|
|
fonts.fontconfig.enable = lib.mkDefault
|
|
|
|
(cfg.useUserPackages && config.fonts.fontconfig.enable);
|
2023-07-04 11:28:25 +02:00
|
|
|
|
|
|
|
# Inherit glibcLocales setting from NixOS.
|
|
|
|
i18n.glibcLocales = lib.mkDefault config.i18n.glibcLocales;
|
2024-01-24 22:48:51 +01:00
|
|
|
|
|
|
|
# Legacy profile management is when the activation script generates GC
|
|
|
|
# root and home-manager profile. The modern way simply relies on the
|
|
|
|
# GC root that the system maintains, which should also protect the
|
|
|
|
# Home Manager activation package outputs.
|
|
|
|
home.activationGenerateGcRoot = cfg.enableLegacyProfileManagement;
|
2022-06-07 20:45:06 +02:00
|
|
|
}];
|
2017-12-19 15:43:40 +01:00
|
|
|
};
|
2022-06-07 20:45:06 +02:00
|
|
|
}
|
|
|
|
(mkIf (cfg.users != { }) {
|
|
|
|
systemd.services = mapAttrs' (_: usercfg:
|
2024-01-24 22:48:51 +01:00
|
|
|
let
|
|
|
|
username = usercfg.home.username;
|
|
|
|
driverVersion =
|
|
|
|
if cfg.enableLegacyProfileManagement then "0" else "1";
|
2022-06-07 20:45:06 +02:00
|
|
|
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" ];
|
|
|
|
before = [ "systemd-user-sessions.service" ];
|
|
|
|
|
|
|
|
environment = serviceEnvironment;
|
|
|
|
|
|
|
|
unitConfig = { RequiresMountsFor = usercfg.home.homeDirectory; };
|
|
|
|
|
|
|
|
stopIfChanged = false;
|
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
User = usercfg.home.username;
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = "yes";
|
2023-06-29 17:29:30 +02:00
|
|
|
TimeoutStartSec = "5m";
|
2022-06-07 20:45:06 +02:00
|
|
|
SyslogIdentifier = "hm-activate-${username}";
|
|
|
|
|
|
|
|
ExecStart = let
|
|
|
|
systemctl =
|
|
|
|
"XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$UID} systemctl";
|
|
|
|
|
|
|
|
sed = "${pkgs.gnused}/bin/sed";
|
|
|
|
|
|
|
|
exportedSystemdVariables = concatStringsSep "|" [
|
|
|
|
"DBUS_SESSION_BUS_ADDRESS"
|
|
|
|
"DISPLAY"
|
|
|
|
"WAYLAND_DISPLAY"
|
|
|
|
"XAUTHORITY"
|
|
|
|
"XDG_RUNTIME_DIR"
|
|
|
|
];
|
|
|
|
|
|
|
|
setupEnv = pkgs.writeScript "hm-setup-env" ''
|
|
|
|
#! ${pkgs.runtimeShell} -el
|
|
|
|
|
|
|
|
# The activation script is run by a login shell to make sure
|
|
|
|
# that the user is given a sane environment.
|
|
|
|
# If the user is logged in, import variables from their current
|
|
|
|
# session environment.
|
|
|
|
eval "$(
|
|
|
|
${systemctl} --user show-environment 2> /dev/null \
|
|
|
|
| ${sed} -En '/^(${exportedSystemdVariables})=/s/^/export /p'
|
|
|
|
)"
|
|
|
|
|
2024-01-24 22:48:51 +01:00
|
|
|
exec "$1/activate" --driver-version ${driverVersion}
|
2022-06-07 20:45:06 +02:00
|
|
|
'';
|
|
|
|
in "${setupEnv} ${usercfg.home.activationPackage}";
|
|
|
|
};
|
|
|
|
}) cfg.users;
|
|
|
|
})
|
|
|
|
];
|
2017-10-14 20:56:02 +02:00
|
|
|
}
|