liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 4e51977ae014e26e345304eb405e35a99dbf64f6
parent 2b0972ed73222a104dbe45a330e29a398879e567
Author: Daniel Barlow <dan@telent.net>
Date:   Wed, 12 Mar 2025 23:35:56 +0000

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/

Diffstat:
Mpkgs/liminix-tools/services/builder.sh | 10++++++++++
Mpkgs/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 @@ -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 @@ -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;