summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2019-08-19 16:05:44 +0200
committerRobert Helgesson <robert@rycee.net>2020-09-12 18:29:46 +0200
commitfbc5093649b17b65a5db6caa252f7d3aa99f94d0 (patch)
tree0122881b77666528b463bf25f585f7e073aaaec7
parent37d29394ecba3ccff2083119ec49fc3eaf36db8c (diff)
downloadnixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.tar
nixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.tar.gz
nixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.tar.bz2
nixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.tar.lz
nixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.tar.xz
nixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.tar.zst
nixpkgs-fbc5093649b17b65a5db6caa252f7d3aa99f94d0.zip
hooks: add moveSystemdUserUnitsHook
This hook moves systemd user service file from `lib/systemd/user` to
`share/systemd/user`. This is to allow systemd to find the user
services when installed into a user profile. The `lib/systemd/user`
path does not work since `lib` is not in `XDG_DATA_DIRS`.
-rw-r--r--doc/stdenv/stdenv.xml13
-rw-r--r--nixos/modules/config/system-path.nix1
-rwxr-xr-xpkgs/build-support/setup-hooks/move-systemd-user-units.sh25
-rw-r--r--pkgs/stdenv/generic/default.nix5
4 files changed, 43 insertions, 1 deletions
diff --git a/doc/stdenv/stdenv.xml b/doc/stdenv/stdenv.xml
index f97c2a145af..e85e2ccb0ec 100644
--- a/doc/stdenv/stdenv.xml
+++ b/doc/stdenv/stdenv.xml
@@ -1836,6 +1836,19 @@ addEnvHooks "$hostOffset" myBashFunction
     </varlistentry>
     <varlistentry>
      <term>
+      <literal>move-systemd-user-units.sh</literal>
+     </term>
+     <listitem>
+      <para>
+       This setup hook moves any systemd user units installed in the lib
+       subdirectory into share. In addition, a link is provided from share to
+       lib for compatibility. This is needed for systemd to find user services
+       when installed into the user profile.
+      </para>
+     </listitem>
+    </varlistentry>
+    <varlistentry>
+     <term>
       <literal>set-source-date-epoch-to-latest.sh</literal>
      </term>
      <listitem>
diff --git a/nixos/modules/config/system-path.nix b/nixos/modules/config/system-path.nix
index 67305e8499c..c46937f8008 100644
--- a/nixos/modules/config/system-path.nix
+++ b/nixos/modules/config/system-path.nix
@@ -142,6 +142,7 @@ in
         "/share/kservices5"
         "/share/kservicetypes5"
         "/share/kxmlgui5"
+        "/share/systemd"
       ];
 
     system.path = pkgs.buildEnv {
diff --git a/pkgs/build-support/setup-hooks/move-systemd-user-units.sh b/pkgs/build-support/setup-hooks/move-systemd-user-units.sh
new file mode 100755
index 00000000000..5963d87c751
--- /dev/null
+++ b/pkgs/build-support/setup-hooks/move-systemd-user-units.sh
@@ -0,0 +1,25 @@
+#!/usr/bin/env bash
+
+# This setup hook, for each output, moves everything in
+# $output/lib/systemd/user to $output/share/systemd/user, and replaces
+# $output/lib/systemd/user with a symlink to
+# $output/share/systemd/user.
+
+fixupOutputHooks+=(_moveSystemdUserUnits)
+
+_moveSystemdUserUnits() {
+    if [ "${dontMoveSystemdUserUnits:-0}" = 1 ]; then return; fi
+    if [ ! -e "${prefix:?}/lib/systemd/user" ]; then return; fi
+    local source="$prefix/lib/systemd/user"
+    local target="$prefix/share/systemd/user"
+    echo "moving $source/* to $target"
+    mkdir -p "$target"
+    (
+      shopt -s dotglob
+      for i in "$source"/*; do
+          mv "$i" "$target"
+      done
+    )
+    rmdir "$source"
+    ln -s "$target" "$source"
+}
diff --git a/pkgs/stdenv/generic/default.nix b/pkgs/stdenv/generic/default.nix
index b5798978690..eeddb584a3d 100644
--- a/pkgs/stdenv/generic/default.nix
+++ b/pkgs/stdenv/generic/default.nix
@@ -61,7 +61,10 @@ let
     ]
       # FIXME this on Darwin; see
       # https://github.com/NixOS/nixpkgs/commit/94d164dd7#commitcomment-22030369
-    ++ lib.optional hostPlatform.isLinux ../../build-support/setup-hooks/audit-tmpdir.sh
+    ++ lib.optionals hostPlatform.isLinux [
+      ../../build-support/setup-hooks/audit-tmpdir.sh
+      ../../build-support/setup-hooks/move-systemd-user-units.sh
+    ]
     ++ [
       ../../build-support/setup-hooks/multiple-outputs.sh
       ../../build-support/setup-hooks/move-sbin.sh