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.
This commit is contained in:
worldofpeace 2020-01-07 21:41:28 -05:00
parent ffe6b959a1
commit 1c2e27e4d5

View File

@ -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