change output references from attrset to lambda

this is so that we can distinguish a ref from a literal parameter that
might be a attrset
This commit is contained in:
Daniel Barlow 2024-08-23 22:25:57 +01:00
parent dd75322c10
commit 9c30b6f882
6 changed files with 63 additions and 73 deletions

View File

@ -30,6 +30,7 @@
lns = { hostname = "l2tp.aaisp.net.uk"; address = "194.4.172.12"; }; lns = { hostname = "l2tp.aaisp.net.uk"; address = "194.4.172.12"; };
inherit (pkgs.liminix.services) oneshot longrun target; inherit (pkgs.liminix.services) oneshot longrun target;
inherit (pkgs.liminix) outputRef;
inherit (pkgs.pseudofile) dir symlink; inherit (pkgs.pseudofile) dir symlink;
inherit (pkgs) serviceFns; inherit (pkgs) serviceFns;
svc = config.system.service; svc = config.system.service;
@ -99,14 +100,18 @@ in rec {
localDomain = "lan"; localDomain = "lan";
}; };
}; };
wan = { wan =
interface = let let
secret = path: { service = config.services.secrets; inherit path; }; secret = outputRef config.services.secrets;
username = secret "ppp/username";
password = secret "ppp/password";
in {
interface =
let
pppoe = svc.pppoe.build { pppoe = svc.pppoe.build {
interface = config.hardware.networkInterfaces.wan; interface = config.hardware.networkInterfaces.wan;
debug = true; debug = true;
username = secret "ppp/username"; inherit username password;
password = secret "ppp/password";
}; };
l2tp = l2tp =
@ -123,11 +128,7 @@ in rec {
}; };
l2tpd= svc.l2tp.build { l2tpd= svc.l2tp.build {
lns = lns.address; lns = lns.address;
ppp-options = [ inherit username password;
"debug" "+ipv6" "noauth"
"name" rsecrets.l2tp.name
"password" rsecrets.l2tp.password
];
dependencies = [config.services.lns-address route check-address]; dependencies = [config.services.lns-address route check-address];
}; };
in in
@ -154,10 +155,7 @@ in rec {
channel = "6"; channel = "6";
ieee80211n = 1; ieee80211n = 1;
} // wirelessConfig // { } // wirelessConfig // {
wpa_passphrase = { wpa_passphrase = outputRef config.services.secrets "wpa_passphrase";
service = config.services.secrets;
path = "wpa_passphrase";
};
}; };
"${rsecrets.ssid}5" = rec { "${rsecrets.ssid}5" = rec {
@ -170,14 +168,10 @@ in rec {
ieee80211n = 1; ieee80211n = 1;
ieee80211ac = 1; ieee80211ac = 1;
} // wirelessConfig // { } // wirelessConfig // {
wpa_passphrase = { wpa_passphrase = outputRef config.services.secrets "wpa_passphrase";
service = config.services.secrets;
path = "wpa_passphrase";
}; };
}; };
}; };
};
services.bootstrap-dhcpc = svc.network.dhcp.client.build { services.bootstrap-dhcpc = svc.network.dhcp.client.build {
interface = config.services.wwan; interface = config.services.wwan;

View File

@ -30,7 +30,7 @@ let
literal_or_output = o: ({ literal_or_output = o: ({
string = builtins.toJSON; string = builtins.toJSON;
int = builtins.toJSON; int = builtins.toJSON;
set = (o: "output(${builtins.toJSON o.service}, ${builtins.toJSON o.path})"); lambda = (o: "output(${builtins.toJSON (o "service")}, ${builtins.toJSON (o "path")})");
}.${builtins.typeOf o}) o; }.${builtins.typeOf o}) o;
conf = conf =

View File

@ -40,12 +40,12 @@ in {
description = "ethernet interface to run PPPoE over"; description = "ethernet interface to run PPPoE over";
}; };
username = mkOption { username = mkOption {
type = types.nullOr liminix.lib.types.replacable; type = types.nullOr (liminix.lib.types.replacable types.str);
default = null; default = null;
description = "username"; description = "username";
}; };
password = mkOption { password = mkOption {
type = types.nullOr liminix.lib.types.replacable; type = types.nullOr (liminix.lib.types.replacable types.str);
default = null; default = null;
description = "password"; description = "password";
}; };
@ -83,12 +83,12 @@ in {
description = "hostname or address of the L2TP network server"; description = "hostname or address of the L2TP network server";
}; };
username = mkOption { username = mkOption {
type = types.nullOr liminix.lib.types.replacable; type = types.nullOr (liminix.lib.types.replacable types.str);
default = null; default = null;
description = "username"; description = "username";
}; };
password = mkOption { password = mkOption {
type = types.nullOr liminix.lib.types.replacable; type = types.nullOr (liminix.lib.types.replacable types.str);
default = null; default = null;
description = "password"; description = "password";
}; };
@ -116,6 +116,7 @@ in {
}; };
ppp-options = mkOption { ppp-options = mkOption {
type = types.listOf types.str; type = types.listOf types.str;
default = [];
description = "options supplied on ppp command line"; description = "options supplied on ppp command line";
}; };
}; };

View File

@ -44,7 +44,7 @@ let
let v = o: ({ let v = o: ({
string = builtins.toJSON; string = builtins.toJSON;
int = builtins.toJSON; int = builtins.toJSON;
set = (o: "output(${builtins.toJSON o.service}, ${builtins.toJSON o.path})"); lambda = (o: "output(${builtins.toJSON (o "service")}, ${builtins.toJSON (o "path")})");
}.${builtins.typeOf o}) o; }.${builtins.typeOf o}) o;
in o: "{{ ${v o} }}"; in o: "{{ ${v o} }}";

View File

@ -44,7 +44,7 @@ let
let v = o: ({ let v = o: ({
string = builtins.toJSON; string = builtins.toJSON;
int = builtins.toJSON; int = builtins.toJSON;
set = (o: "output(${builtins.toJSON o.service}, ${builtins.toJSON o.path})"); lambda = (o: "output(${builtins.toJSON (o "service")}, ${builtins.toJSON (o "path")})");
}.${builtins.typeOf o}) o; }.${builtins.typeOf o}) o;
in o: "{{ ${v o} }}"; in o: "{{ ${v o} }}";
ppp-options' = ppp-options' =

View File

@ -14,6 +14,9 @@ in {
uimage = callPackage ./kernel/uimage.nix { }; uimage = callPackage ./kernel/uimage.nix { };
kernel = callPackage ./kernel { }; kernel = callPackage ./kernel { };
}; };
outputRef = service : path :
let h = { inherit service path; };
in x : h.${x};
callService = path : parameters : callService = path : parameters :
let pkg = callPackage path {}; let pkg = callPackage path {};
checkTypes = t : p : typeChecked (builtins.toString path) t p; checkTypes = t : p : typeChecked (builtins.toString path) t p;
@ -43,18 +46,10 @@ in {
description = "parametrisable s6-rc service definition"; description = "parametrisable s6-rc service definition";
check = x: lib.isAttrs x && x ? parameters && x ? build; check = x: lib.isAttrs x && x ? parameters && x ? build;
}; };
replacable = types.either replacable = t : types.either
types.str t
(types.submodule { # function might return a service or a path
options = { (types.functionTo types.anything);
service = mkOption {
type = service;
};
path = mkOption {
type = types.str;
};
};
});
}; };
inherit typeChecked; inherit typeChecked;
}; };