diff --git a/pkgs/default.nix b/pkgs/default.nix index ae42ee9..6dc0904 100644 --- 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 new file mode 100644 index 0000000..ba31cc4 --- /dev/null +++ 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 new file mode 100644 index 0000000..c3fd5b2 --- /dev/null +++ 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 new file mode 100644 index 0000000..6e83a19 --- /dev/null +++ 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 }