Skip to content

Instantly share code, notes, and snippets.

@yunfachi
Created August 26, 2025 18:32
Show Gist options
  • Select an option

  • Save yunfachi/c38e0fe9ccdcb8c9ac6ad55094c9d815 to your computer and use it in GitHub Desktop.

Select an option

Save yunfachi/c38e0fe9ccdcb8c9ac6ad55094c9d815 to your computer and use it in GitHub Desktop.
strange behavior of the config argument in submodule modules when using apply
(import <nixpkgs/lib>).evalModules {
modules = [
(
{ lib, ... }:
{
options = {
someOption = lib.mkOption {
default = {
foo = { };
};
apply = xs: builtins.mapAttrs (name: x: x // { inherit name; }) xs;
type = lib.types.attrsOf (
lib.types.submodule (
{ config, ... }:
{
options = {
name = lib.mkOption {
type = lib.types.str;
default = "defaultName";
};
nameClone = lib.mkOption {
type = lib.types.str;
default = config.name;
};
};
}
)
);
};
};
}
)
];
}
nix eval -f ./default.nix config
@yunfachi
Copy link
Author

Actually, apply didn't run on the input module but on the output value, the result of evalModules… I should have guessed that. And to solve this, there's already a builtin name argument in submodules inside attrsOf

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment