summaryrefslogtreecommitdiff
path: root/lib/template.nix
blob: 5beb22a00311b19cdb1d1d7774b0c487079a636a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{
  lib,
  pkgs,
}: {
  mustache = templateFile: data: let
    fileName = baseNameOf templateFile;
    drvName = lib.strings.removeSuffix ".mustache" fileName;
  in
    pkgs.stdenv.mkDerivation {
      name = drvName;
      nativeBuildInputs = with pkgs; [mustache-go];

      passAsFile = ["jsonData"];
      jsonData = builtins.toJSON data;

      dontUnpack = true;

      buildPhase = ''
        mustache "$jsonDataPath" "${templateFile}" > rendered_config
      '';

      installPhase = ''
        cp rendered_config $out
      '';
    };
}