systemd: add packages option (#8540)
* systemd: add `packages` option The `systemd.user.packages` option is the Home Manager equivalent of NixOS’s `systemd.packages` option and provides a way to specify packages providing systemd user units. This option is similar to `dbus.packages`. * systemd: only create the parent directory if there are packages to symlink
This commit is contained in:
parent
0b24f3a487
commit
27613c7299
4 changed files with 59 additions and 0 deletions
13
modules/misc/news/2026/01/2026-01-11_07-00-11.nix
Normal file
13
modules/misc/news/2026/01/2026-01-11_07-00-11.nix
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
{ pkgs, ... }:
|
||||
{
|
||||
time = "2026-01-11T04:00:11+00:00";
|
||||
condition = pkgs.stdenv.hostPlatform.isLinux;
|
||||
message = ''
|
||||
A new option is available: `systemd.user.packages`.
|
||||
|
||||
This option is the Home Manager equivalent of NixOS’s `systemd.packages`
|
||||
option and provides a way to specify packages providing systemd user units.
|
||||
|
||||
This option is similar to `dbus.packages`.
|
||||
'';
|
||||
}
|
||||
|
|
@ -249,6 +249,20 @@ in
|
|||
'';
|
||||
};
|
||||
|
||||
packages = mkOption {
|
||||
type = with types; listOf package;
|
||||
default = [ ];
|
||||
description = ''
|
||||
Packages providing systemd user units.
|
||||
|
||||
This is the Home Manager equivalent of NixOS’s `systemd.packages`
|
||||
option.
|
||||
|
||||
Files in {file}`«pkg»/share/systemd/user` will be included in the
|
||||
user’s {file}`$XDG_DATA_HOME/systemd/user` directory.
|
||||
'';
|
||||
};
|
||||
|
||||
services = mkOption {
|
||||
default = { };
|
||||
type = serviceType;
|
||||
|
|
@ -450,6 +464,17 @@ in
|
|||
settings
|
||||
];
|
||||
|
||||
xdg.dataFile = lib.mkIf (cfg.packages != [ ]) {
|
||||
"systemd/user" = {
|
||||
recursive = true;
|
||||
source = pkgs.symlinkJoin {
|
||||
name = "user-systemd-units";
|
||||
paths = cfg.packages;
|
||||
stripPrefix = "/share/systemd/user";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
# Run systemd service reload if user is logged in. If we're
|
||||
# running this from the NixOS module then XDG_RUNTIME_DIR is not
|
||||
# set and systemd commands will fail. We'll therefore have to
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
{
|
||||
systemd-services = ./services.nix;
|
||||
systemd-packages = ./packages.nix;
|
||||
systemd-services-disabled-for-root = ./services-disabled-for-root.nix;
|
||||
systemd-session-variables = ./session-variables.nix;
|
||||
systemd-user-config = ./user-config.nix;
|
||||
|
|
|
|||
20
tests/modules/systemd/packages.nix
Normal file
20
tests/modules/systemd/packages.nix
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
{ pkgs, config, ... }:
|
||||
let
|
||||
package = config.lib.test.mkStubPackage {
|
||||
buildScript = ''
|
||||
mkdir -p $out/share/systemd/user
|
||||
> $out/share/systemd/user/dummy.service cat <<EOF
|
||||
[Service]
|
||||
ExecStart=$out/bin/nonexistent
|
||||
EOF
|
||||
'';
|
||||
};
|
||||
in
|
||||
{
|
||||
systemd.user.packages = [ package ];
|
||||
nmt.script = ''
|
||||
serviceFile=home-files/.local/share/systemd/user/dummy.service
|
||||
assertFileExists "$serviceFile"
|
||||
assertFileContent "$serviceFile" ${package}/share/systemd/user/dummy.service
|
||||
'';
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue