Skip to content

Set key for modules and nixosModules#251

Open
Atry wants to merge 5 commits intohercules-ci:mainfrom
Atry:key
Open

Set key for modules and nixosModules#251
Atry wants to merge 5 commits intohercules-ci:mainfrom
Atry:key

Conversation

@Atry
Copy link
Copy Markdown
Contributor

@Atry Atry commented Sep 12, 2024

@roberth
Copy link
Copy Markdown
Member

roberth commented Sep 13, 2024

I'm slightly concerned about overridden inputs not being represented in the key, but this may be the lesser evil of the two.

Copy link
Copy Markdown
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Probably best to implement it anyway.

Copy link
Copy Markdown
Member

@roberth roberth left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Coming to think of it, since we have this logic in two places now, it should be factored out, and since we're enabling new behavior, we should test it.

Specifically, eval-tests.nix should check that deduplication works (e.g. with a list-typed option that merges by appending, as usual), and that disabledModules works.

I won't have time for it in the coming days, so feel free to give it a shot.

Atry and others added 3 commits October 8, 2024 22:15
@liarokapisv
Copy link
Copy Markdown

Hi there, can I help push this PR forward somehow?

@Atry
Copy link
Copy Markdown
Contributor Author

Atry commented Nov 19, 2025

Hi there, can I help push this PR forward somehow?

Feel free to hack on this

@liarokapisv
Copy link
Copy Markdown

liarokapisv commented Nov 20, 2025

@roberth Can't we use

inputsHash = builtins.hashString "sha256" (                                                                                                    
     builtins.toJSON (builtins.mapAttrs (_: v: v.outPath) self.inputs)                                                                          
);     

to also pin the inputs for the key?

@roberth
Copy link
Copy Markdown
Member

roberth commented Nov 20, 2025

It's not known which inputs and which transitive inputs matter to the behavior of the module, so that's still a heuristic, and a potentially costly one because you're also fetching inputs that may otherwise not be fetched.

I guess the good news is that the problem is still tractable and doesn't require fetching the whole input closure, but we'll have to be more clever about how we model this, and this will require Nix itself to help out a bit.

The behavior of a flake is determined by Nix itself, the lock file plus any overrides.

  • Nix itself: can be ignored, because since the key contents aren't really for external consumption, we only care about the current evaluation, which is run by one Nix
  • The lock file: can be read with outPath + "/flake.lock", unless the lock is edited in memory without using the overrides mechanism in call-flake.nix. We'd have to make sure it always goes through overrides or puts a virtual lock file in that place.
  • The overrides: these are currently not accessible to the flake outputs function. Adding info about overrides is non-trivial and perhaps not something we even want user code to be able to observe. It seems preferable to perform the key computation in call-flake.nix instead, and only expose its value instead of the data that went into it.

I've opened NixOS/nix#14601 in nix so that we can work towards a real solution.

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.

Multiple imports of the same NixOS module not allowed with flake

3 participants