feat: automatically populate meta from env variables if they have a desc

This commit is contained in:
technofab 2025-09-15 15:37:32 +02:00
parent 41547462fb
commit 1ecf4d461d
No known key found for this signature in database

View file

@ -4,7 +4,18 @@
config,
...
}: let
inherit (lib) filter assertMsg head length escapeShellArg types mkOption concatStringsSep;
inherit
(lib)
filter
filterAttrs
assertMsg
head
length
escapeShellArg
types
mkOption
concatStringsSep
;
envToBash = {
name,
@ -37,7 +48,11 @@
then ''unset ${name}''
else throw "[devshell] BUG in the env module. This should never be reached.";
envType = types.submodule ({name, ...}: {
envType = types.submodule ({
config,
name,
...
}: {
options = {
name = mkOption {
type = types.str;
@ -46,7 +61,7 @@
Name of the environment variable, usually already set to `<name>`.
'';
};
desc = mkOption {
description = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
@ -55,7 +70,7 @@
};
visible = mkOption {
type = types.bool;
default = true;
default = config.description != null;
description = ''
Whether to include this env var and it's description in the menu.
'';
@ -120,16 +135,12 @@ in {
env = {
"XDG_DATA_DIRS".eval = "$DEVSHELL_DIR/share:\${XDG_DATA_DIRS-}";
};
enterShellCommands."env".text = concatStringsSep "\n" (map envToBash (builtins.attrValues config.env));
# TODO: collect all env vars, then add them to the menu if they have a description and "visibile == true"
meta = {
sections."Environment Variables".color = "red";
entries."XDG_DATA_DIRS" = {
description = "Hello world";
section = "Environment Variables";
subEntries."Usage" = "hello world";
};
};
enterShellCommands."env".text =
concatStringsSep "\n" (map envToBash (builtins.attrValues config.env));
# meta entries for the menu
meta.entries = builtins.mapAttrs (_name: env: {
inherit (env) description;
section = "Environment Variables";
}) (filterAttrs (_name: env: env.visible) config.env);
};
}