about summary refs log tree commit diff
path: root/nixos/modules/system/boot
diff options
context:
space:
mode:
authorworldofpeace <worldofpeace@protonmail.ch>2020-01-07 21:41:28 -0500
committerworldofpeace <worldofpeace@protonmail.ch>2020-01-07 21:42:14 -0500
commit1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e (patch)
tree806826db5ae881d7565aaa6169b7e93d7884472e /nixos/modules/system/boot
parentffe6b959a1c0288c38cbd4850454deeb6f4a18f1 (diff)
downloadnixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.tar
nixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.tar.gz
nixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.tar.bz2
nixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.tar.lz
nixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.tar.xz
nixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.tar.zst
nixlib-1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e.zip
nixos/systemd-lib: don't fail on systemd.packages duplicates
In some cases like we've noticed in https://github.com/NixOS/nixpkgs/issues/76169,
having duplicate packages in systemd.packages like
```
systemd.packages = [ gnome-shell gnome-shell gnome-session ];
```
breaks.

Here we use an associative array to ensure no
duplicate paths when we symlink all the units listed
in systemd.packages.
Diffstat (limited to 'nixos/modules/system/boot')
-rw-r--r--nixos/modules/system/boot/systemd-lib.nix8
1 files changed, 7 insertions, 1 deletions
diff --git a/nixos/modules/system/boot/systemd-lib.nix b/nixos/modules/system/boot/systemd-lib.nix
index 28ad4f121bbe..fd1a5b9f62c5 100644
--- a/nixos/modules/system/boot/systemd-lib.nix
+++ b/nixos/modules/system/boot/systemd-lib.nix
@@ -147,7 +147,13 @@ in rec {
       done
 
       # Symlink all units provided listed in systemd.packages.
-      for i in ${toString cfg.packages}; do
+      packages="${toString cfg.packages}"
+
+      # Filter duplicate directories
+      declare -A unique_packages
+      for k in $packages ; do unique_packages[$k]=1 ; done
+
+      for i in ''${!unique_packages[@]}; do
         for fn in $i/etc/systemd/${type}/* $i/lib/systemd/${type}/*; do
           if ! [[ "$fn" =~ .wants$ ]]; then
             if [[ -d "$fn" ]]; then