NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
18.16k stars 14.19k forks source link

Module system: "jig" #355648

Open roberth opened 2 days ago

roberth commented 2 days ago

Description

Don't we all want better control over modules, and better performance?

In this issue, I propose a function which I think is feasible to implement: mkJig

A device in manufacturing, woodworking, or other creative endeavors for controlling the location, path of movement, or both of either a workpiece or the tool that is operating upon it. (wiktionary)

This would be a function that, given some settings, transforms a module into a module.

mkJig :: { ... } -> Module -> Module
         ^^^^^^^ some settings
                    ^^^^^^ passed module
                              ^^^^^^ returned module

The settings restrict the structure of the returned module, and perhaps also restrict or alter the module arguments available to the passed module.

Doing this is ambitious. This function is effectively an alternate (simpler?) evalModules that functions as a proxy instead of computing its own fixpoint.

This kind of transformation has the potential to solve a number of issues:

Caveats

Context

Notify maintainers

@infinisil @roberth



Add a :+1: reaction to issues you find important.

Aleksanaa commented 2 days ago

I thought so before, but then the to-do list was too long so I didn’t raise this issue again.

It is easy to design a fancy new module system, but what we should think about is how to design one that is good enough but also allows us to easily migrate from the current state (just requiring some simple tidying up work or even automatic treewide changes).

Also CC @GTrunSec who did a lot of experiment on module system related works.

roberth commented 1 day ago

how to design one that is good enough but also allows us to easily migrate from the current state

Absolutely.

I think you're responding to:

This function is effectively an alternate (simpler?) evalModules that functions as a proxy instead of computing its own fixpoint.

Not the best phrasing of mine. It won't be a types type or an actual alternative to evalModules; just an implementation of something that has a resemblance to evalModules. The goal is for it to produce modules that are compatible with evalModules.