|
5 | 5 | }:
|
6 | 6 |
|
7 | 7 | {
|
| 8 | + # Top-level packages to the shell |
8 | 9 | packages = [
|
9 |
| - pkgs.curl |
10 | 10 | pkgs.jq
|
11 | 11 | ];
|
12 | 12 |
|
13 |
| - scripts.silly-example.exec = ''curl "https://httpbin.org/get?$1" | jq .args''; |
14 |
| - scripts.silly-example.description = "curls httpbin with provided arg"; |
| 13 | + # Scripts have access to the top-level `packages` |
| 14 | + scripts.silly-example.exec = ''echo "{\"name\":\"$1\",\"greeting\":\"Hello $1!\",\"timestamp\":\"$(date -Iseconds)\"}" | jq ''; |
| 15 | + scripts.silly-example.description = "creates JSON with provided arg and shows it with jq"; |
15 | 16 |
|
16 |
| - scripts.serious-example.exec = ''${pkgs.cowsay}/bin/cowsay "$*"''; |
| 17 | + # Scripts can declare their own private `packages` |
| 18 | + scripts.serious-example.exec = ''cowsay "$*"''; |
| 19 | + scripts.serious-example.packages = [ pkgs.cowsay ]; |
17 | 20 | scripts.serious-example.description = ''echoes args in a very serious manner'';
|
18 | 21 |
|
19 |
| - # Example with custom package |
| 22 | + # Write scripts using your favourite language. |
20 | 23 | scripts.python-hello.exec = ''print("Hello, world!")'';
|
21 |
| - scripts.python-hello.package = pkgs.python311; |
| 24 | + scripts.python-hello.package = pkgs.python3Minimal; |
22 | 25 |
|
23 |
| - # Example when package and binary are different |
| 26 | + # Handle custom scripts where the binary name doesn't match the package name |
24 | 27 | scripts.nushell-greet.exec = ''
|
25 | 28 | def greet [name] {
|
26 | 29 | ["hello" $name]
|
|
31 | 34 | scripts.nushell-greet.package = pkgs.nushell;
|
32 | 35 | scripts.nushell-greet.binary = "nu";
|
33 | 36 |
|
| 37 | + # Render a help section when you enter the shell, similar to `devenv info` |
34 | 38 | enterShell = ''
|
35 | 39 | echo
|
36 | 40 | echo 🦾 Helper scripts you can run to make your development richer:
|
|
40 | 44 | EOF
|
41 | 45 | echo
|
42 | 46 | '';
|
| 47 | + |
| 48 | + # Test that the scripts work as expected with `devenv test` |
| 49 | + enterTest = '' |
| 50 | + echo "Testing silly-example" |
| 51 | + silly-example world | grep Hello |
| 52 | +
|
| 53 | + echo "Testing serious-example" |
| 54 | + serious-example hello world | grep hello |
| 55 | +
|
| 56 | + echo "Testing python-hello" |
| 57 | + python-hello | grep Hello |
| 58 | +
|
| 59 | + echo "Testing nushell-greet" |
| 60 | + nushell-greet | grep hello |
| 61 | + ''; |
43 | 62 | }
|
0 commit comments