Skip to content
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

Add nix flake #1575

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Add nix flake #1575

wants to merge 2 commits into from

Conversation

tirimia
Copy link

@tirimia tirimia commented Nov 27, 2024

This PR enables building lychee via nix flake by simply running nix build.
Simultaneously, nix develop will open a shell with the environment required to build and develop it.

@mre mre mentioned this pull request Nov 27, 2024
@mre
Copy link
Member

mre commented Nov 27, 2024

@thomas-zahner, @niklaskorz, any thoughts?

@thomas-zahner
Copy link
Member

@tirimia Did you see #1565? It's pretty much a duplicate of this PR. The main difference is that with my PR I didn't have nix build in mind. I do like the idea, so eventually we could use Nix to build in CI.

Is it possible to easily specify the Rust version in this flake? If not I would probably prefer my approach.

@tirimia
Copy link
Author

tirimia commented Nov 30, 2024

That’s the beauty of using the fenix flake and reading the toolchain configuration, that’s already taken care of and we then also know we provision rust like the non-nix users of the repo 🥳

In general though, I personally avoid thinking of the specific version of software when working with nix as it’s rolling release and if I need something specific, importing a pinned version of nixpkgs is still an open option.

A further advantage of this PR is that people can reference this flake and use lychee without having to figure out how to build it on their own. You can also directly call it with nix run github:lycheeverse/lychee

@thomas-zahner
Copy link
Member

@tirimia Ah I see, thanks for the clarification. I agree that this is probably the better approach. Does this mean that nixpkgs could simply reference our flake?

flake.nix Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@thomas-zahner
Copy link
Member

Also would you mind if we add an .envrc file to the project, as in my PR?
Sorry if my questions seem weird or stupid, I'm quite new to Nix 😅

@tirimia
Copy link
Author

tirimia commented Nov 30, 2024

@tirimia Ah I see, thanks for the clarification. I agree that this is probably the better approach. Does this mean that nixpkgs could simply reference our flake?

Nixpkgs offers a reference to its packages via flakes as a convenience; flakes are not “officially” stable.

You can, however, reference this flake in your own or in the command line

@tirimia
Copy link
Author

tirimia commented Nov 30, 2024

Also would you mind if we add an .envrc file to the project, as in my PR? Sorry if my questions seem weird or stupid, I'm quite new to Nix 😅

I would avoid that. Direnv docs recommend you add .envrc and .direnv to your global git ignore. Committing it forces people to use the flake if they use direnv, and it also prevents people from having their own configuration

As for the “stupid” questions: nix is a beast, the craft of tech is impossible to master in its entirety. Don’t judge yourself for not knowing things, enjoy that you get to learn 💃

@niklaskorz
Copy link

niklaskorz commented Nov 30, 2024

Also would you mind if we add an .envrc file to the project, as in my PR? Sorry if my questions seem weird or stupid, I'm quite new to Nix 😅

I would avoid that. Direnv docs recommend you add .envrc and .direnv to your global git ignore. Committing it forces people to use the flake if they use direnv, and it also prevents people from having their own configuration

As for the “stupid” questions: nix is a beast, the craft of tech is impossible to master in its entirety. Don’t judge yourself for not knowing things, enjoy that you get to learn 💃

As for .direnv, yes, that should be gitignored. But it's common practice to track the .envrc.

flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
flake.nix Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@thomas-zahner
Copy link
Member

@tirimia @niklaskorz thank you for the answers and improvements. The flake now targets my platform but it still does not build because of the pinned SHA which is not the same on my platform. With the current version I get a mismatch: error: hash mismatch in fixed-output derivation.

We can't simply remove the argument because it seems to be required: error: in pure evaluation mode, 'fetchurl' requires a 'sha256'.

When an empty string is provided or if nixpkgs.lib.fakeSha256 is used, the following error will occur

       error: hash mismatch in fixed-output derivation ...:
         specified: sha256-AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA=
            got:    sha256-s1RPtyvDGJaX/BisLT+ifVfuhDT1nZkZ1NcK8sbwELM=

So now I see two possibilities:

  • Specify the hashes for every single platform. But I'm not sure if this is possible or if this makes sense as it seems quite cumbersome.
  • Just switch to rust-overlay as in my PR

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.

4 participants