Skip to content

Commit

Permalink
feat: devshell.menu.interpolate option
Browse files Browse the repository at this point in the history
  • Loading branch information
deemp committed Jan 14, 2024
1 parent d45f45b commit b395c41
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 1 deletion.
2 changes: 1 addition & 1 deletion modules/commands.nix
Original file line number Diff line number Diff line change
Expand Up @@ -178,7 +178,7 @@ in
help = "prints this menu";
name = "menu";
command = ''
cat <<'DEVSHELL_MENU'
cat <<${(x: if config.devshell.menu.interpolate then x else "'${x}'") "DEVSHELL_MENU"}
${commandsToMenu config.commands}
DEVSHELL_MENU
'';
Expand Down
15 changes: 15 additions & 0 deletions modules/devshell.nix
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,21 @@ in
options list (except that the 'name' field is ignored).
'';
};

menu = mkOption {
type = types.submodule {
options.interpolate = mkEnableOption "interpolation in the devshell menu";
};
default = { };
description = ''
Controls devshell menu
'';
example = literalExpression ''
{
interpolate = true;
}
'';
};
};

config.devshell = {
Expand Down
20 changes: 20 additions & 0 deletions tests/extra/devshell.menu.interpolate.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{ pkgs, devshell, runTest }:
{
interpolate =
let
shell = devshell.mkShell {
devshell.menu.interpolate = true;
commands = [
{ package = "hello"; help = "hello from '$PRJ_ROOT'!"; }
{ package = "jq"; help = ''jq from '\$PRJ_ROOT'!''; }
];
};
in
runTest "interpolate" { } ''
# Check interpolation is enabled
cat ${shell}/bin/menu | grep '<<DEVSHELL_MENU'
# Check escaped variable
eval ${shell}/bin/menu | grep '\$PRJ_ROOT'
'';
}

0 comments on commit b395c41

Please sign in to comment.