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

View File

@ -30,7 +30,7 @@ let
literal_or_output = o: ({
string = 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;
conf =

View File

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

View File

@ -44,7 +44,7 @@ let
let v = o: ({
string = 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;
in o: "{{ ${v o} }}";

View File

@ -44,7 +44,7 @@ let
let v = o: ({
string = 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;
in o: "{{ ${v o} }}";
ppp-options' =

View File

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