From 4e51977ae014e26e345304eb405e35a99dbf64f6 Mon Sep 17 00:00:00 2001 From: Daniel Barlow Date: Wed, 12 Mar 2025 23:35:56 +0000 Subject: [PATCH] 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/ --- pkgs/liminix-tools/services/builder.sh | 10 ++++++++++ pkgs/liminix-tools/services/default.nix | 11 ++++++++++- 2 files changed, 20 insertions(+), 1 deletion(-) diff --git a/pkgs/liminix-tools/services/builder.sh b/pkgs/liminix-tools/services/builder.sh index 47587c6..7a00b37 100644 --- a/pkgs/liminix-tools/services/builder.sh +++ b/pkgs/liminix-tools/services/builder.sh @@ -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 diff --git a/pkgs/liminix-tools/services/default.nix b/pkgs/liminix-tools/services/default.nix index 79b4a8f..6e11a32 100644 --- a/pkgs/liminix-tools/services/default.nix +++ b/pkgs/liminix-tools/services/default.nix @@ -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;