Skip to content

nix: decouple modules from the flake & drive outputs from required overlay - #214

Open
toastal wants to merge 9 commits into
nlewo:mainfrom
toastal:decoupled-overlay
Open

toastal wants to merge 9 commits into
nlewo:mainfrom
toastal:decoupled-overlay

Conversation

@toastal

@toastal toastal commented Oct 22, 2026

Copy link
Copy Markdown

Motivation:

🤝 Support flake and non-flake repositories

Why not make the project more stable-Nix-friendly too! Currently, the flake is too, dare we say in the age of LLMs, “load-bearing”—especially in the case of stable Nix users, where all they need is an overlay + a module to import. This also now frees up flake = false to be used by flake users that wish to avoid your transitive flake dependencies which are not needed to run: flake-compat, treefmt-nix.

Flakes’ design patterns have introduced some flaws in the Nix code from my viewpoint as a path of less resistance solved by overlay-driven Nix:

  • NixOS/Darwin modules are coupled/stateful to the flake making them not composable (self is curried & unreachable to users) & can’t “just” be imported
  • Assertion null checks in the module to handle this coupling, fallback in the modules that can be simplified by requiring the overlay
  • The overlay being the source of truth means all the code is shared via 1 callPackage that users can override at any time (not just at the module package boundary)
  • That overlay now removes gymnastics for getting comin into packages like lint.nix
  • A separate comin-tools overlay + scope also now remove the rec but also makes it too easier to use even inside the flake
  • Limiting the project to the 4 specified system when actually RISC-V & others can run/build this just fine, & those users will now have access to the bare overlay
  • Stable Nix users needed to download another dependency, flake-compat, just to get access to the flakes’ features, but still required manually assembly, but a decoupled overlay eliminates/simplifies this (compare the rendered “Quick start” using system.nix vs. flake.nix).

Use flakes as thin wrappers over existing Nix code. This way, code can be used in both ways.

— https://nix.dev/concepts/flakes#discoverability

High-level changes

  • create nix/overlay/{default,tools}.nix directory with overlays that now drive the flake (packages, checks)
  • drop { self } from the modules to make them properly composable
    • modules no longer need lib.modules.importApply
    • modules require the comin package, thus dropping asserts, nullability, fallbacks
  • lint.nix is now valid package with callPackage
  • Caught a mislabeled doc file name in the check script
  • Regenerated/updated docs (including a system.nix example which requires no experimental features)

Migration

  • User must now explicitly add the overlay (do not append overlays in NixOS modules for consumers as modules vs. profiles are different concepts (but LLMs have been spitting out this anti-pattern))

This is breaking. But, a lot of the module complexity is hinged on avoiding the overlay. However, the overlay is reducing project complexity while also enabling users more flexibility in how/where to include it & now with the ability to override it since it isn’t baked into self. The overlay was accessible(ish, flake-compat) before, but I believe should have been the only way.

Nothing else is changed from the user or developer standpoint (flake packages still the same names). nix --extra-experimental-features flakes flake check still passes. Patchset here can be read by commit. If only some ideas are good, feel free to cherrypick.

1

Footnotes

  1. Please consider giving up MS GitHub or offering a non-proprietary, non-US-corporate-controlled mirror for this free software project. I wish to delete this Microsoft account in the future, but I need more projects like this to support alternative methods to send patches & contribute. ↩

this is what a required overlay fixes & removes a lot of switches
& prefer it since no experimental features are required. `tar.zst` would
be better for the Nixpkgs fetch example but Zstandard support isn’t in
all Nix version.

```nix
"pkgs.comin or comin.packages.\${system}.default or null"
pkgs.comin

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Do you think it would be possible to add a message at eval time explaining the overlay is now required?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

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

Probably with the warning or assertion systems

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