Skip to content

Commit a24d517

Browse files
authored
Merge pull request #890 from mmlb/add-scripts.script.description
Add description to script
2 parents a7c4dd8 + 0794e17 commit a24d517

File tree

3 files changed

+61
-3
lines changed

3 files changed

+61
-3
lines changed

docs/scripts.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,3 +57,42 @@ Entering shell ...
5757
"foo": "1"
5858
}
5959
```
60+
61+
Scripts can also have an optional description, which can be useful in your `enterShell`.
62+
63+
```nix title="devenv.nix"
64+
{ pkgs, config, lib, ... }:
65+
66+
{
67+
packages = [ pkgs.curl pkgs.jq ];
68+
69+
scripts.silly-example.exec = ''curl "https://httpbin.org/get?$1" | jq .args'';
70+
scripts.silly-example.description = "curls httpbin with provided arg";
71+
72+
scripts.serious-example.exec = ''${pkgs.cowsay}/bin/cowsay "$*"'';
73+
scripts.serious-example.description = ''echoes args in a very serious manner'';
74+
75+
enterShell = ''
76+
echo
77+
echo 🦾 Helper scripts you can run to make your development richer:
78+
echo 🦾
79+
${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e 's|^|🦾 |' -e 's|••| |g'
80+
${lib.generators.toKeyValue {} (lib.mapAttrs (name: value: value.description) config.scripts)}
81+
EOF
82+
echo
83+
'';
84+
}
85+
```
86+
87+
```shell-session
88+
$ devenv shell
89+
Building shell ...
90+
Entering shell ...
91+
92+
🦾 Helper scripts you can run to make your development richer:
93+
🦾
94+
🦾 serious-example echoes args in a very serious manner
95+
🦾 silly-example curls httpbin with provided arg
96+
97+
(devenv) $
98+
```

examples/scripts/devenv.nix

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,21 @@
1-
{ pkgs, ... }:
1+
{ config, lib, pkgs, ... }:
22

33
{
4-
scripts."gitversion".exec = ''
5-
echo hello $(${pkgs.git}/bin/git --version)
4+
packages = [ pkgs.curl pkgs.jq ];
5+
6+
scripts.silly-example.exec = ''curl "https://httpbin.org/get?$1" | jq .args'';
7+
scripts.silly-example.description = "curls httpbin with provided arg";
8+
9+
scripts.serious-example.exec = ''${pkgs.cowsay}/bin/cowsay "$*"'';
10+
scripts.serious-example.description = ''echoes args in a very serious manner'';
11+
12+
enterShell = ''
13+
echo
14+
echo 🦾 Helper scripts you can run to make your development richer:
15+
echo 🦾
16+
${pkgs.gnused}/bin/sed -e 's| |••|g' -e 's|=| |' <<EOF | ${pkgs.util-linuxMinimal}/bin/column -t | ${pkgs.gnused}/bin/sed -e 's|^|🦾 |' -e 's|••| |g'
17+
${lib.generators.toKeyValue {} (lib.mapAttrs (name: value: value.description) config.scripts)}
18+
EOF
19+
echo
620
'';
721
}

src/modules/scripts.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,11 @@ let
88
type = types.str;
99
description = "Bash code to execute when the script is run.";
1010
};
11+
description = lib.mkOption {
12+
type = types.str;
13+
description = "Description of the script.";
14+
default = "";
15+
};
1116
};
1217
});
1318
# lib.hiPrioSet: prioritize scripts over plain packages

0 commit comments

Comments
 (0)