refactor(ops/clbot): use escapeSystemdPath

This is definitely faster than doing a roundtrip via a build.

Change-Id: I7a02b828462def735fdb241ce729143e90bc5c75
Reviewed-on: https://cl.tvl.fyi/c/depot/+/13236
Tested-by: BuildkiteCI
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: sterni <sternenseemann@systemli.org>
This commit is contained in:
Florian Klink 2025-03-10 14:06:00 +07:00 committed by clbot
parent 40c213b63d
commit fc7f013066

View file

@ -1,9 +1,8 @@
# Module that configures CLBot, our Gerrit->IRC info bridge. # Module that configures CLBot, our Gerrit->IRC info bridge.
{ depot, config, lib, pkgs, ... }: { depot, config, lib, utils, ... }:
let let
inherit (builtins) attrValues concatStringsSep mapAttrs readFile; inherit (builtins) attrValues concatStringsSep mapAttrs;
inherit (pkgs) runCommand;
inherit (lib) inherit (lib)
listToAttrs listToAttrs
@ -11,7 +10,6 @@ let
mkEnableOption mkEnableOption
mkIf mkIf
mkOption mkOption
removeSuffix
types; types;
description = "Bot to forward CL notifications"; description = "Bot to forward CL notifications";
@ -21,13 +19,8 @@ let
concatStringsSep " " concatStringsSep " "
(attrValues (mapAttrs (key: value: "-${key} \"${toString value}\"") flags)); (attrValues (mapAttrs (key: value: "-${key} \"${toString value}\"") flags));
# Escapes a unit name for use in systemd
systemdEscape = name: removeSuffix "\n" (readFile (runCommand "unit-name" { } ''
${pkgs.systemd}/bin/systemd-escape '${name}' >> $out
''));
mkUnit = channel: channelFlags: { mkUnit = channel: channelFlags: {
name = "clbot-${systemdEscape channel}"; name = "clbot-${utils.escapeSystemdPath channel}";
value = { value = {
description = "${description} to ${channel}"; description = "${description} to ${channel}";
wantedBy = [ "multi-user.target" ]; wantedBy = [ "multi-user.target" ];