Skip to content

Add #flakeModules.flakeModulesSansAlias#285

Open
mightyiam wants to merge 1 commit intohercules-ci:mainfrom
mightyiam:safe-flake-module-alias
Open

Add #flakeModules.flakeModulesSansAlias#285
mightyiam wants to merge 1 commit intohercules-ci:mainfrom
mightyiam:safe-flake-module-alias

Conversation

@mightyiam
Copy link
Contributor

Importing flakeModules.flakeModules
results in an always-failing nix flake check.

This seems to be because it adds a value to
flake.flakeModules.flakeModule that ends up as a flake output that
fails to evaluate with the error:

Renaming error: option `flakeModules.default' does not exist.

@roberth
Copy link
Member

roberth commented May 15, 2025

That would be caused by

(mkAliasOptionModule [ "flakeModule" ] [ "flakeModules" "default" ])

To solve this problem, we'd have to either make that behavior optional, or remove it entirely.
By making it optional in an automatic way, we'll introduce an infinite recursion when accessing self.outPath (or self itself, any attr) from within a flakeModules definition, breaking directory-based autodiscovery solutions.
By removing it, we cause trouble for users who import flakeModule, as it will disappear without an error message that tells them what to do.

The only solution is see is to add an option like enableFlakeModuleAlias so that you can disable that attr in your flake.
Or split the module into a new one that declares flakeModules and another that imports the new one and adds the alias. Then you can import the new module without the alias.

@mightyiam
Copy link
Contributor Author

Split module sounds 🏆 to me.

@mightyiam mightyiam force-pushed the safe-flake-module-alias branch from 69073d6 to 267e2ee Compare May 16, 2025 16:18
@mightyiam
Copy link
Contributor Author

Could use some help here:

$ nix flake check
error:
       … while checking flake output 'checks'

       … while checking the derivation 'checks.x86_64-linux.eval-tests'

       … while evaluating the attribute 'optionalValue.value'
         at /nix/store/80jiav8nl8hsx2sf4miaihfacajn1i5h-source/lib/modules.nix:974:5:
          973|
          974|     optionalValue =
             |     ^
          975|       if isDefined then { value = mergedValue; }

       … while evaluating definitions from `/nix/store/2g82mhkbp6cdnc33mag8cvmxxy8afcfr-source/extras/partitions.nix':

       … while evaluating definitions from `/nix/store/2g82mhkbp6cdnc33mag8cvmxxy8afcfr-source/modules/transposition.nix':

       … while evaluating definitions from `/nix/store/2g82mhkbp6cdnc33mag8cvmxxy8afcfr-source/dev/flake-module.nix, via option partitions.dev.module.perSystem':

       (stack trace truncated; use '--show-trace' to show the full, detailed trace)

       error: Module `/nix/store/2g82mhkbp6cdnc33mag8cvmxxy8afcfr-source/dev/tests/eval-tests.nix` contains a disabledModules item that is an attribute set, presumably a module, that does not have a `key` attribute. This means that the module system doesn't have any means to identify the module that should be disabled. Make sure that you've put the correct value in disabledModules: a string path relative to modulesPath, a path value, or an attribute set with a `key` attribute.

Which module is it that is missing a key and what is the change that causes this? I could grind against this some more but it's bed time.

@mightyiam mightyiam force-pushed the safe-flake-module-alias branch from 267e2ee to 0d0375f Compare May 17, 2025 13:56
@mightyiam mightyiam force-pushed the safe-flake-module-alias branch from 0d0375f to b9111fd Compare May 17, 2025 14:01
@mightyiam mightyiam changed the title flakeModules causes nix flake check to fail Add #flakeModules.flakeModulesSansAlias May 17, 2025
@mightyiam mightyiam changed the title Add #flakeModules.flakeModulesSansAlias Add #flakeModules.flakeModulesSansAlias May 17, 2025
@mightyiam mightyiam marked this pull request as ready for review May 17, 2025 14:02
@mightyiam
Copy link
Contributor Author

flake.parts fails to build with this, claiming this input has no options to render.

@roberth
Copy link
Member

roberth commented Jun 2, 2025

Thank you for writing this.

Unfortunately I believe I've thought within the framework of the module system too much.
Dogfooding is still a UX issue, and I think it's worth solving monolithically in evalFlakeModule. A solution there would make this module obsolete.

I'm also leaning towards migrating to modules.flake.<name>, as modules.<class>.<name> is, in a larger context, a more flexible, cleaner place for such attributes.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants