Skip to content

hackage2nix reproducibility #431

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

Closed
roberth opened this issue Oct 13, 2019 · 8 comments
Closed

hackage2nix reproducibility #431

roberth opened this issue Oct 13, 2019 · 8 comments

Comments

@roberth
Copy link
Member

roberth commented Oct 13, 2019

I've tried to run hackage2nix in order to test a change I made to the yaml file in Nixpkgs. I didn't make it through. I'll summarize my experience.

  1. I used git add worktree and git checkout --detach instead of git clone nixpkgs to speed it up. Didn't work because update-nixpkgs.sh pulls in the nixpkgs worktree.
  2. I had to add cabal, ghc, zlib and openssl to my shell before invoking update-nixpkgs.sh
  3. Still, cabal failed with
    $ ./update-nixpkgs.sh 
    <command line>: can't load .so/.DLL for: libz.so (libz.so: cannot open shared object file: No such file or directory)
    cabal: Failed to build cabal2nix-2.15.0 (which is required by exe:hackage2nix
    from cabal2nix-2.15.0).
    

Proposed solution

I think the script can be nixified. I suggest adding the following to Nixpkgs:

  • pin files for
    • cabal2nix repo revision
    • all-cabal-hashes repo revision
  • a port of update-nixpkgs.sh, limited to generation
    • using the pins
    • no assumption about the caller's environment (nix-shell shebang or similar)
    • no git logic, just generation
  • a script to update the pins and call the codegen script
  • assuming the code generation is now pure, a derivation that tests whether the generated code is up to date, to prevent hand-editing and ensure reproducibility

This will let anyone regenerate the package set in a reproducible way. This also makes #219 trivial. Just mention the pin files in a comment.

Did I miss something that makes the above not work?

@peti
Copy link
Member

peti commented Oct 14, 2019

https://www.youtube.com/watch?v=qX0mgtSm360 has very detailed instructions how to run hackage2nix. Maybe that is helpful? Once you have actually built the executable correctly, you'll find that it's actually pretty easy to run.

@roberth
Copy link
Member Author

roberth commented Oct 15, 2019

That's really cool that you've put it in a video. Video is a great format for explaining things.

When I tried running the update script, I followed the Setup and Run steps in the hackage2nix README. My goal was to test a configuration change, not hacking on hackage2nix or anything like that. Even without my "proposed solution" I don't think that it should take more than a little shell script invocation.

If my intention was to do more work on hackage2nix etc, I'd probably have found the video.

@peti
Copy link
Member

peti commented Oct 18, 2019

I believe I can close this issue now. Do you agree? Or do you feel like your suggestion hasn't been fully resolved or addressed yet?

@roberth
Copy link
Member Author

roberth commented Oct 18, 2019

The hackage2nix readme does not work if you don't also follow the steps from the video. I think the instructions in the readme itself should be minimal but correct. Minimal because the video does a good job explaining all the subtleties, correct because otherwise people run into trouble like me.

You have spent significant effort on the current workflow and I understand if you're not motivated to change it again. Perhaps you don't want people to regenerate the package set in a single command without setup? Anyway, that's up to you as a maintainer.

@peti
Copy link
Member

peti commented Oct 18, 2019

The hackage2nix readme does not work if you don't also follow the steps from the video.

Would you mind making a specific suggestion how to improve the README? I would very much like it to describe the process correctly, so if you could offer concrete advice -- or a PR? -- then that would be very useful.

You have spent significant effort on the current workflow and I understand if you're not motivated to change it again.

What makes you say that? If the workflow can be improved, then I am all for it! I just don't see what improvements you would suggest, specifically. What would you like to change?

@nh2
Copy link
Contributor

nh2 commented Apr 17, 2020

Going through this as well myself now, I think I start to understand what @roberth is asking.

A common use case seems to be that somebody wants to "just" do a minor change to configuration-hackage2nix.yaml, and then render the results out into hackage-packages.nix using hackage2nix.

But there are some obstacles to it:

  • The default workflow relies on tooling outside nixpkgs. The tooling itself is not version-pinned, and a user has to learn multiple stps in order to run it.
    • It would be better if we could have a script in pkgs/development/haskell-modules, that drops you in a shell that has cabal2nix (and its hackage2nix executable) from that same nixpkgs. Then one could run ./generate-hackage-packages.sh straight from that directory, without having to setup anything.
  • The update-nixpkgs.sh in cabal2nix does various things that one may not need/want, such as git reset -q --hard inside nixpkgs. That is a bit impractical for the use case of quickly testing a local change.
    • W could perhaps make a ./generate-hackage-packages.sh process the configuration-hackage2nix.yaml right next to it, without any git operations.

nh2 added a commit to nh2/cabal2nix that referenced this issue Apr 26, 2020
This should make it much easier for new contributers to contribute to
`cabal2nix`, as it addresses many of the pain points from NixOS#431.

The added Stack build also improves reproducibility by using a Stackage LTS
and pinning a nixpkgs version.
nh2 added a commit to nh2/cabal2nix that referenced this issue Apr 26, 2020
This should make it much easier for new contributers to contribute to
`cabal2nix`, as it addresses many of the pain points from NixOS#431.

The added Stack build also improves reproducibility by using a Stackage LTS
and pinning a nixpkgs version.
@roberth
Copy link
Member Author

roberth commented Jun 22, 2021

The steps in Nixpkgs to regenerate the packages have been reduced to essentially two steps, which is close enough for me.

My notes for a quick test with updated hackage, distilled from the more complete pkgs/development/haskell-modules/HACKING.md (or its permalink)

Test newly uploaded release

Check that all-cabal-hashes is up to date with your upload. Run:

./maintainers/scripts/haskell/update-hackage.sh
./maintainers/scripts/haskell/regenerate-hackage-packages.sh
nix-build -A haskellPackages.foo

@roberth roberth closed this as completed Jun 22, 2021
@sternenseemann
Copy link
Member

Pending tasks are:

  • Document at least the regenerate-hackage-packages.sh script in the nixpkgs manual
  • Remove the legacy hackage2nix scripts from this repository (I think they now only serve to confuse users)

Profpatsch pushed a commit to Profpatsch/cabal2nix that referenced this issue Mar 7, 2022
This should make it much easier for new contributers to contribute to
`cabal2nix`, as it addresses many of the pain points from NixOS#431.

The added Stack build also improves reproducibility by using a Stackage LTS
and pinning a nixpkgs version.
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

No branches or pull requests

4 participants