Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 22 additions & 1 deletion projects/jaq/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,26 @@
};
};

# no service module as this is strictly a program
nixos.demo.shell = {
module = ./programs/jaq/examples/basic.nix;
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;
};
}
5 changes: 5 additions & 0 deletions projects/jaq/programs/jaq/module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,10 @@ in
environment.systemPackages = with pkgs; [
cfg.package
];
demo-shell.jaq = {
programs = {
jaq = cfg.package;
};
};
};
}
34 changes: 34 additions & 0 deletions projects/jaq/programs/jaq/tests/shell.nix
Original file line number Diff line number Diff line change
@@ -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')
'';
}