network/nix/lib/salt-support/expand-template.nix

24 lines
476 B
Nix
Raw Normal View History

2021-02-25 01:06:32 +01:00
{ pkgs ? import <nixpkgs> {}
}:
name: template: data:
let
jsonFile =
builtins.toFile "data.json" (builtins.toJSON data);
j2custom =
builtins.toFile "j2custom.py" ''
def j2_environment(env):
env.globals.update(
zip=zip
)
return env
'';
2021-02-25 01:06:32 +01:00
in
pkgs.runCommandLocal name {
nativeBuildInputs = with pkgs; [
pythonPackages.j2cli yaml2json
];
} ''
j2 --customize ${j2custom} -f json ${template} ${jsonFile} > $out
2021-02-25 01:06:32 +01:00
''