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-20 00:51:38 +02:00
|
|
|
} :let
|
|
|
|
inherit (builtins) concatStringsSep;
|
|
|
|
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 {
|
|
|
|
name = "${name}.service";
|
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
|
|
|
|
name = "${name}.service";
|
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-22 01:10:55 +02:00
|
|
|
bundle = { name, ... } @args : target (args // { name = "${name}.bundle";});
|
|
|
|
|
2022-09-20 00:51:38 +02:00
|
|
|
in {
|
|
|
|
networking = {
|
|
|
|
interface = { type, device } @ args: oneshot {
|
|
|
|
name = "${device}.link";
|
|
|
|
up = "ip link set up dev ${device}";
|
|
|
|
down = "ip link set down dev ${device}";
|
|
|
|
} // {
|
|
|
|
inherit device;
|
|
|
|
};
|
2022-09-25 17:51:13 +02:00
|
|
|
address = interface: { family, prefixLength, address } @ args:
|
|
|
|
let inherit (builtins) toString;
|
|
|
|
in oneshot {
|
|
|
|
dependencies = [ interface ];
|
|
|
|
name = "${interface.device}.addr.${address}";
|
|
|
|
up = "ip address add ${address}/${toString prefixLength} dev ${interface.device} ";
|
|
|
|
down = "ip address del ${address}/${toString prefixLength} dev ${interface.device} ";
|
|
|
|
};
|
2022-09-22 12:10:41 +02:00
|
|
|
udhcpc = callPackage ./networking/udhcpc.nix {};
|
2022-09-20 00:51:38 +02:00
|
|
|
odhcpc = interface: { ... } @ args: longrun {
|
|
|
|
name = "${interface.device}.odhcp";
|
|
|
|
run = "odhcpcd ${interface.device}";
|
|
|
|
};
|
2022-09-25 12:54:31 +02:00
|
|
|
pppoe = callPackage ./networking/pppoe.nix {};
|
2022-09-20 00:51:38 +02:00
|
|
|
};
|
|
|
|
services = {
|
2022-09-22 01:10:55 +02:00
|
|
|
inherit longrun oneshot bundle target;
|
2022-09-25 22:10:04 +02:00
|
|
|
output = service: name: "/run/service-state/${service.name}/${name}";
|
2022-09-20 00:51:38 +02:00
|
|
|
};
|
|
|
|
}
|