aboutsummaryrefslogtreecommitdiff
path: root/modules/systemd.nix
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2020-07-07 00:35:28 +0200
committerRobert Helgesson <robert@rycee.net>2020-08-04 01:01:10 +0200
commit9c0fe3957bb91128d5d3599e289fe9344a293ece (patch)
treeb326bf3286587cf782d86cf47a3c376f8d6db244 /modules/systemd.nix
parent152769aed96d4d6f005ab40daf03ec4f5102c763 (diff)
systemd: use sd-switch
This makes the systemd module use the sd-switch application to perform the unit switch during a generation activation. Since the closure of sd-switch is relatively lightweight we unconditionally pull it in as a dependency. We simultaneously remove the `systemd.user.startServices` option and perform the switch action automatically. PR #1388
Diffstat (limited to '')
-rw-r--r--modules/systemd.nix33
1 files changed, 20 insertions, 13 deletions
diff --git a/modules/systemd.nix b/modules/systemd.nix
index dcb1a29570d..5acfabc7469 100644
--- a/modules/systemd.nix
+++ b/modules/systemd.nix
@@ -54,8 +54,6 @@ let
buildServices = style: serviceCfgs:
concatLists (mapAttrsToList (buildService style) serviceCfgs);
- servicesStartTimeoutMs = builtins.toString cfg.servicesStartTimeoutMs;
-
unitType = unitKind: with types;
let
primitive = either bool (either int str);
@@ -152,9 +150,11 @@ in
example = unitExample "Path";
};
+ # Keep for a while for backwards compatibility.
startServices = mkOption {
default = false;
type = types.bool;
+ visible = false;
description = ''
Start all services that are wanted by active targets.
Additionally, stop obsolete services from the previous
@@ -164,10 +164,10 @@ in
servicesStartTimeoutMs = mkOption {
default = 0;
- type = types.int;
+ type = types.ints.unsigned;
description = ''
- How long to wait for started services to fail until their
- start is considered successful.
+ How long to wait for started services to fail until their start is
+ considered successful. The value 0 indicates no timeout.
'';
};
@@ -203,6 +203,10 @@ in
"Must use Linux for modules that require systemd: " + names;
}
];
+
+ warnings = mkIf cfg.startServices [
+ "The option 'systemd.user.startServices' is obsolete and can be removed."
+ ];
}
# If we run under a Linux system we assume that systemd is
@@ -230,13 +234,17 @@ in
# set it ourselves in that case.
home.activation.reloadSystemD = hm.dag.entryAfter ["linkGeneration"] (
let
- autoReloadCmd = ''
- ${pkgs.ruby}/bin/ruby ${./systemd-activate.rb} \
- "''${oldGenPath=}" "$newGenPath" "${servicesStartTimeoutMs}"
- '';
+ timeoutArg =
+ if cfg.servicesStartTimeoutMs != 0 then
+ "--timeout " + toString cfg.servicesStartTimeoutMs
+ else
+ "";
- legacyReloadCmd = ''
- bash ${./systemd-activate.sh} "''${oldGenPath=}" "$newGenPath"
+ sdSwitchCmd = ''
+ ${pkgs.sd-switch}/bin/sd-switch \
+ ''${DRY_RUN:+--dry-run} $VERBOSE_ARG ${timeoutArg} \
+ ''${oldGenPath:+--old-units $oldGenPath/home-files/.config/systemd/user} \
+ --new-units $newGenPath/home-files/.config/systemd/user
'';
ensureRuntimeDir = "XDG_RUNTIME_DIR=\${XDG_RUNTIME_DIR:-/run/user/$(id -u)}";
@@ -254,8 +262,7 @@ in
fi
${ensureRuntimeDir} \
- PATH=${dirOf cfg.systemctlPath}:$PATH \
- ${if cfg.startServices then autoReloadCmd else legacyReloadCmd}
+ ${sdSwitchCmd}
else
echo "User systemd daemon not running. Skipping reload."
fi