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, 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";
};
};
}; };
} }