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
Crystal package builder #67510
Crystal package builder #67510
Conversation
|
||
defaultOptions = [ "--release" "--progress" "--no-debug" "--verbose" ]; | ||
|
||
in stdenv.mkDerivation (mkDerivationArgs // { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Wouldn't it be nicer to allow overriding of all attributes by inverting the merge order?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@manveru For all attributes I'm setting in the derivation, I'm also propagating the ones from args
(if any). This order is needed because otherwise e.g. the users buildInputs
would override our changed buildInputs
which contains crystal.
runHook postInstall | ||
''; | ||
|
||
meta = args.meta or {} // { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not sure why the {} //
is needed here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's parsed as (args.meta or {}) // { ... }
, so this prevents it from failing when args
doesn't have meta
runHook postConfigure | ||
''; | ||
|
||
buildInputs = args.buildInputs or [] ++ [ crystal ]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is the [] ++
needed here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah same reason, in case args
doesn't have buildInputs
set
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, I was reading the precedence wrong... really would prefer parenthesis in this case :)
We definitely need this! Any reason for building using |
@peterhoeg I have zero experience with both crystal and shards, I just followed what the mint derivation was doing. Maybe
|
05438bf
to
1d07491
Compare
I pushed a minor I also added a commit for adding a Crystal section to the nixpkgs docs |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nix-review
passes on NixOS
diff LGTM (But im also very unfamiliar with crystal, and it should probably be tested by building a crystal package)
has documentation 👍
executables still seem to work
[4 built, 33 copied (1293.6 MiB), 223.0 MiB DL]
https://github.com/NixOS/nixpkgs/pull/67510
2 package were build:
crystal2nix mint
When you do targets:
foo:
main: src/foo.cr Which is enough for you to build with Except for |
@peterhoeg Since we need this functionality anyways for |
This makes `crystal play` work
Just added a commit to switch |
Fair enough. It's definite improvement on the existing situation. lgtm when the darwin test passes. |
Hey, I wonder if there is a way to avoid needing crystal2nix. I would prefer if there story of someone using crystal on nix would not be that different from crystal on other platform. When installing crystal dependencies described in a shard.yml a shard.lock is generated. That will have for example the git tag or the commit ref if the dependency was a branch. When installing crystal dependencies with a shard.lock present that will be used. Nothing novel. I know that if the tag of a dependency is removed/changed the lock will be useless for reproducing. If shards would include always the git commit in the lock file and install from it, would that be enough to avoid needing crystal2nix? Or what else would be needed? |
using a lock file to pull in dependencies is something that's already done with rust and go packages. All it takes is someone implementing it. |
Are there any requirements for those lock files to be enough for Nix? Eg: always include the explicit commit ref instead of tag. |
generally there's some pull step in-which the dependencies defined in the lock file have to manifest themselves as a derivation which then can be consumed downstream. For go, this is looking at the go.mod file, pulling all the related dependencies, then passing that to the actual build. |
@bcardiff Almost transparent Nix support is possible with the following:
The only project I know of that has transparent Nix support is poetry using poetry2nix which only exposes a set of Nix functions for building poetry projects without any code generation necessary. This is also what allows poetry2nix to be used in nixpkgs by just checking in the project and lock file. For poetry I believe they don't need to mess with NAR hashes because all dependencies are downloaded from pypi's servers, which probably don't ever update tarballs (unlike e.g. GitHub). Pinging @adisbladis as poetry2nix author, and who pushed poetry towards making their lock files Nix compatible. |
@manveru is already working on this ref #89863 (comment) |
@manveru I think your lock file transformer function wouldn't work for nixpkgs because of And ideally we wouldn't have to do IFD or code generation also (which is the case with poetry2nix). IFD is no good for nixpkgs and code generation is more maintenance. With the points I mentioned above both of these problems wouldn't be there. |
Oh actually poetry2nix used |
Motivation for this change
I'll be trying to package invidious soon, which uses crystal, so I thought why not first upgrade the crystal infrastructure in nixpkgs a bit.
I put the
buildCrystalPackage
function inside the compiler attributes such that you can select a version with e.g.pkgs.crystal_0_29.buildCrystalPackage
, which is very simple.I recommend viewing each commit separately
Ping @manveru @david50407 @peterhoeg
Things done
crystal2nix
andmint
)