liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit d760c2d27b1c4b8e6ea8c40abea54ff3975d453f
parent 1e139c22fdc4a1be37855b90e746cb5727039b0f
Author: Daniel Barlow <dan@telent.net>
Date:   Thu,  8 Aug 2024 15:35:11 +0100

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

Diffstat:
Mpkgs/default.nix | 1+
Apkgs/http-fstree/default.nix | 37+++++++++++++++++++++++++++++++++++++
Apkgs/http-fstree/example.json | 19+++++++++++++++++++
Apkgs/http-fstree/http-fstree.fnl | 19+++++++++++++++++++
4 files changed, 76 insertions(+), 0 deletions(-)

diff --git a/pkgs/default.nix b/pkgs/default.nix @@ -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 { }; diff --git a/pkgs/http-fstree/default.nix b/pkgs/http-fstree/default.nix @@ -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} + ''; +} diff --git a/pkgs/http-fstree/example.json b/pkgs/http-fstree/example.json @@ -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" + } +} diff --git a/pkgs/http-fstree/http-fstree.fnl b/pkgs/http-fstree/http-fstree.fnl @@ -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 }