diff --git a/modules/misc/news/2026/01/2026-01-11_07-00-11.nix b/modules/misc/news/2026/01/2026-01-11_07-00-11.nix new file mode 100644 index 00000000..efbcf036 --- /dev/null +++ b/modules/misc/news/2026/01/2026-01-11_07-00-11.nix @@ -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`. + ''; +} diff --git a/modules/systemd.nix b/modules/systemd.nix index 127cb73f..43ac60a4 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -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 diff --git a/tests/modules/systemd/default.nix b/tests/modules/systemd/default.nix index ee8a9ae6..9221c347 100644 --- a/tests/modules/systemd/default.nix +++ b/tests/modules/systemd/default.nix @@ -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; diff --git a/tests/modules/systemd/packages.nix b/tests/modules/systemd/packages.nix new file mode 100644 index 00000000..41875b99 --- /dev/null +++ b/tests/modules/systemd/packages.nix @@ -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 <