port: bring output-template
, outputRef
, health check services from Liminix upstream #28
15 changed files with 73 additions and 0 deletions
|
@ -91,6 +91,7 @@ in {
|
|||
odhcp-script = callPackage ./odhcp-script {};
|
||||
odhcp6c = callPackage ./odhcp6c {};
|
||||
openwrt = callPackage ./openwrt {};
|
||||
output-template = callPackage ./output-template { };
|
||||
ppp = callPackage ./ppp {};
|
||||
pppoe = callPackage ./pppoe {};
|
||||
preinit = callPackage ./preinit {};
|
||||
|
|
3
pkgs/output-template/Makefile
Normal file
3
pkgs/output-template/Makefile
Normal file
|
@ -0,0 +1,3 @@
|
|||
check:
|
||||
./output-template ./example-output/ '{{' '}}' < example.ini > output
|
||||
diff -u output example.ini.expected
|
34
pkgs/output-template/default.nix
Normal file
34
pkgs/output-template/default.nix
Normal file
|
@ -0,0 +1,34 @@
|
|||
{
|
||||
fetchurl,
|
||||
writeFennel,
|
||||
fennel,
|
||||
runCommand,
|
||||
lua,
|
||||
anoia,
|
||||
linotify,
|
||||
lualinux,
|
||||
stdenv
|
||||
}:
|
||||
let name = "output-template";
|
||||
in stdenv.mkDerivation {
|
||||
inherit name;
|
||||
src = ./.;
|
||||
|
||||
buildInputs = [lua];
|
||||
doCheck = true;
|
||||
|
||||
buildPhase = ''
|
||||
cp -p ${writeFennel name {
|
||||
packages = [
|
||||
anoia
|
||||
lualinux
|
||||
linotify
|
||||
] ;
|
||||
mainFunction = "run";
|
||||
} ./output-template.fnl } ${name}
|
||||
'';
|
||||
checkPhase = "make check";
|
||||
installPhase = ''
|
||||
install -D ${name} $out/bin/${name}
|
||||
'';
|
||||
}
|
|
@ -0,0 +1 @@
|
|||
a11
|
|
@ -0,0 +1 @@
|
|||
a33
|
|
@ -0,0 +1 @@
|
|||
a55
|
|
@ -0,0 +1 @@
|
|||
a66
|
1
pkgs/output-template/example-output/colours/black
Normal file
1
pkgs/output-template/example-output/colours/black
Normal file
|
@ -0,0 +1 @@
|
|||
000000
|
1
pkgs/output-template/example-output/colours/blue
Normal file
1
pkgs/output-template/example-output/colours/blue
Normal file
|
@ -0,0 +1 @@
|
|||
0000ff
|
1
pkgs/output-template/example-output/colours/green
Normal file
1
pkgs/output-template/example-output/colours/green
Normal file
|
@ -0,0 +1 @@
|
|||
00ff00
|
1
pkgs/output-template/example-output/colours/red
Normal file
1
pkgs/output-template/example-output/colours/red
Normal file
|
@ -0,0 +1 @@
|
|||
ff0000
|
1
pkgs/output-template/example-output/name
Normal file
1
pkgs/output-template/example-output/name
Normal file
|
@ -0,0 +1 @@
|
|||
eth1
|
2
pkgs/output-template/example.ini
Normal file
2
pkgs/output-template/example.ini
Normal file
|
@ -0,0 +1,2 @@
|
|||
wpa_passphrase={{ secret "colours/black" }}
|
||||
think = {{ string.format("%q", secret("colours/blue")) }}
|
2
pkgs/output-template/example.ini.expected
Normal file
2
pkgs/output-template/example.ini.expected
Normal file
|
@ -0,0 +1,2 @@
|
|||
wpa_passphrase=000000
|
||||
think = "0000ff"
|
22
pkgs/output-template/output-template.fnl
Normal file
22
pkgs/output-template/output-template.fnl
Normal file
|
@ -0,0 +1,22 @@
|
|||
(local svc (require :anoia.svc))
|
||||
|
||||
(fn substitute [text service opening closing]
|
||||
(let [delim (.. opening "(.-)" closing)
|
||||
myenv {
|
||||
: string
|
||||
:secret (fn [x] (service:output x))
|
||||
:lua_quote #(string.format "%q" %1)
|
||||
}]
|
||||
(string.gsub text delim
|
||||
(fn [x]
|
||||
(assert ((load (.. "return " x) x :t myenv))
|
||||
(string.format "missing value for %q" x))))))
|
||||
|
||||
(fn run []
|
||||
(let [[service-dir opening closing] arg
|
||||
service (assert (svc.open service-dir))
|
||||
out (substitute (: (io.input) :read "*a") service opening closing)]
|
||||
(io.write out)))
|
||||
|
||||
|
||||
{ : run }
|
Loading…
Reference in a new issue