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

Remove Nix dependency: flake-utils + fixups #802

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

toastal
Copy link
Contributor

@toastal toastal commented Dec 10, 2024

This dependency isn’t useful since it is just a loop, doesn’t capture all supported systems, & isn’t worth propagating it to downstream users (currently it still is required for Nickel, but that is on them). Related #613.

Also caught a typo.

Small refactors:

  • using inputs as an attrset to more easily track dependencies (allows removing *-input from one of the inputs)
  • expose overlays
  • attrset “caches” for nixpkgs, topiaryPkgs, binPkgs
  • use self.packages where possible
  • don’t calculate checksLight for all systems

Normally removing flake-utils the diff results in less line of code, but refactors added a little bit.

Note: reviewing without whitespace changes makes this easier to review (nesting level changed)

1

Footnotes

  1. Please consider giving up MS GitHub or offering a non-proprietary, non-US-corporate-controlled mirror for this free software project. I wish to delete this Microsoft account in the future, but I need more projects like this to support alternative methods to send patches & contribute.

Copy link
Member

@Niols Niols left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The two first commits definitely bring some nice improvements to the flake; thank you for catching the typo! As for the third one, removing flake-utils and replacing it by repeated calls to nixpkgs.lib.genAttrs, I am much less convinced by the motivation and the gain in usability and readability, but it does seem clean to me.

flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@toastal
Copy link
Contributor Author

toastal commented Dec 10, 2024

As for the third one, removing flake-utils and replacing it by repeated calls to nixpkgs.lib.genAttrs, I am much less convinced by the motivation and the gain in usability and readability, but it does seem clean to me.

The motivation is in #613. Tweag isn’t maintaining Topiary its package in upstream Nixpkgs, which is still on 0.3.x. I would like to use the latest version which seems easiest as a flake, but there are more dependencies than needed which pollute my own flake which I now need to audit for security. Currently, Nickel still has flake-utils as a dependency so it isn’t eliminated, but if I have to do a merge request along that, I would—which would fully eliminate flake-utils + 19 lines from the lockfile. I have spoken with Numtide folks in the past & they agree that it is never worth it to include their library just for the loop… its purpose is to handle Flake environments where you are not reliant on Nixpkgs or its lib, which this project very much already is (for example, having a flake.nix but not using Flakes to lock the nixpkgs version otherwise you have to maintain 2 Nixpkgs by Flake’s design & that lib isn’t in a separate repository). There are repeated calls to genAttrs to build attrsets per architecture that can be reused without calling & evaluating more loops or imports than is necessary. Mind us that Nix is evaluated lazily.

@toastal
Copy link
Contributor Author

toastal commented Dec 10, 2024

If topiaryPkgs & binPkgs were refactored a bit differently this could be smaller/more concise, but I was trying to get the diff as minimal as possible.

With regards to readability:
To view that specific commit without white space: 560b767?w=1
To view a full file: https://github.com/toastal/topiary/blob/remove-flake-utils/flake.nix

Subjectively I think this reads almost identical.

@toastal
Copy link
Contributor Author

toastal commented Dec 10, 2024

Actually I think I can squeeze one smaller commit in the middle here to break it down more. One sec.

✔️ self.packages.${system}.topiary-cli eliminated another function call.

@toastal toastal force-pushed the remove-flake-utils branch 4 times, most recently from 4a3a312 to a188780 Compare December 10, 2024 15:09
@toastal
Copy link
Contributor Author

toastal commented Dec 10, 2024

For more motivation: https://ayats.org/blog/no-flake-utils/

@toastal toastal requested a review from Niols December 10, 2024 15:15
@toastal
Copy link
Contributor Author

toastal commented Dec 10, 2024

It could make more sense to move to pkgsFor & just do that genAttrs once which holds { pkgs = …; topiaryPkgs = …; binPkgs = …; }, since it doesn’t seem that we need a one-off nixpkgsFor.

Yes, this is few lines of code & less loops.

wasm-bindgen-cli-overlay = final: prev:
outputs = { self, nixpkgs, ... }@inputs:
let
supportedSystems = nixpkgs.lib.systems.flakeExposed;
Copy link
Contributor Author

@toastal toastal Dec 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This can be a different value, but Rust doesn’t have many platform limitations & flake-utils has an arbitrary/opinionated list of supported platforms in x86_64 + aarch64 for Linux & Darwin.

@toastal
Copy link
Contributor Author

toastal commented Dec 10, 2024

Rebased & resolved conflicts

@toastal
Copy link
Contributor Author

toastal commented Dec 11, 2024

Rerebased & reresolved conflicts

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.

2 participants