From 1c2e27e4d55d14f8a6d769eb9a27c0bc3c4f883e Mon Sep 17 00:00:00 2001 From: worldofpeace Date: Tue, 7 Jan 2020 21:41:28 -0500 Subject: [PATCH] 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. --- nixos/modules/system/boot/systemd-lib.nix | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) 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