mirror of
https://gitlab.com/rensa-nix/devshell.git
synced 2025-12-11 22:00:08 +01:00
feat: automatically populate meta from env variables if they have a desc
This commit is contained in:
parent
41547462fb
commit
1ecf4d461d
1 changed files with 26 additions and 15 deletions
|
|
@ -4,7 +4,18 @@
|
||||||
config,
|
config,
|
||||||
...
|
...
|
||||||
}: let
|
}: let
|
||||||
inherit (lib) filter assertMsg head length escapeShellArg types mkOption concatStringsSep;
|
inherit
|
||||||
|
(lib)
|
||||||
|
filter
|
||||||
|
filterAttrs
|
||||||
|
assertMsg
|
||||||
|
head
|
||||||
|
length
|
||||||
|
escapeShellArg
|
||||||
|
types
|
||||||
|
mkOption
|
||||||
|
concatStringsSep
|
||||||
|
;
|
||||||
|
|
||||||
envToBash = {
|
envToBash = {
|
||||||
name,
|
name,
|
||||||
|
|
@ -37,7 +48,11 @@
|
||||||
then ''unset ${name}''
|
then ''unset ${name}''
|
||||||
else throw "[devshell] BUG in the env module. This should never be reached.";
|
else throw "[devshell] BUG in the env module. This should never be reached.";
|
||||||
|
|
||||||
envType = types.submodule ({name, ...}: {
|
envType = types.submodule ({
|
||||||
|
config,
|
||||||
|
name,
|
||||||
|
...
|
||||||
|
}: {
|
||||||
options = {
|
options = {
|
||||||
name = mkOption {
|
name = mkOption {
|
||||||
type = types.str;
|
type = types.str;
|
||||||
|
|
@ -46,7 +61,7 @@
|
||||||
Name of the environment variable, usually already set to `<name>`.
|
Name of the environment variable, usually already set to `<name>`.
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
desc = mkOption {
|
description = mkOption {
|
||||||
type = types.nullOr types.str;
|
type = types.nullOr types.str;
|
||||||
default = null;
|
default = null;
|
||||||
description = ''
|
description = ''
|
||||||
|
|
@ -55,7 +70,7 @@
|
||||||
};
|
};
|
||||||
visible = mkOption {
|
visible = mkOption {
|
||||||
type = types.bool;
|
type = types.bool;
|
||||||
default = true;
|
default = config.description != null;
|
||||||
description = ''
|
description = ''
|
||||||
Whether to include this env var and it's description in the menu.
|
Whether to include this env var and it's description in the menu.
|
||||||
'';
|
'';
|
||||||
|
|
@ -120,16 +135,12 @@ in {
|
||||||
env = {
|
env = {
|
||||||
"XDG_DATA_DIRS".eval = "$DEVSHELL_DIR/share:\${XDG_DATA_DIRS-}";
|
"XDG_DATA_DIRS".eval = "$DEVSHELL_DIR/share:\${XDG_DATA_DIRS-}";
|
||||||
};
|
};
|
||||||
enterShellCommands."env".text = concatStringsSep "\n" (map envToBash (builtins.attrValues config.env));
|
enterShellCommands."env".text =
|
||||||
# TODO: collect all env vars, then add them to the menu if they have a description and "visibile == true"
|
concatStringsSep "\n" (map envToBash (builtins.attrValues config.env));
|
||||||
|
# meta entries for the menu
|
||||||
meta = {
|
meta.entries = builtins.mapAttrs (_name: env: {
|
||||||
sections."Environment Variables".color = "red";
|
inherit (env) description;
|
||||||
entries."XDG_DATA_DIRS" = {
|
section = "Environment Variables";
|
||||||
description = "Hello world";
|
}) (filterAttrs (_name: env: env.visible) config.env);
|
||||||
section = "Environment Variables";
|
|
||||||
subEntries."Usage" = "hello world";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue