Compare commits

...

2 Commits

15 changed files with 59 additions and 62 deletions

View File

@ -174,7 +174,7 @@ To expose a service template in a module, it needs the following:
.. code-block:: nix .. code-block:: nix
config.system.service.cowsay = liminix.callService ./service.nix { config.system.service.cowsay = config.system.callService ./service.nix {
address = mkOption { address = mkOption {
type = types.str; type = types.str;
default = "0.0.0.0"; default = "0.0.0.0";

View File

@ -59,63 +59,60 @@ in rec {
services.wan = services.wan =
let let
z = final : prev: { controller = longrun rec {
controller = longrun rec { name = "wan-switcher";
name = "wan-switcher"; run = ''
run = ''
in_outputs ${name} in_outputs ${name}
exec ${pkgs.s6-rc-round-robin}/bin/s6-rc-round-robin \ exec ${pkgs.s6-rc-round-robin}/bin/s6-rc-round-robin \
-p ${final.proxy.name} \ -p ${proxy.name} \
${lib.concatStringsSep " " ${lib.concatStringsSep " "
(builtins.map (f: f.name) [final.pppoe final.l2tp])} (builtins.map (f: f.name) [pppoe l2tp])}
''; '';
}; };
pppoe = (svc.pppoe.build { pppoe = (svc.pppoe.build {
interface = config.hardware.networkInterfaces.wan; interface = config.hardware.networkInterfaces.wan;
ppp-options = [
"debug" "+ipv6" "noauth"
"name" rsecrets.l2tp.name
"password" rsecrets.l2tp.password
];
}).overrideAttrs(o: { inherit controller; });
l2tp =
let
check-address = oneshot rec {
name = "check-lns-address";
up = "grep -Fx ${ lns.address} $(output_path ${services.lns-address} addresses)";
dependencies = [ services.lns-address ];
};
route = svc.network.route.build {
via = "$(output ${services.dhcpc} router)";
target = lns.address;
dependencies = [services.dhcpc check-address];
};
in (svc.l2tp.build {
lns = lns.address;
ppp-options = [ ppp-options = [
"debug" "+ipv6" "noauth" "debug" "+ipv6" "noauth"
"name" rsecrets.l2tp.name "name" rsecrets.l2tp.name
"password" rsecrets.l2tp.password "password" rsecrets.l2tp.password
]; ];
}).overrideAttrs(o: { inherit (final) controller; }); dependencies = [config.services.lns-address route check-address];
}).overrideAttrs(o: { inherit controller; });
l2tp = proxy = oneshot rec {
let name = "wan-proxy";
check-address = oneshot rec { inherit controller;
name = "check-lns-address"; buildInputs = [ pppoe l2tp];
up = "grep -Fx ${ lns.address} $(output_path ${services.lns-address} addresses)"; up = ''
dependencies = [ services.lns-address ];
};
route = svc.network.route.build {
via = "$(output ${services.dhcpc} router)";
target = lns.address;
dependencies = [services.dhcpc check-address];
};
in (svc.l2tp.build {
lns = lns.address;
ppp-options = [
"debug" "+ipv6" "noauth"
"name" rsecrets.l2tp.name
"connect-delay" "5000"
"password" rsecrets.l2tp.password
];
dependencies = [config.services.lns-address route check-address];
}).overrideAttrs(o: { inherit (final) controller; });
proxy = oneshot rec {
name = "wan-proxy";
inherit (final) controller;
buildInputs = with final; [ pppoe l2tp];
up = ''
echo start proxy ${name} echo start proxy ${name}
set -x set -x
(in_outputs ${name} (in_outputs ${name}
cp -rv $(output_path ${final.controller} active)/* . cp -rv $(output_path ${controller} active)/* .
) )
''; '';
};
}; };
in (lib.fix (lib.extends z (prev : { }))).proxy; in proxy;
services.sshd = svc.ssh.build { }; services.sshd = svc.ssh.build { };

View File

@ -22,7 +22,7 @@ in
}; };
}; };
config.system.service.bridge = { config.system.service.bridge = {
primary = liminix.callService ./primary.nix { primary = config.system.callService ./primary.nix {
ifname = mkOption { ifname = mkOption {
type = types.str; type = types.str;
description = "bridge interface name to create"; description = "bridge interface name to create";

View File

@ -23,13 +23,13 @@ in
}; };
}; };
config.system.service.dhcp6c = { config.system.service.dhcp6c = {
client = liminix.callService ./client.nix { client = config.system.callService ./client.nix {
interface = mkOption { interface = mkOption {
type = liminix.lib.types.interface; type = liminix.lib.types.interface;
description = "interface (usually WAN) to query for DHCP6"; description = "interface (usually WAN) to query for DHCP6";
}; };
}; };
address = liminix.callService ./address.nix { address = config.system.callService ./address.nix {
client = mkOption { client = mkOption {
type = types.anything; # liminix.lib.types.service; type = types.anything; # liminix.lib.types.service;
}; };
@ -38,7 +38,7 @@ in
description = "interface to assign the address to"; description = "interface to assign the address to";
}; };
}; };
prefix = liminix.callService ./prefix.nix { prefix = config.system.callService ./prefix.nix {
client = mkOption { client = mkOption {
type = types.anything; # liminix.lib.types.service; type = types.anything; # liminix.lib.types.service;
}; };

View File

@ -16,7 +16,7 @@ in {
}; };
}; };
config = { config = {
system.service.dnsmasq = liminix.callService ./service.nix { system.service.dnsmasq = config.system.callService ./service.nix {
user = mkOption { user = mkOption {
type = types.str; type = types.str;
default = "dnsmasq"; default = "dnsmasq";

View File

@ -54,7 +54,7 @@ in
}; };
config = { config = {
system.service.firewall = system.service.firewall =
let svc = liminix.callService ./service.nix { let svc = config.system.callService ./service.nix {
extraRules = mkOption { extraRules = mkOption {
type = types.attrsOf types.attrs; type = types.attrsOf types.attrs;
description = "firewall ruleset"; description = "firewall ruleset";

View File

@ -22,7 +22,7 @@ in {
}; };
}; };
config = { config = {
system.service.hostapd = liminix.callService ./service.nix { system.service.hostapd = config.system.callService ./service.nix {
interface = mkOption { interface = mkOption {
type = liminix.lib.types.service; type = liminix.lib.types.service;
}; };

View File

@ -64,7 +64,7 @@ in {
services.loopback = config.hardware.networkInterfaces.lo; services.loopback = config.hardware.networkInterfaces.lo;
system.service.network = { system.service.network = {
link = liminix.callService ./link.nix { link = config.system.callService ./link.nix {
ifname = mkOption { ifname = mkOption {
type = types.str; type = types.str;
example = "eth0"; example = "eth0";
@ -89,7 +89,7 @@ in {
example = 1480; example = 1480;
}; };
}; };
address = liminix.callService ./address.nix { address = config.system.callService ./address.nix {
interface = mkOption { interface = mkOption {
type = liminix.lib.types.service; type = liminix.lib.types.service;
}; };
@ -104,7 +104,7 @@ in {
}; };
}; };
route = liminix.callService ./route.nix { route = config.system.callService ./route.nix {
interface = mkOption { interface = mkOption {
type = types.nullOr liminix.lib.types.interface; type = types.nullOr liminix.lib.types.interface;
default = null; default = null;
@ -125,7 +125,7 @@ in {
}; };
}; };
forward = liminix.callService ./forward.nix { forward = config.system.callService ./forward.nix {
enableIPv4 = mkOption { enableIPv4 = mkOption {
type = types.bool; type = types.bool;
default = true; default = true;
@ -136,7 +136,7 @@ in {
}; };
}; };
dhcp.client = liminix.callService ./dhcpc.nix { dhcp.client = config.system.callService ./dhcpc.nix {
interface = mkOption { interface = mkOption {
type = liminix.lib.types.service; type = liminix.lib.types.service;
}; };

View File

@ -18,7 +18,7 @@ in {
}; };
}; };
config = { config = {
system.service.ntp = liminix.callService ./service.nix { system.service.ntp = config.system.callService ./service.nix {
user = mkOption { user = mkOption {
type = types.str; type = types.str;
default = "ntp"; default = "ntp";

View File

@ -22,7 +22,7 @@ in {
}; };
}; };
config = { config = {
system.service.pppoe = pkgs.liminix.callService ./pppoe.nix { system.service.pppoe = config.system.callService ./pppoe.nix {
interface = mkOption { interface = mkOption {
type = liminix.lib.types.service; type = liminix.lib.types.service;
description = "ethernet interface to run PPPoE over"; description = "ethernet interface to run PPPoE over";
@ -32,7 +32,7 @@ in {
description = "options supplied on ppp command line"; description = "options supplied on ppp command line";
}; };
}; };
system.service.l2tp = pkgs.liminix.callService ./l2tp.nix { system.service.l2tp = config.system.callService ./l2tp.nix {
lns = mkOption { lns = mkOption {
type = types.str; type = types.str;
description = "hostname or address of the L2TP network server"; description = "hostname or address of the L2TP network server";

View File

@ -14,7 +14,7 @@ in {
}; };
}; };
config = { config = {
system.service.uevent-rule = liminix.callService ./rule.nix { system.service.uevent-rule = config.system.callService ./rule.nix {
serviceName = mkOption { serviceName = mkOption {
description = "name of the service to run when the rule matches"; description = "name of the service to run when the rule matches";
type = types.str; type = types.str;

View File

@ -20,7 +20,7 @@ in {
}; };
}; };
config.system.service = { config.system.service = {
ssh = liminix.callService ./ssh.nix { ssh = config.system.callService ./ssh.nix {
address = mkOption { address = mkOption {
type = types.nullOr types.str; type = types.nullOr types.str;
default = null; default = null;

View File

@ -19,7 +19,7 @@ in
options = { options = {
system.service.vlan = mkOption { type = liminix.lib.types.serviceDefn; }; system.service.vlan = mkOption { type = liminix.lib.types.serviceDefn; };
}; };
config.system.service.vlan = liminix.callService ./service.nix { config.system.service.vlan = config.system.callService ./service.nix {
ifname = mkOption { ifname = mkOption {
type = types.str; type = types.str;
description = "interface name to create"; description = "interface name to create";

View File

@ -15,7 +15,7 @@ in
type = liminix.lib.types.serviceDefn; type = liminix.lib.types.serviceDefn;
}; };
}; };
config.system.service.watchdog = liminix.callService ./watchdog.nix { config.system.service.watchdog = config.system.callService ./watchdog.nix {
watched = mkOption { watched = mkOption {
description = "services to watch"; description = "services to watch";
type = types.listOf liminix.lib.types.service; type = types.listOf liminix.lib.types.service;

View File

@ -20,7 +20,7 @@ in
type = liminix.lib.types.serviceDefn; type = liminix.lib.types.serviceDefn;
}; };
config.boot.zyxel-dual-image = liminix.callService ./service.nix { config.boot.zyxel-dual-image = config.system.callService ./service.nix {
ensureActiveImage = mkOption { ensureActiveImage = mkOption {
type = types.enum [ "primary" "secondary" ]; type = types.enum [ "primary" "secondary" ];
default = "primary"; default = "primary";