liminix/pkgs/liminix-tools/services/default.nix
Daniel Barlow 5427456c21 rename notificationFd to notification-fd
it's perfectly valid syntax and consistent with the s6 spelling
2023-03-04 21:19:30 +00:00

72 lines
1.6 KiB
Nix

{
stdenvNoCC
, s6-rc
, lib
, busybox
, callPackage
, writeScript
, serviceFns
}:
let
inherit (builtins) concatStringsSep;
output = service: name: "/run/service-state/${service.name}/${name}";
serviceScript = commands : ''
#!${busybox}/bin/sh
. ${serviceFns}
${commands}
'';
service = {
name
, serviceType
, run ? null
, up ? null
, down ? null
, outputs ? []
, notification-fd ? null
, dependencies ? []
, contents ? []
} @ args: stdenvNoCC.mkDerivation {
# we use stdenvNoCC to avoid generating derivations with names
# like foo.service-mips-linux-musl
inherit name serviceType up down run notification-fd;
buildInputs = dependencies ++ contents;
dependencies = builtins.map (d: d.name) dependencies;
contents = builtins.map (d: d.name) contents;
builder = ./builder.sh;
};
longrun = {
name
, run
, outputs ? []
, notification-fd ? null
, dependencies ? []
} @ args: service (args //{
serviceType = "longrun";
run = serviceScript run;
});
oneshot = {
name
, up
, down
, outputs ? []
, dependencies ? []
, ...
} @ args : service (args // {
serviceType = "oneshot";
up = writeScript "${name}-up" (serviceScript up);
down= writeScript "${name}-down" (serviceScript down);
});
bundle = {
name
, contents ? []
, dependencies ? []
, ...
} @ args: service (args // {
serviceType = "bundle";
inherit contents dependencies;
});
target = bundle;
in {
inherit target bundle oneshot longrun output;
}