Closed olebedev closed 1 year ago
is this a breaking change btw?
@pathway27, no, it's not a breaking change, everything will continue working as it was before.
@pathway27, I will rebase on https://github.com/canva-public/js2nix/pull/7 after it's merged so we can see a regression if any.
Background
Writing Nix expressions for non-Nix folks can be overwhelming. For example, developers from product teams can bump and update Node.js packages quite often, and sometimes they have to deal with Nix expressions like this:
which is pretty natural for folks who are aware of how to write Nix but for those who are not familiar it can be challenging. Also, I found that the complexity of Nix and its ecosystem is the main barrier when people question if we should adopt Nix more, which I believe shouldn't even be asked.
That is, the main point of this PR is to reduce this burden and let non-Nix folks apply overlays defined in
package.json
files instead of writing Nix expressions in the Nix language.The solution
The introduced mechanism is very similar to additional sections of
package.json
file that different package managers from Node.js ecosystem support. For example, Yarn supports theresolutions
section, PNPM supportspnpm.overrides
(and more), and so on.For example, instead of creating an overlay function as a Nix expression as above, the same can be done in
package.json
file now:In this PR
This PR required many things to be moved around to make it work and a couple of those are naturally aligned with the point of this PR, here are the technical pieces of the changeset:
js2nix
section infpackage.json
file, and an overlay function generation, see./overlay.nix
file.__meta__
section in the resulting generated Nix expression, to make the overlay generation logic work. Otherwise it won't be possible because it's not possible to inspect the whole resulting attrset from within an overlay, it will reach infinite recursion.It can be gotten by:
(js2nix will abort the evaluation phase if there is a name clash)
lib.nix
file, which is the cause of a huge diffindex.js
file in the package root folder or themain
field inpackage.json
file will be checked by default if it can be required in Node.js context, likerequire('yargs')
. Can be disabled by overriding.buildEnv
function as the main API entry point to reduce cognitive overloading and make use ofjs2nix
simpler. For example, it's only single function invocation nowSee the documentation's addition, for more details.