hercules-ci / flake-parts

❄️ Simplify Nix Flakes with the module system
https://flake.parts
MIT License
779 stars 42 forks source link

Dev-only dependencies #119

Open roberth opened 1 year ago

roberth commented 1 year ago

Avoid loading dev-only modules by deferring those; when checks etc are accessed.

This will work best with

roberth commented 1 year ago

flakeModules may suffer from a similar lack of laziness and should perhaps be considered as a "class" or "context" of its own.

Both it and dev-only dependencies move towards a situation where the top level attributes are more controlled, and have to be enumerated somewhere in order to be published on the flake. It's perhaps worth considering to model these dependency phenomena explicitly within the top level modules somehow. The genericity seems warranted because the internal dependencies may differ between flakes. I'm concerned about the complexity of such a solution though, and about the potential for bad interactions (although that might just be fear talking at this point). To develop this, it's probably best to start with dev-only dependencies and perhaps later generalize it, if feasible.

roberth commented 1 year ago

Here's a possible implementation

The flaws are

Ideally it would reuse the base evaluation's option values, while also setting readOnly = true on the pre-existing options. Only specific options, such as checks and perSystem.checks would have their definitions forwarded, allowing merging (instead of forwarding the final option value).

a situation where the top level attributes are more controlled, and have to be enumerated somewhere in order to be published on the flake.

Not sure. They may be quite orthogonal despite serving similar goals.

later generalize it

Had no problem generalizing https://github.com/hercules-ci/hercules-ci-agent/pull/516 (mentioned at the start).

roberth commented 3 months ago

:tada: You may now use flake-parts.flakeModules.partitions to achieve this.


I'm debating whether to add an opinionated module that sets

partitionedAttrs.checks = "dev";
partitionedAttrs.devShells = "dev";

and perhaps add a convenience alias dev for partitions.dev.module. Not sure about the other options in partitions.dev though. Maybe set opinionated defaults like extraInputsFlake = self.outPath + "/dev";? Might be fragile.