2022-09-20 00:51:38 +02:00
|
|
|
{
|
|
|
|
stdenvNoCC
|
|
|
|
, s6-rc
|
2022-09-22 01:10:55 +02:00
|
|
|
, lib
|
|
|
|
, busybox
|
2022-09-22 12:10:41 +02:00
|
|
|
, callPackage
|
2022-09-25 22:02:10 +02:00
|
|
|
, writeAshScript
|
2022-09-26 13:26:54 +02:00
|
|
|
}:
|
|
|
|
let
|
2022-09-20 00:51:38 +02:00
|
|
|
inherit (builtins) concatStringsSep;
|
2022-09-26 13:26:54 +02:00
|
|
|
output = service: name: "/run/service-state/${service.name}/${name}";
|
2022-09-20 00:51:38 +02:00
|
|
|
longrun = {
|
|
|
|
name
|
|
|
|
, run
|
|
|
|
, outputs ? []
|
2022-09-25 22:06:08 +02:00
|
|
|
, notification-fd ? null
|
2022-09-20 00:51:38 +02:00
|
|
|
, dependencies ? []
|
|
|
|
} @ args: stdenvNoCC.mkDerivation {
|
2022-09-27 23:35:29 +02:00
|
|
|
inherit name;
|
2022-09-26 12:46:09 +02:00
|
|
|
serviceType = "longrun";
|
2022-09-20 00:51:38 +02:00
|
|
|
buildInputs = dependencies;
|
|
|
|
dependencies = builtins.map (d: d.name) dependencies;
|
2022-09-22 01:10:55 +02:00
|
|
|
shell = "${busybox}/bin/sh";
|
2022-09-20 00:51:38 +02:00
|
|
|
inherit run;
|
2022-09-25 22:06:08 +02:00
|
|
|
notificationFd = notification-fd;
|
2022-09-20 00:51:38 +02:00
|
|
|
builder = ./builder.sh;
|
|
|
|
};
|
|
|
|
oneshot = {
|
|
|
|
name
|
|
|
|
, up
|
|
|
|
, down
|
|
|
|
, outputs ? []
|
|
|
|
, dependencies ? []
|
|
|
|
, ...
|
|
|
|
} @ args: stdenvNoCC.mkDerivation {
|
|
|
|
# stdenvNoCC is to avoid generating derivations with names
|
|
|
|
# like foo.service-mips-linux-musl
|
2022-09-27 23:35:29 +02:00
|
|
|
inherit name;
|
2022-09-26 12:46:09 +02:00
|
|
|
serviceType = "oneshot";
|
2022-09-20 00:51:38 +02:00
|
|
|
# does this suffice to make sure dependencies are included
|
|
|
|
# even though the built output has no references to their
|
|
|
|
# store directories?
|
|
|
|
buildInputs = dependencies;
|
2022-09-22 01:10:55 +02:00
|
|
|
shell = "${busybox}/bin/sh";
|
2022-09-25 22:02:10 +02:00
|
|
|
# up and down for oneshots are pathnames not scripts
|
|
|
|
up = writeAshScript "${name}-up" {} up;
|
|
|
|
down = writeAshScript "${name}-down" {} down;
|
2022-09-20 00:51:38 +02:00
|
|
|
dependencies = builtins.map (d: d.name) dependencies;
|
|
|
|
builder = ./builder.sh;
|
|
|
|
};
|
2022-09-22 01:10:55 +02:00
|
|
|
target = {
|
2022-09-20 00:51:38 +02:00
|
|
|
name
|
|
|
|
, contents ? []
|
|
|
|
, dependencies ? []
|
|
|
|
, ...
|
|
|
|
}: stdenvNoCC.mkDerivation {
|
2022-09-22 01:10:55 +02:00
|
|
|
inherit name;
|
2022-09-26 12:46:09 +02:00
|
|
|
serviceType = "bundle";
|
2022-09-20 00:51:38 +02:00
|
|
|
contents = builtins.map (d: d.name) contents;
|
2022-09-22 13:45:41 +02:00
|
|
|
buildInputs = dependencies ++ contents;
|
2022-09-20 00:51:38 +02:00
|
|
|
dependencies = builtins.map (d: d.name) dependencies;
|
2022-09-22 01:10:55 +02:00
|
|
|
shell = "${busybox}/bin/sh";
|
2022-09-20 00:51:38 +02:00
|
|
|
builder = ./builder.sh;
|
|
|
|
};
|
2022-09-27 23:35:29 +02:00
|
|
|
bundle = { name, ... } @args : target (args // { inherit name;});
|
2022-09-20 00:51:38 +02:00
|
|
|
in {
|
2022-09-26 13:26:54 +02:00
|
|
|
inherit target bundle oneshot longrun output;
|
2022-09-20 00:51:38 +02:00
|
|
|
}
|