forked from DGNum/liminix
3677ab9cb3
getting weird permission errors, seems simpler all raound just to put them somewhere else
93 lines
2.7 KiB
Nix
93 lines
2.7 KiB
Nix
{
|
|
stdenvNoCC
|
|
, s6-rc
|
|
, lib
|
|
, busybox
|
|
, callPackage
|
|
, writeAshScript
|
|
} :let
|
|
inherit (builtins) concatStringsSep;
|
|
longrun = {
|
|
name
|
|
, run
|
|
, outputs ? []
|
|
, notification-fd ? null
|
|
, dependencies ? []
|
|
} @ args: stdenvNoCC.mkDerivation {
|
|
name = "${name}.service";
|
|
type = "longrun";
|
|
buildInputs = dependencies;
|
|
dependencies = builtins.map (d: d.name) dependencies;
|
|
shell = "${busybox}/bin/sh";
|
|
inherit run;
|
|
notificationFd = notification-fd;
|
|
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";
|
|
type = "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 = {
|
|
name
|
|
, contents ? []
|
|
, dependencies ? []
|
|
, ...
|
|
}: stdenvNoCC.mkDerivation {
|
|
inherit name;
|
|
type = "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 // { name = "${name}.bundle";});
|
|
|
|
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;
|
|
};
|
|
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} ";
|
|
};
|
|
udhcpc = callPackage ./networking/udhcpc.nix {};
|
|
odhcpc = interface: { ... } @ args: longrun {
|
|
name = "${interface.device}.odhcp";
|
|
run = "odhcpcd ${interface.device}";
|
|
};
|
|
pppoe = callPackage ./networking/pppoe.nix {};
|
|
};
|
|
services = {
|
|
inherit longrun oneshot bundle target;
|
|
output = service: name: "/run/service-state/${service.name}/${name}";
|
|
};
|
|
}
|