From 71204983bd2194d7bba3753799c2bcaf0c7a97d1 Mon Sep 17 00:00:00 2001 From: Alois Wohlschlager Date: Sat, 12 Oct 2024 10:14:25 +0200 Subject: [PATCH] nixos/bees: use the upstream service file Instead of duplicating the options from the upstream service file and letting them get out of sync, use the file directly and only configure the needed overrides. In particular, the upstream improvements include the mounts not being globally visible any more, so they can't be used for bypassing nosuid and the like, and the custom cleanup script that performed the unmount becomes unnecessary. --- nixos/modules/services/misc/bees.nix | 51 +++++++++++----------------- 1 file changed, 19 insertions(+), 32 deletions(-) diff --git a/nixos/modules/services/misc/bees.nix b/nixos/modules/services/misc/bees.nix index b16552a8eecd..2815bb035cb7 100644 --- a/nixos/modules/services/misc/bees.nix +++ b/nixos/modules/services/misc/bees.nix @@ -97,42 +97,29 @@ in ''; }; }; - config = { + config = lib.mkIf (cfg.filesystems != { }) { + systemd.packages = [ pkgs.bees ]; systemd.services = lib.mapAttrs' ( name: fs: lib.nameValuePair "beesd@${name}" { - description = "Block-level BTRFS deduplication for %i"; - after = [ "sysinit.target" ]; - - serviceConfig = - let - configOpts = [ - fs.spec - "verbosity=${toString fs.verbosity}" - "idxSizeMB=${toString fs.hashTableSizeMB}" - "workDir=${fs.workDir}" + overrideStrategy = "asDropin"; + serviceConfig = { + ExecStart = + let + configOpts = [ + fs.spec + "verbosity=${toString fs.verbosity}" + "idxSizeMB=${toString fs.hashTableSizeMB}" + "workDir=${fs.workDir}" + ]; + configOptsStr = lib.escapeShellArgs configOpts; + in + [ + "" + "${pkgs.bees}/bin/bees-service-wrapper run ${configOptsStr} -- --no-timestamps ${lib.escapeShellArgs fs.extraOptions}" ]; - configOptsStr = lib.escapeShellArgs configOpts; - in - { - # Values from https://github.com/Zygo/bees/blob/v0.6.5/scripts/beesd@.service.in - ExecStart = "${pkgs.bees}/bin/bees-service-wrapper run ${configOptsStr} -- --no-timestamps ${lib.escapeShellArgs fs.extraOptions}"; - ExecStopPost = "${pkgs.bees}/bin/bees-service-wrapper cleanup ${configOptsStr}"; - CPUAccounting = true; - CPUSchedulingPolicy = "batch"; - CPUWeight = 12; - IOSchedulingClass = "idle"; - IOSchedulingPriority = 7; - IOWeight = 10; - KillMode = "control-group"; - KillSignal = "SIGTERM"; - MemoryAccounting = true; - Nice = 19; - Restart = "on-abnormal"; - StartupCPUWeight = 25; - StartupIOWeight = 25; - SyslogIdentifier = "beesd"; # would otherwise be "bees-service-wrapper" - }; + SyslogIdentifier = "beesd"; # would otherwise be "bees-service-wrapper" + }; unitConfig.RequiresMountsFor = lib.mkIf (lib.hasPrefix "/" fs.spec) fs.spec; wantedBy = [ "multi-user.target" ]; }