liminix

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

commit f030efbd494413bfcdf48dd0d90839459ac38c7e
parent 7f280b5d6a98ba165521ab564690924b34d44050
Author: Daniel Barlow <dan@telent.net>
Date:   Sun,  2 Oct 2022 14:44:29 +0100

extract "service" function to reduce duplicated code

Diffstat:
Mpkgs/liminix-tools/services/default.nix | 59++++++++++++++++++++++++++++++-----------------------------
1 file changed, 30 insertions(+), 29 deletions(-)

diff --git a/pkgs/liminix-tools/services/default.nix b/pkgs/liminix-tools/services/default.nix @@ -9,22 +9,39 @@ let inherit (builtins) concatStringsSep; output = service: name: "/run/service-state/${service.name}/${name}"; - longrun = { + + service = { name - , run + , serviceType + , run ? null + , up ? null + , down ? null , outputs ? [] , notification-fd ? null , dependencies ? [] + , contents ? [] } @ args: stdenvNoCC.mkDerivation { - inherit name; - serviceType = "longrun"; - buildInputs = dependencies; + # stdenvNoCC is to avoid generating derivations with names + # like foo.service-mips-linux-musl + inherit name serviceType; + inherit run up down; + buildInputs = dependencies ++ contents; dependencies = builtins.map (d: d.name) dependencies; + contents = builtins.map (d: d.name) contents; shell = "${busybox}/bin/sh"; - inherit run; notificationFd = notification-fd; builder = ./builder.sh; }; + + longrun = { + name + , run + , outputs ? [] + , notification-fd ? null + , dependencies ? [] + } @ args: service (args //{ + serviceType = "longrun"; + }); oneshot = { name , up @@ -32,37 +49,21 @@ let , outputs ? [] , dependencies ? [] , ... - } @ args: stdenvNoCC.mkDerivation { - # stdenvNoCC is to avoid generating derivations with names - # like foo.service-mips-linux-musl - inherit name; + } @ args : service (args // { serviceType = "oneshot"; - # does this suffice to make sure dependencies are included - # even though the built output has no references to their - # store directories? - buildInputs = dependencies; - shell = "${busybox}/bin/sh"; - # up and down for oneshots are pathnames not scripts up = writeAshScript "${name}-up" {} up; down = writeAshScript "${name}-down" {} down; - dependencies = builtins.map (d: d.name) dependencies; - builder = ./builder.sh; - }; - target = { + }); + bundle = { name , contents ? [] , dependencies ? [] , ... - }: stdenvNoCC.mkDerivation { - inherit name; + } @ args: service (args // { serviceType = "bundle"; - contents = builtins.map (d: d.name) contents; - buildInputs = dependencies ++ contents; - dependencies = builtins.map (d: d.name) dependencies; - shell = "${busybox}/bin/sh"; - builder = ./builder.sh; - }; - bundle = { name, ... } @args : target (args // { inherit name;}); + inherit contents dependencies; + }); + target = bundle; in { inherit target bundle oneshot longrun output; }