http-fstree downloads a json file and converts to service outputs

This commit is contained in:
Daniel Barlow 2024-08-08 15:35:11 +01:00
parent 1e139c22fd
commit d760c2d27b
4 changed files with 76 additions and 0 deletions

View File

@ -62,6 +62,7 @@ in {
gen_init_cpio = callPackage ./gen_init_cpio { };
go-l2tp = callPackage ./go-l2tp { };
hi = callPackage ./hi { };
http-fstree = callPackage ./http-fstree { };
ifwait = callPackage ./ifwait { };
initramfs-peek = callPackage ./initramfs-peek { };
kernel-backport = callPackage ./kernel-backport { };

View File

@ -0,0 +1,37 @@
{
fetchurl,
writeFennel,
fennel,
fennelrepl,
runCommand,
lua,
anoia,
linotify,
lualinux,
fetch-freebsd,
openssl,
rxi-json,
stdenv
}:
let name = "http-fstree";
in stdenv.mkDerivation {
inherit name;
src = ./.;
buildInputs = [fetch-freebsd rxi-json openssl lua];
buildPhase = "";
installPhase = ''
mkdir -p $out/bin
cp -p ${writeFennel name {
packages = [
fetch-freebsd
rxi-json
anoia
lualinux
linotify
] ;
mainFunction = "run";
} ./http-fstree.fnl } $out/bin/${name}
'';
}

View File

@ -0,0 +1,19 @@
{
"wpa_passphrase": "you bring light in",
"ssid": "liminix",
"l2tp": {
"name": "abcde@a.1",
"password": "NotMyIspPassword"
},
"root": {
"passwd": "$6$6pt0mpbgcB7kC2RJ$kSBoCYGyi1.qxt7dqmexLj1l8E6oTZJZmfGyJSsMYMW.jlsETxdgQSdv6ptOYDM7DHAwf6vLG0pz3UD31XBfC1",
"openssh": {
"authorizedKeys": {
"keys": [ ]
}
}
},
"lan": {
"prefix": "10.8.0"
}
}

View File

@ -0,0 +1,19 @@
(local json (require :json))
(local http (require :fetch))
(local svc (require :anoia.svc))
(local { : utime } (require :lualinux))
(fn download [url dest]
(match (http.fetch url)
(nil code str)
(assert nil (.. "error " code ": " str))
(body { : last-modified })
(let [service (svc.open dest)]
(service:output "." (json.decode body))
(utime dest last-modified))))
(fn run [] (download (. arg 1) (. arg 2)))
{ : run }