From d97e8f8861a7ad3cb2f72adf5b2cd14ab302c593 Mon Sep 17 00:00:00 2001 From: Ramses Date: Thu, 11 May 2023 15:50:37 +0200 Subject: [PATCH] systemd: accept derivations as values for systemd options (#3974) --- modules/systemd.nix | 2 +- tests/modules/systemd/services.nix | 14 +++++++++----- 2 files changed, 10 insertions(+), 6 deletions(-) diff --git a/modules/systemd.nix b/modules/systemd.nix index 456b22fd1..68929ed1e 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -51,7 +51,7 @@ let unitType = unitKind: with types; - let primitive = either bool (either int str); + let primitive = oneOf [ bool int str path ]; in attrsOf (attrsOf (attrsOf (either primitive (listOf primitive)))) // { description = "systemd ${unitKind} unit configuration"; }; diff --git a/tests/modules/systemd/services.nix b/tests/modules/systemd/services.nix index fbef7b9c2..ce030f7c7 100644 --- a/tests/modules/systemd/services.nix +++ b/tests/modules/systemd/services.nix @@ -1,14 +1,17 @@ -{ config, lib, pkgs, ... }: +{ pkgs, ... }: -with lib; - -{ +let + drvScript = pkgs.writeShellScript "drv-script.sh" '' + echo "Just a test" + ''; +in { config = { systemd.user.services."test-service@" = { Unit = { Description = "A basic test service"; }; Service = { Environment = [ "VAR1=1" "VAR2=2" ]; + ExecStartPre = drvScript; ExecStart = ''/some/exec/start/command --with-arguments "%i"''; }; }; @@ -18,11 +21,12 @@ with lib; assertFileExists $serviceFile assertFileContent $serviceFile \ ${ - builtins.toFile "services-expected.conf" '' + pkgs.writeText "services-expected.conf" '' [Service] Environment=VAR1=1 Environment=VAR2=2 ExecStart=/some/exec/start/command --with-arguments "%i" + ExecStartPre=${drvScript} [Unit] Description=A basic test service