Skip to content

Commit c69d401

Browse files
committed
feat: devshell.menu.interpolate option
1 parent d45f45b commit c69d401

File tree

3 files changed

+36
-1
lines changed

3 files changed

+36
-1
lines changed

modules/commands.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -178,7 +178,7 @@ in
178178
help = "prints this menu";
179179
name = "menu";
180180
command = ''
181-
cat <<'DEVSHELL_MENU'
181+
cat <<${(x: if config.devshell.menu.interpolate then x else "'${x}'") "DEVSHELL_MENU"}
182182
${commandsToMenu config.commands}
183183
DEVSHELL_MENU
184184
'';

modules/devshell.nix

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,21 @@ in
345345
options list (except that the 'name' field is ignored).
346346
'';
347347
};
348+
349+
menu = mkOption {
350+
type = types.submodule {
351+
options.interpolate = mkEnableOption "interpolation in the devshell menu";
352+
};
353+
default = { };
354+
description = ''
355+
Controls devshell menu
356+
'';
357+
example = literalExpression ''
358+
{
359+
interpolate = true;
360+
}
361+
'';
362+
};
348363
};
349364

350365
config.devshell = {
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
{ pkgs, devshell, runTest }:
2+
{
3+
interpolate =
4+
let
5+
shell = devshell.mkShell {
6+
devshell.menu.interpolate = true;
7+
commands = [
8+
{ package = "hello"; help = "start at $PRJ_ROOT"; }
9+
{ package = "jq"; help = ''jq from '\$PRJ_ROOT'!''; }
10+
];
11+
};
12+
in
13+
runTest "interpolate" { } ''
14+
# Check interpolation is enabled
15+
cat ${shell}/bin/menu | grep '<<DEVSHELL_MENU'
16+
17+
# Check escaped variable
18+
eval ${shell}/bin/menu | grep '\$PRJ_ROOT'
19+
'';
20+
}

0 commit comments

Comments
 (0)