1
0

provide properties attr to services

properties are similar to outputs, but are different in that they are
fixed values (do not change) and are present even when the service is
down

if the attribute is present and an attrset, this will write the
equivalent recursive directory structure to $out/.properties/
This commit is contained in:
Daniel Barlow 2025-03-12 23:35:56 +00:00
parent 2b0972ed73
commit 4e51977ae0
2 changed files with 20 additions and 1 deletions

View File

@ -1,5 +1,15 @@
source $stdenv/setup
mkdir -p $out/${name}
writepath(){
mkdir -p $(dirname $1)
echo $2 > $1
}
if test -n "$propertiesText"; then
mkdir $out/.properties
( cd $out/.properties; eval "$propertiesText" )
fi
echo $serviceType > $out/${name}/type
mkdir -p $out/${name}/dependencies.d
echo $buildInputs > $out/buildInputs

View File

@ -8,6 +8,8 @@
let
prefix = "/run/services/outputs";
output = service: name: "${prefix}/${service.name}/${name}";
inherit (lib.attrsets) mapAttrsRecursive collect;
inherit (lib.strings) concatStringsSep;
serviceScript = commands: ''
#!/bin/sh
exec 2>&1
@ -38,6 +40,7 @@ let
buildInputs ? [ ],
restart-on-upgrade ? false,
controller ? null,
properties ? {}
}:
stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names
@ -56,7 +59,13 @@ let
timeout-up
timeout-down
restart-on-upgrade
;
;
propertiesText =
let a = mapAttrsRecursive
(path: value: "writepath ${concatStringsSep "/" path} ${builtins.toString value}\n")
properties;
in collect builtins.isString a;
buildInputs =
buildInputs ++ dependencies ++ contents ++ lib.optional (controller != null) controller;
inherit controller dependencies contents;