commit cb30ce52ebb1530d6d62e3937ac6209c463f2ef2
parent fdffdbb22a2fe19bfc6bd4b4b1bf5cb25a393ee1
Author: Daniel Barlow <dan@telent.net>
Date: Tue, 30 May 2023 18:20:14 +0100
rotuer: use writeFennelScript for odhcpc update script
Diffstat:
3 files changed, 60 insertions(+), 63 deletions(-)
diff --git a/examples/odhcp6-script.fnl b/examples/odhcp6-script.fnl
@@ -0,0 +1,56 @@
+
+(os.chdir (os.getenv "SERVICE_STATE"))
+
+(fn write-value [name value]
+ (with-open [fout (io.open name :w)]
+ (when value (fout:write value))))
+
+(write-value "state" (. arg 2))
+(write-value "ifname" (. arg 1))
+
+(fn write-value-from-env [name]
+ (write-value name (os.getenv (string.upper name))))
+
+(let [wanted
+ [
+ :addresses
+ :aftr
+ :cer
+ :domains
+ :lw406
+ :mape
+ :mapt
+ :ntp_fqdn
+ :ntp_ip
+ :option_1
+ :option_2
+ :option_3
+ :option_4
+ :option_5
+ :passthru
+ :prefixes
+ :ra_addresses
+ :ra_dns
+ :ra_domains
+ :ra_hoplimit
+ :ra_mtu
+ :ra_reachable
+ :ra_retransmit
+ :ra_routes
+ :rdnss
+ :server
+ :sip_domain
+ :sip_ip
+ :sntp_ip
+ :sntp_fqdn
+ ]]
+ (each [_ n (ipairs wanted)]
+ (write-value-from-env n)))
+
+(let [ready (match state
+ "started" false
+ "unbound" false
+ "stopped" false
+ _ true)]
+ (and ready
+ (with-open [fd (io.open "/proc/self/fd/10" :w)] (fd:write "\n"))))
diff --git a/examples/rotuer.nix b/examples/rotuer.nix
@@ -21,6 +21,7 @@ let
dropbear
ifwait
writeText
+ writeFennelScript
serviceFns;
in rec {
boot = {
@@ -235,18 +236,13 @@ in rec {
services.dhcp6 =
let
name = "dhcp6c.wan";
- luafile = pkgs.runCommand "udhcpc-script" {} ''
- ${pkgs.luaSmall.pkgs.fennel}/bin/fennel --compile ${./udhcp6-script.fnl} > $out
- '';
- script = pkgs.writeAshScript "dhcp6-notify" {} ''
- . ${serviceFns}
- (in_outputs ${name}; ${pkgs.luaSmall}/bin/lua ${luafile} "$@")
- '';
+ luafile = writeFennelScript "odhcpc-script" [] ./odhcp6-script.fnl;
in longrun {
inherit name;
notification-fd = 10;
run = ''
- ${pkgs.odhcp6c}/bin/odhcp6c -s ${script} -e -v -p /run/${name}.pid -P 48 $(output ${services.wan} ifname)
+ export SERVICE_STATE=/run/service-state/${name}
+ ${pkgs.odhcp6c}/bin/odhcp6c -s ${luafile} -e -v -p /run/${name}.pid -P 48 $(output ${services.wan} ifname)
)
'';
dependencies = [ services.wan ];
diff --git a/examples/udhcp6-script.fnl b/examples/udhcp6-script.fnl
@@ -1,55 +0,0 @@
-
-
-(fn write-value [name value]
- (with-open [fout (io.open name :w)]
- (when value (fout:write value))))
-
-(write-value "state" (. arg 2))
-(write-value "ifname" (. arg 1))
-
-(fn write-value-from-env [name]
- (write-value name (os.getenv (string.upper name))))
-
-(let [wanted
- [
- :addresses
- :aftr
- :cer
- :domains
- :lw406
- :mape
- :mapt
- :ntp_fqdn
- :ntp_ip
- :option_1
- :option_2
- :option_3
- :option_4
- :option_5
- :passthru
- :prefixes
- :ra_addresses
- :ra_dns
- :ra_domains
- :ra_hoplimit
- :ra_mtu
- :ra_reachable
- :ra_retransmit
- :ra_routes
- :rdnss
- :server
- :sip_domain
- :sip_ip
- :sntp_ip
- :sntp_fqdn
- ]]
- (each [_ n (ipairs wanted)]
- (write-value-from-env n)))
-
-(let [ready (match state
- "started" false
- "unbound" false
- "stopped" false
- _ true)]
- (and ready
- (with-open [fd (io.open "/proc/self/fd/10" :w)] (fd:write "\n"))))