diff --git a/README.md b/README.md index 4f95e22..68c2747 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,7 @@ use the `devshellModule` for easy integration, see the docs for more. - **`derivation`**: Use existing Nix derivations as file content - **`gomplate`**: Advanced Go template rendering via gomplate - **`jinja`**: Python Jinja2 template rendering +- **`mustache`**: Mustache template rendering ## Docs diff --git a/docs/index.md b/docs/index.md index 5d45fe9..7576c2f 100644 --- a/docs/index.md +++ b/docs/index.md @@ -21,6 +21,7 @@ Soonix helps you: - **derivation**: Use existing Nix derivations as file content - **gomplate**: Advanced Go template rendering via gomplate - **jinja**: Python Jinja2 template rendering +- **mustache**: Mustache template rendering ### Automatic File Management diff --git a/lib/lib.nix b/lib/lib.nix index 8bcfff9..3e6005d 100644 --- a/lib/lib.nix +++ b/lib/lib.nix @@ -100,6 +100,21 @@ } '' python ${renderScript} > $out ''; + + mustache = { + name, + opts, + data, + }: let + inherit (opts) template; + mustache = opts.mustache or pkgs.mustache-go; + dataJson = writeText "template-data.json" (builtins.toJSON data); + in + runCommand name { + buildInputs = [mustache]; + } '' + mustache ${dataJson} ${template} > $out + ''; }; buildAllFiles = files: diff --git a/lib/module.nix b/lib/module.nix index 53017d9..98400e3 100644 --- a/lib/module.nix +++ b/lib/module.nix @@ -30,7 +30,7 @@ in { }; generator = mkOption { - type = types.enum ["nix" "string" "derivation" "gomplate" "jinja" "template"]; + type = types.enum ["nix" "string" "derivation" "gomplate" "jinja" "mustache" "template"]; description = '' Which engine to use for content generation. ''; diff --git a/tests/fixtures/mustache_template b/tests/fixtures/mustache_template new file mode 100644 index 0000000..a4d8ee1 --- /dev/null +++ b/tests/fixtures/mustache_template @@ -0,0 +1 @@ +Hello {{hello}} diff --git a/tests/soonix_test.nix b/tests/soonix_test.nix index 8198e4b..0cfa1b8 100644 --- a/tests/soonix_test.nix +++ b/tests/soonix_test.nix @@ -30,6 +30,12 @@ data.hello = "world"; opts.template = ./fixtures/jinja_template; }; + mustache = { + output = "mustache"; + generator = "mustache"; + data.hello = "world"; + opts.template = ./fixtures/mustache_template; + }; }; in { suites."Soonix Tests" = { @@ -53,6 +59,9 @@ in { assert "-f ${finalFiles}/jinja" "should exist" assert_file_contains ${finalFiles}/jinja "Hello world" + + assert "-f ${finalFiles}/mustache" "should exist" + assert_file_contains ${finalFiles}/mustache "Hello world" ''; } {