lusingander / serie

A rich git commit graph in your terminal, like magic 📚
MIT License
436 stars 13 forks source link

add nix flake #30

Open nebunebu opened 3 months ago

nebunebu commented 3 months ago

adds files flake.nix and package.nix and updates README.md with explanation on how to run with nix and how to install on NixOS.

yanganto commented 3 months ago

Could you put a dev shell for the project? It will be nice for anyone want to join the project.

nebunebu commented 3 months ago

@yanganto I added a devShell with the local build of serie, and also rustfmt and rustup

yanganto commented 3 months ago

If we want to build a nix package for serie, we do not need to add flake here. We can make a PR on https://github.com/NixOS/nixpkgs/, which is an official way.

Why do people use nix/flake for their projects? Because we want to make the build, the development, and the CI server in the same environment.

For a Rust project, we will keep the Rust version, fmt, clippy, and all the dependencies the same from the build system, and the dev shell for development, and use it in CI.

The flake is introduced here, and what do we want for this project? The build and the development environment are not the same, so it is not reproducible and not beneficial to serie in this PR.

nebunebu commented 3 months ago

It's already been added to nixpkgs. I appreciate the consideration you gave to this contribution. Feel free to close the request at your leisure.

alerque commented 3 months ago

Having a flake serves a completely different purpose as having a package in nixpkgs. Both can be used by and end user just to run an app, but they are fundamentally different and having both is a good thing. The nix package is great to have both on Nix OS and anywhere nix will run as a way to run a pre-approved packaged version (often prebuilt in a cache somewhere). The Flake is useful to be able to execute the repository as if it was the app at any point in history (tag, branch, commit hash, etc.). This is great for testing PRs, checking out a new feature before it is merged or packaged, etc. Additionally having the dev shell feature in the flake makes it easy to contribute back to the project by making sure to have all the development, testing, and linting tooling handy. The project itself can choose to use it or not, but for contributors that use Nix it's quite handy.

yanganto commented 3 months ago

@alerque Yes, I agree with you. Flake provides a consistent environment for all builds (and easy to use branch, tag, and event with a commit). I love combining the Rust with Nix to enhance a project. I am not against flake here, but the strong power of nix and flake needs you to lock things correctly. The thing I point out is that the current implementation is not correct, and let me clarify this in details.

The following are issues if you use rustup in dev shell, and it does not help and makes issues.

First, rustup will download rust and cargo, and it will have a side effect, no one can guarantee any version of rust downloaded by rustup can run this project, such that Nix loses its reproducibility guarantee. In other words, the rust to build the package is locked in flake.lock, but the rust in the dev shell is not the same thing, so it will not be reproducible.

Second, if a system already has cargo managed by another existing rustup, the rustup of the dev shell will get conflict with it. Because rustup will not install things inside the nix shell but out side of it. This will conflict if you develop more than one Rust projects with nix dev shell using rustup.

Last, installation of rustup is easy with the one-line command

curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh

It is no a good reason for a developer to install nix and get rustup only, the developer will want the exact rust and all dependencies for the project from the nix dev shell.

nebunebu commented 3 months ago

@alerque @yanganto