mirror of
https://gitlab.com/TECHNOFAB/soonix.git
synced 2026-02-01 23:05:06 +01:00
Compare commits
3 commits
404d8cb782
...
26e79ede19
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
26e79ede19 | ||
| 7e3efd400c | |||
|
|
a8acaf7143 |
8 changed files with 39 additions and 12 deletions
|
|
@ -53,8 +53,9 @@ use the `devshellModule` for easy integration, see the docs for more.
|
|||
- **`nix`**: Convert Nix data to JSON, YAML, TOML, INI, XML formats
|
||||
- **`string`**: Output raw string content with optional executable permissions
|
||||
- **`derivation`**: Use existing Nix derivations as file content
|
||||
- **`gotmpl`**: Advanced Go template rendering via gomplate
|
||||
- **`gomplate`**: Advanced Go template rendering via gomplate
|
||||
- **`jinja`**: Python Jinja2 template rendering
|
||||
- **`mustache`**: Mustache template rendering
|
||||
|
||||
## Docs
|
||||
|
||||
|
|
|
|||
|
|
@ -19,8 +19,9 @@ Soonix helps you:
|
|||
- **nix**: Convert Nix data to JSON, YAML, TOML, INI, XML formats
|
||||
- **string**: Output raw string content with optional executable permissions
|
||||
- **derivation**: Use existing Nix derivations as file content
|
||||
- **gotmpl**: Advanced Go template rendering via gomplate
|
||||
- **gomplate**: Advanced Go template rendering via gomplate
|
||||
- **jinja**: Python Jinja2 template rendering
|
||||
- **mustache**: Mustache template rendering
|
||||
|
||||
### Automatic File Management
|
||||
|
||||
|
|
@ -63,7 +64,7 @@ Automatically manage .gitignore entries for generated files to keep your reposit
|
|||
|
||||
dockerfile = {
|
||||
output = "Dockerfile";
|
||||
generator = "gotmpl";
|
||||
generator = "gomplate";
|
||||
data = {
|
||||
baseImage = "node:18-alpine";
|
||||
port = 3000;
|
||||
|
|
|
|||
|
|
@ -100,7 +100,7 @@ Use Go templates for more complex file generation:
|
|||
hooks = {
|
||||
dockerfile = {
|
||||
output = "Dockerfile";
|
||||
generator = "gotmpl";
|
||||
generator = "gomplate";
|
||||
data = {
|
||||
baseImage = "node:18-alpine";
|
||||
workdir = "/app";
|
||||
|
|
@ -331,7 +331,7 @@ in {
|
|||
hooks = {
|
||||
kubernetes-manifest = {
|
||||
output = "k8s/deployment.yaml";
|
||||
generator = "gotmpl";
|
||||
generator = "gomplate";
|
||||
data = {
|
||||
app = {
|
||||
name = "my-app";
|
||||
|
|
|
|||
17
lib/lib.nix
17
lib/lib.nix
|
|
@ -50,7 +50,7 @@
|
|||
# only a passthru
|
||||
derivation = {data, ...}: data;
|
||||
|
||||
gotmpl = {
|
||||
gomplate = {
|
||||
name,
|
||||
opts,
|
||||
data,
|
||||
|
|
@ -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:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@ in {
|
|||
};
|
||||
|
||||
generator = mkOption {
|
||||
type = types.enum ["nix" "string" "derivation" "gotmpl" "jinja" "template"];
|
||||
type = types.enum ["nix" "string" "derivation" "gomplate" "jinja" "mustache" "template"];
|
||||
description = ''
|
||||
Which engine to use for content generation.
|
||||
'';
|
||||
|
|
|
|||
1
tests/fixtures/mustache_template
vendored
Normal file
1
tests/fixtures/mustache_template
vendored
Normal file
|
|
@ -0,0 +1 @@
|
|||
Hello {{hello}}
|
||||
|
|
@ -19,10 +19,10 @@
|
|||
};
|
||||
};
|
||||
gomplate = {
|
||||
output = "gotmpl";
|
||||
generator = "gotmpl";
|
||||
output = "gomplate";
|
||||
generator = "gomplate";
|
||||
data.hello = "world";
|
||||
opts.template = ./fixtures/gotmpl_template;
|
||||
opts.template = ./fixtures/gomplate_template;
|
||||
};
|
||||
jinja = {
|
||||
output = "jinja";
|
||||
|
|
@ -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" = {
|
||||
|
|
@ -48,11 +54,14 @@ in {
|
|||
assert "-f ${finalFiles}/out/test.json" "should exist"
|
||||
assert_file_contains ${finalFiles}/out/test.json "soonix-test"
|
||||
|
||||
assert "-f ${finalFiles}/gotmpl" "should exist"
|
||||
assert_file_contains ${finalFiles}/gotmpl "Hello world"
|
||||
assert "-f ${finalFiles}/gomplate" "should exist"
|
||||
assert_file_contains ${finalFiles}/gomplate "Hello world"
|
||||
|
||||
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"
|
||||
'';
|
||||
}
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue