various: replace systemd.services.<name>.{script,preStart} with ExecStart{,Pre}

This is a partial revert of 39e9380
This commit is contained in:
h7x4
2026-07-31 03:08:12 +09:00
parent 69f6c0a1c5
commit b0cce36acb
24 changed files with 104 additions and 125 deletions
@@ -58,10 +58,11 @@ with lib;
ln -sf ${pkgs.writeText "tinydns-data" config.services.tinydns.data} data
tinydns-data
'';
script = ''
cd /var/lib/tinydns
exec ./run
'';
serviceConfig = {
StateDirectory = "tinydns";
WorkingDirectory = "/var/lib/tinydns";
ExecStart = "/var/lib/tinydns/run";
};
};
};
}
+12 -13
View File
@@ -43,20 +43,19 @@ with lib;
wantedBy = [ "multi-user.target" ];
after = [ "network.target" ];
preStart = ''
mkdir -p /run/toxvpn || true
chown toxvpn /run/toxvpn
'';
path = [ pkgs.toxvpn ];
script = ''
exec toxvpn -i ${config.services.toxvpn.localip} -l /run/toxvpn/control -u toxvpn -p ${toString config.services.toxvpn.port} ${
lib.concatMapStringsSep " " (x: "-a ${x}") config.services.toxvpn.auto_add_peers
}
'';
serviceConfig = {
ExecStart =
let
args = lib.cli.toCommandLineShellGNU { } {
i = config.services.toxvpn.localip;
l = "/run/toxvpn/control";
u = "toxvpn";
p = config.services.toxvpn.port;
a = config.services.toxvpn.auto_add_peers;
};
in
"${lib.getExe pkgs.toxvpn} ${args}";
RuntimeDirectory = "toxvpn";
KillMode = "process";
Restart = "on-success";
Type = "notify";
@@ -17,7 +17,7 @@ in
config = lib.mkIf cfg.enable {
systemd.packages = [ cfg.package ];
systemd.services.twingate = {
preStart = "cp -r --update=none ${cfg.package}/etc/twingate/. /etc/twingate/";
serviceConfig.ExecStartPre = "${lib.getExe' pkgs.coreutils "cp"} -r --update=none ${cfg.package}/etc/twingate/. /etc/twingate/";
wantedBy = [ "multi-user.target" ];
};
+1 -2
View File
@@ -143,8 +143,7 @@ in
description = "xinetd server";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
path = [ pkgs.xinetd ];
script = "exec xinetd -syslog daemon -dontfork -stayalive -f ${configFile}";
serviceConfig.ExecStart = "${lib.getExe pkgs.xinetd} -syslog daemon -dontfork -stayalive -f ${configFile}";
};
};
}
+1 -3
View File
@@ -93,10 +93,8 @@ with lib;
description = "xray Daemon";
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
script = ''
exec "${cfg.package}/bin/xray" -config "$CREDENTIALS_DIRECTORY/config.json"
'';
serviceConfig = {
ExecStart = "${cfg.package}/bin/xray -config \"\${CREDENTIALS_DIRECTORY}\"/config.json";
DynamicUser = true;
LoadCredential = "config.json:${settingsFile}";
CapabilityBoundingSet = "CAP_NET_ADMIN CAP_NET_BIND_SERVICE";
@@ -91,14 +91,14 @@ in
enable = true;
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
serviceConfig.ExecStartPre = [
"${lib.getExe' pkgs.coreutils "mkdir"} -p ${cfg.dataDir}"
"${lib.getExe' pkgs.coreutils "chown"} ${cfg.user} ${cfg.dataDir}"
];
serviceConfig.ExecStart = "${pkgs.zerobin}/bin/zerobin ${cfg.listenAddress} ${toString cfg.listenPort} false ${cfg.user} ${cfg.group} ${zerobin_config}";
serviceConfig.PrivateTmp = "yes";
serviceConfig.User = cfg.user;
serviceConfig.Group = cfg.group;
preStart = ''
mkdir -p ${cfg.dataDir}
chown ${cfg.user} ${cfg.dataDir}
'';
};
};
}
+1 -1
View File
@@ -389,10 +389,10 @@ in
// lib.mapAttrs (_: v: "%d/${v}") nonNullEnvSecretsMap
// instance.environmentVariables;
preStart = "${execCommand} ${configArg} validate-config";
serviceConfig = {
User = instance.user;
Group = instance.group;
ExecStartPre = "${execCommand} ${configArg} validate-config";
ExecStart = "${execCommand} ${configArg}";
Restart = "always";
RestartSec = "5s";
+4 -6
View File
@@ -34,11 +34,6 @@ let
[ spec ]
) (lib.attrValues cfg.specs)
);
preStart = ''
${lib.concatStringsSep " \\\n" ([ "mkdir -p" ] ++ map lib.escapeShellArg specPaths)}
${cfg.package}/bin/certmgr -f ${certmgrYaml} check
'';
in
{
options.services.certmgr = {
@@ -215,11 +210,14 @@ in
wants = [ "network-online.target" ];
after = [ "network-online.target" ];
wantedBy = [ "multi-user.target" ];
inherit preStart;
serviceConfig = {
Restart = "always";
RestartSec = "10s";
ExecStartPre = [
"${lib.getExe' pkgs.coreutils "mkdir"} -p ${lib.escapeShellArgs specPaths}"
"${lib.getExe cfg.package} -f ${certmgrYaml} check"
];
ExecStart = "${cfg.package}/bin/certmgr -f ${certmgrYaml}";
};
};
@@ -55,10 +55,8 @@ in
"network-link-dummy0.service"
"network-addresses-dummy0.service"
];
preStart = ''
/run/current-system/sw/bin/rm -fv /run/hologram.sock
'';
serviceConfig = {
ExecStartPre = "/run/current-system/sw/bin/rm -fv /run/hologram.sock";
ExecStart = "${pkgs.hologram}/bin/hologram-agent -debug -conf ${cfgFile} -port ${cfg.httpPort}";
};
};
+1 -3
View File
@@ -298,10 +298,8 @@ in
Type = "oneshot";
Group = "nginx";
UMask = "026";
ExecStart = "${lib.getExe pkgs.bluemap} -c ${configFolder} -gs -r";
};
script = ''
${lib.getExe pkgs.bluemap} -c ${configFolder} -gs -r
'';
};
systemd.timers."render-bluemap-maps" = lib.mkIf cfg.enableRender {
+14 -7
View File
@@ -380,37 +380,44 @@ in
cloudlog-upload-lotw = {
description = "Upload QSOs to LoTW if certs have been provided";
enable = cfg.upload-lotw.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/lotw/lotw_upload";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/lotw/lotw_upload";
serviceConfig.Type = "oneshot";
};
cloudlog-update-lotw-users = {
description = "Update LOTW Users Database";
enable = cfg.update-lotw-users.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/lotw/load_users";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/lotw/load_users";
serviceConfig.Type = "oneshot";
};
cloudlog-update-dok = {
description = "Update DOK File for autocomplete";
enable = cfg.update-dok.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/update/update_dok";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/update/update_dok";
serviceConfig.Type = "oneshot";
};
cloudlog-update-clublog-scp = {
description = "Update Clublog SCP Database File";
enable = cfg.update-clublog-scp.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/update/update_clublog_scp";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/update/update_clublog_scp";
serviceConfig.Type = "oneshot";
};
cloudlog-update-wwff = {
description = "Update WWFF File for autocomplete";
enable = cfg.update-wwff.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/update/update_wwff";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/update/update_wwff";
serviceConfig.Type = "oneshot";
};
cloudlog-upload-qrz = {
description = "Upload QSOs to QRZ Logbook";
enable = cfg.upload-qrz.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/qrz/upload";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/qrz/upload";
serviceConfig.Type = "oneshot";
};
cloudlog-update-sota = {
description = "Update SOTA File for autocomplete";
enable = cfg.update-sota.enable;
script = "${pkgs.curl}/bin/curl -s ${cfg.baseUrl}/update/update_sota";
serviceConfig.ExecStart = "${lib.getExe pkgs.curl} -s ${cfg.baseUrl}/update/update_sota";
serviceConfig.Type = "oneshot";
};
};
timers = {
+4 -7
View File
@@ -133,19 +133,16 @@ in
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart = ''
${optionalString (cfg.insecure != true && cfg.certFile != null && cfg.keyFile != null) ''
install -m 700 -o '${cfg.user}' -g '${cfg.group}' ${cfg.certFile} ${cfg.dataDir}/cert.pem
install -m 700 -o '${cfg.user}' -g '${cfg.group}' ${cfg.keyFile} ${cfg.dataDir}/key.pem
''}
'';
serviceConfig = mkMerge [
{
Type = "simple";
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.stateDir;
ExecStartPre = lib.mkIf (cfg.insecure != true && cfg.certFile != null && cfg.keyFile != null) [
"${lib.getExe' pkgs.coreutils "install"} -m 700 -o '${cfg.user}' -g '${cfg.group}' ${cfg.certFile} ${cfg.dataDir}/cert.pem"
"${lib.getExe' pkgs.coreutils "install"} -m 700 -o '${cfg.user}' -g '${cfg.group}' ${cfg.keyFile} ${cfg.dataDir}/key.pem"
];
ExecStart = ''
${cfg.package}/bin/galene \
${optionalString (cfg.insecure) "-insecure"} \
@@ -280,13 +280,12 @@ in
bindsTo = [ "glitchtip-worker.service" ];
before = [ "glitchtip-worker.service" ];
preStart = ''
${lib.getExe pkg} migrate
${lib.getExe pkg} createcachetable
${lib.getExe pkg} maintain_partitions
'';
serviceConfig = commonServiceConfig // {
ExecStartPre = [
"${lib.getExe pkg} migrate"
"${lib.getExe pkg} createcachetable"
"${lib.getExe pkg} maintain_partitions"
];
ExecStart = ''
${lib.getExe python.pkgs.granian} \
--interface ${if cfg.settings.GLITCHTIP_ENABLE_MCP then "asgi" else "asginl"} \
@@ -237,14 +237,13 @@ in
wantedBy = [ "healthchecks.target" ];
after = [ "healthchecks-migration.service" ];
preStart = ''
${pkg}/opt/healthchecks/manage.py collectstatic --no-input
${pkg}/opt/healthchecks/manage.py remove_stale_contenttypes --no-input
''
+ lib.optionalString (cfg.settings.DEBUG != "True") "${pkg}/opt/healthchecks/manage.py compress";
serviceConfig = commonConfig // {
Restart = "always";
ExecStartPre = [
"${pkg}/opt/healthchecks/manage.py collectstatic --no-input"
"${pkg}/opt/healthchecks/manage.py remove_stale_contenttypes --no-input"
]
++ lib.optionals (cfg.settings.DEBUG != "True") [ "${pkg}/opt/healthchecks/manage.py compress" ];
ExecStart = ''
${pkgs.python3Packages.gunicorn}/bin/gunicorn hc.wsgi \
--bind ${cfg.listenAddress}:${toString cfg.port} \
+17 -17
View File
@@ -310,19 +310,6 @@ in
in
{
mediagoblin-celeryd = lib.recursiveUpdate serviceDefaults {
# we cannot change DEFAULT.data_dir inside mediagoblin.ini because of an annoying bug
# https://todo.sr.ht/~mediagoblin/mediagoblin/57
preStart = ''
cp --remove-destination ${
pkgs.writeText "mediagoblin.ini" (
lib.generators.toINI { } (lib.filterAttrsRecursive (n: v: n != "plugins") cfg.settings)
+ "\n"
+ lib.generators.toINI { mkKeyValue = mkSubSectionKeyValue 2; } {
inherit (cfg.settings.mediagoblin) plugins;
}
)
} /var/lib/mediagoblin/mediagoblin.ini
'';
serviceConfig = {
Environment = [
"CELERY_CONFIG_MODULE=mediagoblin.init.celery.from_celery"
@@ -331,6 +318,19 @@ in
"MEDIAGOBLIN_CONFIG=/var/lib/mediagoblin/mediagoblin.ini"
"PASTE_CONFIG=${pasteConfig}"
];
# we cannot change DEFAULT.data_dir inside mediagoblin.ini because of an annoying bug
# https://todo.sr.ht/~mediagoblin/mediagoblin/57
ExecStartPre = ''
${lib.getExe' pkgs.coreutils "cp"} --remove-destination ${
pkgs.writeText "mediagoblin.ini" (
lib.generators.toINI { } (lib.filterAttrsRecursive (n: v: n != "plugins") cfg.settings)
+ "\n"
+ lib.generators.toINI { mkKeyValue = mkSubSectionKeyValue 2; } {
inherit (cfg.settings.mediagoblin) plugins;
}
)
} /var/lib/mediagoblin/mediagoblin.ini
'';
ExecStart = "${lib.getExe' finalPackage "celery"} worker --loglevel=INFO";
};
unitConfig.Description = "MediaGoblin Celery";
@@ -345,16 +345,16 @@ in
"mediagoblin-celeryd.service"
"postgresql.target"
];
preStart = ''
cp --remove-destination ${pasteConfig} /var/lib/mediagoblin/paste.ini
${lib.getExe' finalPackage "gmg"} dbupdate
'';
serviceConfig = {
Environment = [
"CELERY_ALWAYS_EAGER=false"
"GI_TYPELIB_PATH=${GI_TYPELIB_PATH}"
"GST_PLUGIN_PATH=${GST_PLUGIN_PATH}"
];
ExecStartPre = [
"${lib.getExe' pkgs.coreutils "cp"} --remove-destination ${pasteConfig} /var/lib/mediagoblin/paste.ini"
"${lib.getExe' finalPackage "gmg"} dbupdate"
];
ExecStart = "${lib.getExe' finalPackage "paster"} serve /var/lib/mediagoblin/paste.ini";
};
unitConfig.Description = "Mediagoblin";
+3 -9
View File
@@ -17,14 +17,6 @@ let
cfg = config.services.miniflux;
boolToInt = b: if b then 1 else 0;
pgbin = "${config.services.postgresql.package}/bin";
# The hstore extension is no longer needed as of v2.2.14
# and would prevent Miniflux from starting.
preStart = pkgs.writeScript "miniflux-pre-start" ''
#!${pkgs.runtimeShell}
${pgbin}/psql "miniflux" -c "DROP EXTENSION IF EXISTS hstore"
'';
in
{
@@ -142,7 +134,9 @@ in
serviceConfig = {
Type = "oneshot";
User = config.services.postgresql.superUser;
ExecStart = preStart;
# The hstore extension is no longer needed as of v2.2.14
# and would prevent Miniflux from starting.
ExecStart = ''${config.services.postgresql.package}/bin/psql "miniflux" -c "DROP EXTENSION IF EXISTS hstore"'';
};
};
+15 -15
View File
@@ -326,22 +326,22 @@ in
environment = {
MISSKEY_CONFIG_YML = "/run/misskey/default.yml";
};
preStart = ''
install -m 700 ${settingsFormat.generate "misskey-config.yml" cfg.settings} /run/misskey/default.yml
install -m 700 ${
(pkgs.formats.json { }).generate "misskey-config.json" cfg.settings
} /run/misskey/default.json
''
+ (lib.optionalString (cfg.database.passwordFile != null) ''
${pkgs.replace-secret}/bin/replace-secret '@DATABASE_PASSWORD@' "${cfg.database.passwordFile}" /run/misskey/default.yml
'')
+ (lib.optionalString (cfg.redis.passwordFile != null) ''
${pkgs.replace-secret}/bin/replace-secret '@REDIS_PASSWORD@' "${cfg.redis.passwordFile}" /run/misskey/default.yml
'')
+ (lib.optionalString (cfg.meilisearch.keyFile != null) ''
${pkgs.replace-secret}/bin/replace-secret '@MEILISEARCH_KEY@' "${cfg.meilisearch.keyFile}" /run/misskey/default.yml
'');
serviceConfig = {
ExecStartPre = [
"${lib.getExe' pkgs.coreutils "install"} -m 700 ${settingsFormat.generate "misskey-config.yml" cfg.settings} /run/misskey/default.yml"
"${lib.getExe' pkgs.coreutils "install"} -m 700 ${
(pkgs.formats.json { }).generate "misskey-config.json" cfg.settings
} /run/misskey/default.json"
]
++ (lib.optionals (cfg.database.passwordFile != null) [
"${lib.getExe pkgs.replace-secret} '@DATABASE_PASSWORD@' '${cfg.database.passwordFile}' /run/misskey/default.yml"
])
++ (lib.optionals (cfg.redis.passwordFile != null) [
"${lib.getExe pkgs.replace-secret} '@REDIS_PASSWORD@' '${cfg.redis.passwordFile}' /run/misskey/default.yml"
])
++ (lib.optionals (cfg.meilisearch.keyFile != null) [
"${lib.getExe pkgs.replace-secret} '@MEILISEARCH_KEY@' '${cfg.meilisearch.keyFile}' /run/misskey/default.yml"
]);
ExecStart = "${cfg.package}/bin/misskey migrateandstart";
RuntimeDirectory = "misskey";
RuntimeDirectoryMode = "700";
+1 -2
View File
@@ -142,9 +142,8 @@ in
fi
'';
script = "${cfg.package}/bin/nexus run";
serviceConfig = {
ExecStart = "${cfg.package}/bin/nexus run";
User = cfg.user;
Group = cfg.group;
PrivateTmp = true;
+1 -4
View File
@@ -257,6 +257,7 @@ in
];
wantedBy = [ "multi-user.target" ];
serviceConfig = {
ExecStart = "${lib.getExe cfg.phpPackage} ${lib.getExe' cfg.package "console"} doctrine:migrations:migrate --no-interaction";
Type = "oneshot";
RemainAfterExit = true;
User = "part-db";
@@ -264,10 +265,6 @@ in
restartTriggers = [
cfg.package
];
script = ''
set -euo pipefail
${lib.getExe cfg.phpPackage} ${lib.getExe' cfg.package "console"} doctrine:migrations:migrate --no-interaction
'';
};
phpfpm-part-db = {
@@ -307,11 +307,8 @@ in
]
++ lib.optionals (cfg.environmentFile != null) [ "peering-manager-config.service" ];
preStart = ''
${pkg}/bin/peering-manager remove_stale_contenttypes --no-input
'';
serviceConfig = {
ExecStartPre = "${pkg}/bin/peering-manager remove_stale_contenttypes --no-input";
ExecStart = ''
${pkg.python.pkgs.gunicorn}/bin/gunicorn peering_manager.wsgi \
--bind ${cfg.listenAddress}:${toString cfg.port} \
@@ -95,7 +95,6 @@ in
after = [ "network.target" ];
wantedBy = [ "multi-user.target" ];
preStart = lib.mkIf (!lib.hasPrefix "/var/lib/" cfg.spaceDir) "mkdir -p '${cfg.spaceDir}'";
serviceConfig = {
Type = "simple";
User = "${cfg.user}";
@@ -104,6 +103,9 @@ in
StateDirectory = lib.mkIf (lib.hasPrefix "/var/lib/" cfg.spaceDir) (
lib.last (lib.splitString "/" cfg.spaceDir)
);
ExecStartPre = lib.mkIf (
!lib.hasPrefix "/var/lib/" cfg.spaceDir
) "${lib.getExe' pkgs.coreutils "mkdir"} -p '${cfg.spaceDir}'";
ExecStart =
"${lib.getExe cfg.package} --port ${toString cfg.listenPort} --hostname '${cfg.listenAddress}' '${cfg.spaceDir}' "
+ lib.concatStringsSep " " cfg.extraArgs;
+2 -4
View File
@@ -144,13 +144,11 @@ in
++ optional (cfg.database.dialect == "postgres") "postgresql.target";
wantedBy = [ "multi-user.target" ];
script = ''
exec ${getExe cfg.package} -config ${settingsFile}
'';
serviceConfig = {
EnvironmentFile = cfg.environmentFiles;
ExecStart = "${getExe cfg.package} -config ${settingsFile}";
User = config.users.users.wakapi.name;
Group = config.users.users.wakapi.group;
@@ -443,6 +443,7 @@ in
++ map (certName: "acme-${certName}.service") acmeCertNames.all;
serviceConfig = {
ExecStartPre = "${h2oExe} --mode 'test'";
ExecStart = "${h2oExe} --mode 'master'";
ExecReload = [
"${h2oExe} --mode 'test'"
@@ -483,8 +484,6 @@ in
AmbientCapabilities = [ "CAP_NET_BIND_SERVICE" ];
CapabilitiesBoundingSet = [ "CAP_NET_BIND_SERVICE" ];
};
preStart = "${h2oExe} --mode 'test'";
};
# This service waits for all certificates to be available before reloading
@@ -93,7 +93,7 @@ in
config = mkIf config.services.jboss.enable {
systemd.services.jboss = {
description = "JBoss server";
script = "${jbossService}/bin/control start";
serviceConfig.ExecStart = "${jbossService}/bin/control start";
wantedBy = [ "multi-user.target" ];
};
};