rename http-fstree => json-to-fstree
it works for file urls as well, not just http
This commit is contained in:
37
pkgs/json-to-fstree/default.nix
Normal file
37
pkgs/json-to-fstree/default.nix
Normal file
@@ -0,0 +1,37 @@
|
||||
{
|
||||
fetchurl,
|
||||
writeFennel,
|
||||
fennel,
|
||||
fennelrepl,
|
||||
runCommand,
|
||||
lua,
|
||||
anoia,
|
||||
linotify,
|
||||
lualinux,
|
||||
fetch-freebsd,
|
||||
openssl,
|
||||
rxi-json,
|
||||
stdenv
|
||||
}:
|
||||
let name = "json-to-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";
|
||||
} ./${name}.fnl } $out/bin/${name}
|
||||
'';
|
||||
}
|
24
pkgs/json-to-fstree/json-to-fstree.fnl
Normal file
24
pkgs/json-to-fstree/json-to-fstree.fnl
Normal file
@@ -0,0 +1,24 @@
|
||||
(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)
|
||||
lock (.. dest "/.lock")
|
||||
state (.. dest "/state")]
|
||||
(with-open [fout (io.open lock :w)] (fout:write ""))
|
||||
(service:output "." (json.decode body))
|
||||
(with-open [fout (io.open state :w)] (fout:write "ok"))
|
||||
(os.remove lock)
|
||||
(utime dest last-modified))))
|
||||
|
||||
(fn run [] (download (. arg 1) (. arg 2)))
|
||||
|
||||
|
||||
{ : run }
|
Reference in New Issue
Block a user