Skip to content

Commit

Permalink
Provide an implementation for systemd.packages option
Browse files Browse the repository at this point in the history
  • Loading branch information
aanderse committed Nov 24, 2023
1 parent 0333301 commit 655434d
Showing 1 changed file with 21 additions and 2 deletions.
23 changes: 21 additions & 2 deletions nix/modules/systemd.nix
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,27 @@ let
} ''
mkdir -p $out
# Symlink all units provided listed in systemd.packages.
packages="${toString 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
targetDir="$out/$(basename "$fn")"
mkdir -p "$targetDir"
${pkgs.buildPackages.xorg.lndir}/bin/lndir "$fn" "$targetDir"
else
ln -s $fn $out/
fi
fi
done
done
for i in ${toString (lib.mapAttrsToList (n: v: v.unit) units)}; do
fn=$(basename $i/*)
if [ -e $out/$fn ]; then
Expand Down Expand Up @@ -265,13 +286,11 @@ in

environment.etc = {
"systemd/system".source = generateUnits {
allowCollisions = false;
type = "system";
units = lib.filterAttrs (_: unit: unit.enable) cfg.units;
};

"systemd/user".source = generateUnits {
allowCollisions = false;
type = "user";
units = lib.filterAttrs (_: unit: unit.enable) cfg.user.units;
};
Expand Down

0 comments on commit 655434d

Please sign in to comment.