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

Migrate to Nix flakes #2

Merged
merged 17 commits into from
Dec 12, 2023
Merged

Migrate to Nix flakes #2

merged 17 commits into from
Dec 12, 2023

Conversation

fwcd
Copy link
Owner

@fwcd fwcd commented Dec 12, 2023

While Nix derivations, which we use to package up the programs, produce mostly reproducible builds via nix-build, the Nix ecosystem increasingly seems to be moving in the direction of flakes12, which provide some conveniences and even more reproducible builds by e.g. locking the nixpkgs revision.

Note

Flakes are another, higher-level notion of package, that in of itself only define a set of inputs (dependencies) and outputs (an attribute set)1. By convention, however, keys such as packages and apps are used to declare derivations and executables in the output, such that commands like nix build and nix run know what to work with.

For this reason we will migrate this repo to flakes too. Specifically:

  • Each day will become a flake, declaring a default derivation ("package") and an executable ("app"), such that we can use nix run to build and run the program
  • The default derivation will be moved into derivation.nix using nixpkgs-style dependency injection (i.e. { stdenv, ...}: ... instead of { pkgs }).
    • This seems to be the idiomatic approach, it requires us to use callPackage3 instead of import, however, and also means that we can no longer build the days with the legacy nix-build command. In principle, one could write a wrapper .nix that invokes callPackage, like the flake does4, but to keep things uniform, we will only provide a flake for now.
    • With this approach, we will also inject vendored derivations (e.g. b-compiler or pakcs) from the flake, which are now also declared in the nixpkgs-style format3.

Footnotes

  1. A great write-up of Nix flakes: https://www.reddit.com/r/NixOS/comments/131fvqs/can_someone_explain_to_me_what_a_flake_is_like_im/ 2

  2. Another great write-up: https://christine.website/blog/nix-flakes-1-2022-02-21/

  3. A nice explanation and motivation of callPackage: https://summer.nixos.org/blog/callpackage-a-tool-for-the-lazy/ 2

  4. A good walkthrough of (non-flake) Nix packaging, along with an extensive example can be found here: https://unix.stackexchange.com/a/717169/556223

@fwcd fwcd added the enhancement New feature or request label Dec 12, 2023
@fwcd fwcd merged commit f7f0cf7 into main Dec 12, 2023
22 checks passed
@fwcd fwcd deleted the flakes branch December 12, 2023 01:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant