8000 feat: add support for nix.conf include directives by vilhelmbergsoe · Pull Request #681 · cachix/cachix · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for nix.conf include directives #681

Merged
merged 15 commits into from
Jan 16, 2025

Conversation

vilhelmbergsoe
Copy link
Contributor
@vilhelmbergsoe vilhelmbergsoe commented Jan 10, 2025

Implement parsing and resolution of include/!include directives in nix.conf files to support setups like determinate nix installer that split configs across multiple files.

Key features:

  • Support both required (include) and optional (!include) directives
  • Detect and prevent circular includes

Implementation details:

Following the nix.conf specification:

  • Required includes (include) error if file not found
  • Optional includes (!include) continue silently if file missing
  • Circular includes are detected, with a stack trace showing the include chain, example:
Circular include detected:
/path/to/nix.conf
    -> includes /path/to/nix.custom.conf
    -> includes /path/to/nix.conf (circular reference)
  • Optional includes that would create a circular reference are skipped silently
  • All paths are resolved relative to the including file

This allows Cachix to properly read trusted-users and other settings from included config files.


I'm new to Haskell, so I'd really appreciate feedback on the implementation approach. Happy to adjust based on your input!

Related issue: #680

Implement parsing and resolution of include/!include directives in nix.conf
files to support setups like determinate nix installer that split configs
across multiple files.

Key features:
- Support both required (include) and optional (!include) directives
- Detect and prevent circular includes
- Resolve paths relative to including file
- Maintain existing error handling patterns

This allows Cachix to properly read trusted-users and other settings from
included config files.
@vilhelmbergsoe vilhelmbergsoe force-pushed the include-directive-support branch from c1ce54b to f866fde Compare January 10, 2025 09:15
@sandydoo
Copy link
Member
sandydoo commented Jan 15, 2025

The parsing bits look good to me. I added tests for those and ran the formatters over the code. There are still some minor issues with variable shadowing.

The main problem is the write-back function. If we flatten all of the includes into a single NixConf, then we'll mangle the config when writing it back.

I haven't given this much thought yet. Perhaps we should use our own include for stuff that needs to be written to the config.

@vilhelmbergsoe
Copy link
Contributor Author
vilhelmbergsoe commented Jan 15, 2025

Thanks for giving this a view!

If I understand correctly, the write function is only used for writing our own configuration changes, not modifying the user's existing config files. In that case, flattening should be fine since we're not trying to preserve/modify the original include structure.

Would you confirm that's the intended behavior of the write function? If so, I think the current flattening approach should work well for our needs.

Questions I have:

  1. What's the primary purpose of the write-back functionality? (I'm expecting this to just be configuring subtituters)
  2. Which config file locations are we expecting to read from vs write to?
  3. Are there cases where we need to preserve the original include structure?

@grahamc
Copy link
grahamc commented Jan 15, 2025

[moved to #680, since that is the overall issue]

@sandydoo
Copy link
Member

If I understand correctly, the write function is only used for writing our own configuration changes, not modifying the user's existing config files.

It very much modifies the existing config files in-place.

I've worked out an interim solution for the writes: https://github.com/cachix/cachix/compare/nix-conf-fix?expand=1

@domenkozar and I will review tomorrow morning (it's quite late here), likely apply the above changes on top, and start propagating a release.

@sandydoo sandydoo added the bug Something isn't working label Jan 16, 2025
@sandydoo sandydoo marked this pull request as ready for review January 16, 2025 16:36
@sandydoo sandydoo merged commit 06259af into cachix:master Jan 16, 2025
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants
0