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 a Nix flake #3221

Merged
merged 9 commits into from
Jun 8, 2021
Merged

Add a Nix flake #3221

merged 9 commits into from
Jun 8, 2021

Conversation

gilligan
Copy link
Contributor

@gilligan gilligan commented May 19, 2021

Summary
Add a basic nix flake that simply exports several packages from the toplevel default.nix

Notes

  • This is mostly based on the work by @hamishmack in [WIP] Add flake #2517
  • The flake is only added because using bitte requires it
  • The current flake outputs are only temporary but in general the idea is for the flake to only provide what is essential for using bitte
  • For the most part the flake just imports from niv sources and default.nix, but inputs.nixpkgs and inputs.haskell-nix have to be kept in sync with the niv revisions manually (for now?).

Status Quo

The latest state of this PR provides a flake.nix that "works" but:


Pre-submit checklist:

  • Branch
    • Commit sequence broadly makes sense
    • Key commits have useful messages
    • Relevant tickets are mentioned in commit messages
    • Formatting, materialized Nix files, PNG optimization, etc. are updated
  • PR
    • Self-reviewed the diff
    • Useful pull request description
    • Reviewer requested

Pre-merge checklist:

  • Someone approved it
  • Commits have useful messages
  • Review clarifications made it into the code
  • History is moderately tidy; or going to squash-merge

@gilligan gilligan requested a review from michaelpj May 19, 2021 10:57
Copy link
Contributor

@michaelpj michaelpj left a comment

Choose a reason for hiding this comment

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

For the most part the flake just imports from niv sources and default.nix, but inputs.nixpkgs and inputs.haskell-nix have to be kept in sync with the niv revisions manually (for now?).

Good times...

flake.nix Outdated Show resolved Hide resolved
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
@gilligan gilligan force-pushed the add-nix-flake branch 3 times, most recently from e0651d7 to cd920c3 Compare May 20, 2021 11:51
@gilligan
Copy link
Contributor Author

After chatting with @michaelpj we came to the conclusion that it should be possible to make this much simpler. So i tried, and failed 😅

In 1f1d22f I tried to just have the flake.nix import the default.nix directly by:

  • making sure to pass system when importing sources.nix which is enough to actually use niv sources from flakes
  • trying to use the correct haskell.nix overlay:
haskellNixOverlays =
if useFlakes 
  then [ haskellNix.allOverlays.combined-eval-on-build ]
  else haskellNix.overlays;

This failed in haskell.nix because it doesn't pass system when importing niv's sources.nix so I tried to fix that as well in
tweag/haskell.nix@3bf3616 and make sure to actually pass system when importing haskell.nix

But ultimately this still fails:

error: attribute 'currentSystem' missing                                                                                                                       
                                                                                                                                                               
       at /nix/store/g9vf0rrmn3g50g7fsn19vk0md0f4fya1-haskell.nix-src/nix/sources.nix:163:16:                                                                  
                                                                                                                                                               
          162|     , sources ? if isNull sourcesFile then {} else builtins.fromJSON (builtins.readFile sourcesFile)                                            
          163|     , system ? builtins.currentSystem                                                                                                           
             |                ^                                                                                                                                
          164|     , pkgs ? mkPkgs sources system                                                                                                              
                                                                                                                                                               
       … while evaluating the attribute 'system'                                                                                                               
                                                                                                                                                               
       at /nix/store/g9vf0rrmn3g50g7fsn19vk0md0f4fya1-haskell.nix-src/nix/sources.nix:65:91:                                                                   
                                                                                                                                                               
           64|       sourcesNixpkgs =                                                                                                                          
           65|         import (builtins_fetchTarball { inherit (sources.nixpkgs) url sha256; }) { inherit system; };                                           
             |                                                                                           ^                                                     
           66|       hasNixpkgsPath = builtins.any (x: x.prefix == "nixpkgs") builtins.nixPath;                                                                
                                                                                                                                                               
       … while evaluating 'addContextFrom'

And i honestly don't understand why. Could you perhaps take a look @angerman or @hamishmack ? :) The key point here is that we are only adding the flake because we have to in order to be able to use bitte but we don't want to maintain or use it much otherwise. So ideally it would mostly just import stuff from the existing setup.

@gilligan
Copy link
Contributor Author

@michaelpj as much as I had hoped that we might be able to make the flake.nix more non-intrusive i have to conclude that the current state of this PR is "as good as it gets". TBH though, while the alternative would have been nice(r) it's not that bad.

nix/default.nix Outdated Show resolved Hide resolved
nix/default.nix Outdated Show resolved Hide resolved
nix/default.nix Outdated Show resolved Hide resolved
nix/default.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
flake.nix Outdated Show resolved Hide resolved
@gilligan
Copy link
Contributor Author

While the latest sate of this builds, flake builds yield different outputs and i don't understand why that might be:

$ nix-build -A web-ghc -o ./web-ghc
$ nix build .#web-ghc-server
$ nix-diff $(nix-store --query --deriver ./result) $(nix-store --query --deriver ./web-ghc)
- /nix/store/znfwxgphsq7vj47c1gr34cq75m3zaprr-web-ghc-exe-web-ghc-server-0.1.0.0.drv:{out}
+ /nix/store/6xrgr181hh2fidr6v2amkw6j3m97c5pl-web-ghc.drv:{out}
• The set of input sources do not match:
    - /nix/store/y4wpxza56pmnsmknfjhazihwv69bdm82-plutus-root-web-ghc-exe-web-ghc-server-root
• The set of input names do not match:
    - data-default-class-lib-data-default-class-0.1.2.0
    - default-Setup-setup
    - exceptions-lib-exceptions-0.10.4
    - glibc-locales-2.32-24
    - http-types-lib-http-types-0.12.3
    - monad-logger-lib-monad-logger-0.3.36
    - optparse-applicative-lib-optparse-applicative-0.16.1.0
    - playground-common-lib-playground-common-0.1.0.0
    - prometheus-lib-prometheus-2.2.2
    - remove-references-to
    - servant-lib-servant-0.18.2
    - servant-server-lib-servant-server-0.18.2
    - wai-cors-lib-wai-cors-0.2.7
    - wai-extra-lib-wai-extra-3.1.6
    - wai-lib-wai-3.2.3
    - warp-lib-warp-3.3.14
    - web-ghc-exe-web-ghc-server-0.1.0.0-config
    - web-ghc-exe-web-ghc-server-0.1.0.0-ghc-8.10.4.20210212-env
    - web-ghc-lib-web-ghc-0.1.0.0
    - yaml-lib-yaml-0.11.5.0
    + ghc-shell-for-packages-ghc-8.10.4.20210212-env
    + hook
    + web-ghc-exe-web-ghc-server-0.1.0.0
• The input named `stdenv-linux` differs
  - /nix/store/5galpnsdfi02x7x0d3gn162k9jfsn4xr-stdenv-linux.drv:{out}
  + /nix/store/v6aj0hzvj7p9m4iiaqjs4d0nbrspc98f-stdenv-linux.drv:{out}
  • The environments do not match:
      allowedRequisites=''
          /nix/store/782n0xrdgdl1a32nvpdfnrx06xxa1zlp-gzip-1.10 /nix/store/782n0xrdgdl1a32nvpdfnrx06xxa1zlp-gzip-1.10 /nix/store/c5jgwpwxc1nxl9gzd9m4wlalrw7sr0z7-bzip2-1.0.6.0.1-bin /nix/store/7l68hmbqhmxib2wlmwyd5ib5czfyb25g-bzip2-1.0.6.0.1 /nix/store/9ikwdf54fsq002g4d36vp6r6qvwk5n3a-xz-5.2.5-bin /nix/store/f2l18n620bw7cmvrs1vh35kry3nrkfy0-xz-5.2.5 /nix/store/kl6lr3czkbnr6m5crcy8ffwfzbj8a22i-bash-4.4-p23 /nix/store/kl6lr3czkbnr6m5crcy8ffwfzbj8a22i-bash-4.4-p23 /nix/store/c1gipyfc161lm0fqfg65k4ak7yl2i17i-binutils-2.34 /nix/store/c1gipyfc161lm0fqfg65k4ak7yl2i17i-binutils-2.34 /nix/store/87ipxqn2ah5ba282cnip9z4mm3dbczjc-coreutils-8.32 /nix/store/87ipxqn2ah5ba282cnip9z4mm3dbczjc-coreutils-8.32 /nix/store/ck3kak4rp8j3649bwy0vk114qpy53q7g-diffutils-3.7 /nix/store/ck3kak4rp8j3649bwy0vk114qpy53q7g-diffutils-3.7 /nix/store/87l6ag9v5pa96axxg756hj4pfcajsmbh-findutils-4.7.0 /nix/store/87l6ag9v5pa96axxg756hj4pfcajsmbh-findutils-4.7.0 /nix/store/vnf5x5ggba946dpan66r1npqj4slrinw-gawk-5.1.0 /nix/store/vnf5x5ggba946dpan66r1npqj4slrinw-gawk-5.1.0 /nix/store/1pms77gm9l4rw8k180wmklagcwsya605-gnumake-4.3 /nix/store/1pms77gm9l4rw8k180wmklagcwsya605-gnumake-4.3 /nix/store/6qyl2yyqjrciypyb8728llsm2mqrhqsp-gnused-4.8 /nix/store/6qyl2yyqjrciypyb8728llsm2mqrhqsp-gnused-4.8 /nix/store/vkbdjkwqf7qxhxwd86cik7nfdppj04n2-gnutar-1.32 /nix/store/vkbdjkwqf7qxhxwd86cik7nfdppj04n2-gnutar-1.32 /nix/store/ipd8n0w9pwhfg1hsna9gv1z46y3j76d2-gnugrep-3.6 /nix/store/ipd8n0w9pwhfg1hsna9gv1z46y3j76d2-gnugrep-3.6 /nix/store/40sgch0d26mqjmrfvg6iq9vmkj2m5b7g-patch-2.7.6 /nix/store/40sgch0d26mqjmrfvg6iq9vmkj2m5b7g-patch-2.7.6 /nix/store/cfvww6slpwnvz19hf169ickmjda4l6jb-patchelf-0.12 /nix/store/cfvww6slpwnvz19hf169ickmjda4l6jb-patchelf-0.12 /nix/store/1s7h0ll18n2988ax3hhg2pjyni5jrf36-ed-1.16 /nix/store/1s7h0ll18n2988ax3hhg2pjyni5jrf36-ed-1.16 /nix/store/sylh15pml1cphys55sy0dr28cp8c42d0-attr-2.4.48 /nix/store/vy7phrnzkbjvsf9j5bkg2f3z8mf0fabv-acl-2.2.53 /nix/store/nnqw9pa10j11r3jjc0fw2rwdipram6gc-zlib-1.2.11 /nix/store/v3aw5ip513vsh6r36fs07niv0b3f7f8l-pcre-8.44 /nix/store/0cbzck6xac05rpg8wnz943vmikl1ws1d-libidn2-2.3.0 /nix/store/48j0w68fyd6lpwwfkjghphxvysgjl84x-libunistring-0.9.10 /nix/store/vbr3p4y2azrgwq2s7h2hbip8x06w50z5-glibc-2.32-24 /nix/store/x4v6h4gcw5vb2d0dm86mwk6kvxiyvxf8-glibc-2.32-24-dev /nix/store/y0mjg5mwdvq7m1dwhpz46wjck76bvba5-glibc-2.32-24-bin /nix/store/5njhh92vrhq6bq7vk56pqzp4mspqc3nr-linux-headers-5.10.4 /nix/store/fws5qmgl882n7zva366sw207b4rmgcyz-binutils-wrapper-2.34 /nix/store/d2fqghv083a8q7j8sjb2m5q6i840h691-gcc-wrapper-10.2.0 /nix/store/5wfh94xwg2hd7n82j8klgn4nmf07is24-gcc-10.2.0 /nix/store/xsqxamd86mh21dk0b775acaqgdijgf6p-gcc-10.2.0-lib /nix/store/xxwq0vv7pjinrr6gjfl2wv54qiaq1zsb-expand-response-params /nix/store/cfvww6slpwnvz19hf169ickmjda4l6jb-patchelf-0.12 /nix/store/mjjy30kxz775bhhi6j9phw81qh6dsbrf-move-docs.sh /nix/store/kxw6q8v6isaqjm702d71n2421cxamq68-make-symlinks-relative.sh /nix/store/cl3qd985p1yxyfkj96v0hqxiy3w69xq5-compress-man-pages.sh /nix/store/iw4rfvg0cmk6nyaprhmn4avrzmlwg9mf-strip.sh /nix/store/6k829xz9v508ncxfcf2p1b8g1wq54946-patch-shebangs.sh /nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh /nix/store/8zxndz5ag0p6s526c2xyllhk1nrn4c3i-audit-tmpdir.sh /nix/store/c8n9kcdddp9np665xz6ri61b383nxvz8-move-systemd-user-units.sh /nix/store/1i5y55x4b4m9qkx5dqbmr1r6bvrqbanw-multiple-outputs.sh /nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh /nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh /nix/store/ngg1cv31c8c7bcm2n8ww4g06nq7s4zhm-set-source-date-epoch-to-latest.sh /nix/store/pr6nzbscdpg94yvr151lrif2kg0csx7b-reproducible-builds.sh ←/nix/store/d2fqghv083a8q7j8sjb2m5q6i840h691-gcc-wrapper-10.2.0←
      ''
      defaultNativeBuildInputs=''
          /nix/store/cfvww6slpwnvz19hf169ickmjda4l6jb-patchelf-0.12 /nix/store/mjjy30kxz775bhhi6j9phw81qh6dsbrf-move-docs.sh /nix/store/kxw6q8v6isaqjm702d71n2421cxamq68-make-symlinks-relative.sh /nix/store/cl3qd985p1yxyfkj96v0hqxiy3w69xq5-compress-man-pages.sh /nix/store/iw4rfvg0cmk6nyaprhmn4avrzmlwg9mf-strip.sh /nix/store/6k829xz9v508ncxfcf2p1b8g1wq54946-patch-shebangs.sh /nix/store/cickvswrvann041nqxb0rxilc46svw1n-prune-libtool-files.sh /nix/store/8zxndz5ag0p6s526c2xyllhk1nrn4c3i-audit-tmpdir.sh /nix/store/c8n9kcdddp9np665xz6ri61b383nxvz8-move-systemd-user-units.sh /nix/store/1i5y55x4b4m9qkx5dqbmr1r6bvrqbanw-multiple-outputs.sh /nix/store/kd4xwxjpjxi71jkm6ka0np72if9rm3y0-move-sbin.sh /nix/store/fyaryjvghbkpfnsyw97hb3lyb37s1pd6-move-lib64.sh /nix/store/ngg1cv31c8c7bcm2n8ww4g06nq7s4zhm-set-source-date-epoch-to-latest.sh /nix/store/pr6nzbscdpg94yvr151lrif2kg0csx7b-reproducible-builds.sh ←/nix/store/d2fqghv083a8q7j8sjb2m5q6i840h691-gcc-wrapper-10.2.0←
      ''
• Skipping environment comparison
  • I tried building something without flakes with haskellNix.allOverlays.combined-eval-on-build and haskellNix.overlays respectively and the outputs were identical. So that shouldn't be the problem.
  • I also tried building some output that doesn't use haskell at all and it's the same for flakes/non-flakes builds.

@michaelpj @angerman do you have an ideas what this might be and what else i could perhaps try?

flake.nix Show resolved Hide resolved
shell.nix Show resolved Hide resolved
gilligan added 8 commits June 8, 2021 13:31
Add a basic nix flake that simply exports several packages from the
toplevel default.nix
Import sources.nix by passing system;
Move sources, haskellNix and haskellNixOverlays to the top level
default.nix which allows for passing the haskellNixOverlays from
flake.nix and thus simply importing 'default.nix' directly.

The reason why this is important is that haskell.nix needs to use
a different overlay for when using in flake evaluationor normal one.
This is due to the fact that when evaluating flakes
builtins.currentSystem is not available.
- Remove default redundant default arguments in nix/default.nix
- Remove unused exports in flake
Refactor flake.nix to pass `haskellNix` and `isInFlake` to
`default.nix` and drop haskellNix.config

* Depending on the value of `isInFlake`, nix/default.nix picks either
haskellNix.overlay or haskellNix.overlays.
* Drop haskellNix.config which doesn't seem relevant for plutus (plutus
doesn't target windows and doesn't use nixpkgs-20.03)
Recover `enableHaskellProfiling` shell.nix argument to get shell
environments with haskell profiling enabled.
Add a comment to the flake file explaining intention and current
limitations of this flake file.
Introduce some changes to the plutus-playground vm test to hopefully
make it more stable on hydra

- Use `journalctl -eu` to jump to go to end of logger output
- Add a sleep(2) to wait for service restart
@gilligan gilligan merged commit 5e765f8 into master Jun 8, 2021
@gilligan gilligan deleted the add-nix-flake branch June 8, 2021 17:49
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