From e3a37d5f891818a6b70583186b672db8811bfb59 Mon Sep 17 00:00:00 2001 From: Ethan Carter Edwards Date: Mon, 7 Jul 2025 18:11:18 -0400 Subject: [PATCH 1/2] projects/jaq: add a demo Signed-off-by: Ethan Carter Edwards --- projects/jaq/default.nix | 6 +++- projects/jaq/programs/jaq/module.nix | 5 ++++ projects/jaq/programs/jaq/tests/shell.nix | 34 +++++++++++++++++++++++ 3 files changed, 44 insertions(+), 1 deletion(-) create mode 100644 projects/jaq/programs/jaq/tests/shell.nix diff --git a/projects/jaq/default.nix b/projects/jaq/default.nix index 134d6b2b4..4700763f4 100644 --- a/projects/jaq/default.nix +++ b/projects/jaq/default.nix @@ -26,5 +26,9 @@ }; }; - # no service module as this is strictly a program + nixos.demo.shell = { + module = ./programs/jaq/examples/basic.nix; + description = "jaq example"; + tests.basic.module = import ./programs/jaq/tests/shell.nix args; + }; } diff --git a/projects/jaq/programs/jaq/module.nix b/projects/jaq/programs/jaq/module.nix index 387291a1c..325428cb4 100644 --- a/projects/jaq/programs/jaq/module.nix +++ b/projects/jaq/programs/jaq/module.nix @@ -17,5 +17,10 @@ in environment.systemPackages = with pkgs; [ cfg.package ]; + demo-shell.jaq = { + programs = { + jaq = cfg.package; + }; + }; }; } diff --git a/projects/jaq/programs/jaq/tests/shell.nix b/projects/jaq/programs/jaq/tests/shell.nix new file mode 100644 index 000000000..e3c5c2306 --- /dev/null +++ b/projects/jaq/programs/jaq/tests/shell.nix @@ -0,0 +1,34 @@ +{ + sources, + ... +}: +{ + name = "jaq demo"; + + nodes = { + machine = + { pkgs, ... }: + { + imports = [ + sources.modules.ngipkgs + sources.modules.programs.jaq + sources.examples.jaq.basic + ]; + }; + }; + + testScript = + { nodes, ... }: + '' + start_all() + + # checking if 1 + 2 == 3. + machine.succeed('[ "$(echo \'{"a": 1, "b": 2}\' | jaq \'add\')" -eq 3 ]') + + # echo out 0-3, map over them multiplying by 2, keep all elements under 5, add the results up together. Should be 6 + machine.succeed('[ "$(echo \'[0, 1, 2, 3]\' | jaq \'map(.*2) | [.[] | select(. < 5)] | add\')" -eq 6 ]') + + # fail on malformed input + machine.fail('echo "0, 1, 4, " | jaq') + ''; +} From 6eaf6d99ffbdb1ba84bf965a82bfac8ef566cbb9 Mon Sep 17 00:00:00 2001 From: Ethan Carter Edwards Date: Tue, 8 Jul 2025 14:03:37 -0400 Subject: [PATCH 2/2] projects/jaq: add full description Signed-off-by: Ethan Carter Edwards --- projects/jaq/default.nix | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/projects/jaq/default.nix b/projects/jaq/default.nix index 4700763f4..150d10506 100644 --- a/projects/jaq/default.nix +++ b/projects/jaq/default.nix @@ -28,7 +28,24 @@ nixos.demo.shell = { module = ./programs/jaq/examples/basic.nix; - description = "jaq example"; + description = '' + A demo shell for testing jaq, a data wrangling tool with formal semantics similar to jq. + + Let's get a basic understanding of jaq's capabilities: + + Here, we can pass in a set or object full of numbers and have jaq add them together. + + $ echo '{"a": 1, "b": 2}' | jaq 'add' # equal to 3 + + We can also do more complicated operations like mapping over a list and using conditionals: + + $ echo '[0, 1, 2, 3]' | jaq 'map(.*2) | [.[] | select(. < 5)] | add' # equal to 6 + + Finally, jaq will fail if any malformed input is passed + + $ echo "0, 1, 4, " | jaq + ''; + tests.basic.module = import ./programs/jaq/tests/shell.nix args; }; }