improve syntax for accessing service outputs
This commit is contained in:
@@ -10,10 +10,11 @@ test -n "$contents" && for d in $contents; do
|
||||
mkdir -p $out/${name}/contents.d
|
||||
touch $out/${name}/contents.d/$d
|
||||
done
|
||||
test -n "$run" && (echo -e "#!$shell\n$run" > $out/${name}/run)
|
||||
test -n "$run" && (echo -e "$run" > $out/${name}/run)
|
||||
test -n "${notificationFd}" && (echo ${notificationFd} > $out/${name}/notification-fd)
|
||||
test -n "$up" && (echo -e "#!$shell\n$up" > $out/${name}/up)
|
||||
test -n "$down" && (echo -e "#!$shell\n$down" > $out/${name}/down)
|
||||
test -n "$up" && (echo -e "$up" > $out/${name}/up)
|
||||
test -n "$down" && (echo -e "$down" > $out/${name}/down)
|
||||
( cd $out && ln -s /run/service-state/${name} ./.outputs )
|
||||
for i in $out/${name}/{down,up,run} ; do test -f $i && chmod +x $i; done
|
||||
true
|
||||
# (echo $out/${name} && cd $out/${name} && find . -ls)
|
||||
|
@@ -4,12 +4,16 @@
|
||||
, lib
|
||||
, busybox
|
||||
, callPackage
|
||||
, writeAshScript
|
||||
, writeScript
|
||||
}:
|
||||
let
|
||||
inherit (builtins) concatStringsSep;
|
||||
output = service: name: "/run/service-state/${service.name}/${name}";
|
||||
|
||||
serviceScript = commands : ''
|
||||
#!${busybox}/bin/sh
|
||||
output() { cat $1/.outputs/$2; }
|
||||
${commands}
|
||||
'';
|
||||
service = {
|
||||
name
|
||||
, serviceType
|
||||
@@ -21,14 +25,12 @@ let
|
||||
, dependencies ? []
|
||||
, contents ? []
|
||||
} @ args: stdenvNoCC.mkDerivation {
|
||||
# stdenvNoCC is to avoid generating derivations with names
|
||||
# we use stdenvNoCC to avoid generating derivations with names
|
||||
# like foo.service-mips-linux-musl
|
||||
inherit name serviceType;
|
||||
inherit run up down;
|
||||
inherit name serviceType up down run;
|
||||
buildInputs = dependencies ++ contents;
|
||||
dependencies = builtins.map (d: d.name) dependencies;
|
||||
contents = builtins.map (d: d.name) contents;
|
||||
shell = "${busybox}/bin/sh";
|
||||
notificationFd = notification-fd;
|
||||
builder = ./builder.sh;
|
||||
};
|
||||
@@ -41,6 +43,7 @@ let
|
||||
, dependencies ? []
|
||||
} @ args: service (args //{
|
||||
serviceType = "longrun";
|
||||
run = serviceScript run;
|
||||
});
|
||||
oneshot = {
|
||||
name
|
||||
@@ -51,8 +54,8 @@ let
|
||||
, ...
|
||||
} @ args : service (args // {
|
||||
serviceType = "oneshot";
|
||||
up = writeAshScript "${name}-up" {} up;
|
||||
down = writeAshScript "${name}-down" {} down;
|
||||
up = writeScript "${name}-up" (serviceScript up);
|
||||
down= writeScript "${name}-down" (serviceScript down);
|
||||
});
|
||||
bundle = {
|
||||
name
|
||||
|
Reference in New Issue
Block a user