incremental package builds
play

Incremental Package Builds Guillaume Maudoux @layus NixCon 2017 - PowerPoint PPT Presentation

Incremental Package Builds Guillaume Maudoux @layus NixCon 2017 Louvain-la-Neuve hold a huge bike event @layus ) a long, vague and emphatic speech layus a nixpkgs contributor laus ( @layus ) a long, vague and emphatic speech layus a


  1. Incremental Package Builds Guillaume Maudoux @layus NixCon 2017

  2. Louvain-la-Neuve hold a huge bike event

  3. @layus ) a long, vague and emphatic speech layus a nixpkgs contributor laïus (

  4. @layus ) a long, vague and emphatic speech layus a nixpkgs contributor laïus (

  5. @layus ) a long, vague and emphatic speech layus a nixpkgs contributor laïus (

  6. I contributed to build a castle in France

  7. So I… started a PhD on incremental builds want your feedback on this presentation ▶ like building stufgs

  8. So I… want your feedback on this presentation ▶ like building stufgs ▶ started a PhD on incremental builds

  9. So I… ▶ like building stufgs ▶ started a PhD on incremental builds ▶ want your feedback on this presentation

  10. Incremental package builds

  11. Incremental adjective […] occurring in especially small increments . noun the amount or degree by which something changes;

  12. Incremental adjective […] occurring in especially small increments . noun the amount or degree by which something changes;

  13. Incremental build systems ▶ Works better with small steps ▶ Can reuse older build products ▶ Can detect what needs to be built

  14. Plan Firefox – Works better with small steps i3 – Can reuse older build products Nix store – Can detect what needs to be built

  15. Firefox – Small steps

  16. Building Firefox takes very long 50s unpack 1 min 1s patch 156s confjgure 2 min 30 s 4006s build 1 hour 6 min 31s install 8s fjxup

  17. We need checkpoints!

  18. We need checkpoints!

  19. We need checkpoints!

  20. We need checkpoints!

  21. Trivial idea We could split each package phase in a difgerent derivation… Only a small, local fjx Not clean for /nix/store Already done by external wrappers ( firefox )

  22. Trivial idea We could split each package phase in a difgerent derivation… ▶ Only a small, local fjx ▶ Not clean for /nix/store ▶ Already done by external wrappers ( firefox )

  23. Incremental builds is about small steps Build systems are incremental at command level. let’s use that! ▶ Nix is incremental at the package level. ▶ Nix is a package manager

  24. Incremental builds is about small steps level. ▶ Nix is incremental at the package level. ▶ Nix is a package manager ▶ Build systems are incremental at command ▶ let’s use that!

  25. Build systems details – make 2. cons: 1. pros: ▶ well known ▶ requires previous builds as an input ▶ uses timestamps to detect changes

  26. Build systems details – ccache ccache memoizes compiler invocations sccache can share it’s cache on the network nix is much like sccache

  27. Build systems details – nix-make

  28. Build systems details – nix-make let { inherit (import ../../lib) compileC link; hello = link { objects = compileC { main = ./hello.c; }; }; body = [hello]; }

  29. Build systems details – nix-make 1. pros: 2. cons: ▶ very small steps ▶ compatible with nix ▶ every intermediate .o fjle ends up in the store ▶ requires to port projects to nix-make

  30. Build systems details – bazel

  31. Build systems details – bazel 2. cons: bazel = nix + build system 1. pros: ▶ caches arbitrary commands ▶ uses sandboxing to guarantee correctness ▶ confmicts with nix

  32. Intermediate solution Easy to implement, if we trust the build system. ▶ Use caching in the build system ▶ Control caching from nix-build

  33. Allow caching inside nix-build

  34. still a work in progress

  35. i3 – Reusing old builds

  36. The issue Requirements ▶ Need to patch i3 for an annoying bug ▶ Can only be tested on this machine ▶ Needs to be included in NixOS confjg

  37. Typical debug session ( nixos-rebuild ) ▶ build a custom version ( nix-shell ) ▶ write an overlay for that package ( nix-build ) ▶ modify nixos to use it, and use debug fmags ▶ test and restart

  38. Current options We need an easy solution to achieve simple, local package development: 1. Mount the nix store RW 2. Insert a symlink in the store 3. Confjgure services with paths outside the store Hacky !!

  39. Current options We need an easy solution to achieve simple, local package development: 1. Mount the nix store RW 2. Insert a symlink in the store 3. Confjgure services with paths outside the store Hacky !!

  40. Current options We need an easy solution to achieve simple, local package development: 1. Mount the nix store RW 2. Insert a symlink in the store 3. Confjgure services with paths outside the store Hacky !!

  41. Current options We need an easy solution to achieve simple, local package development: 1. Mount the nix store RW 2. Insert a symlink in the store 3. Confjgure services with paths outside the store Hacky !!

  42. Current options We need an easy solution to achieve simple, local package development: 1. Mount the nix store RW 2. Insert a symlink in the store 3. Confjgure services with paths outside the store Hacky !!

  43. Current options We need an easy solution to achieve simple, local package development: 1. Mount the nix store RW 2. Insert a symlink in the store 3. Confjgure services with paths outside the store Hacky !!

  44. Existing tools git rebase --interactive brings you right at the confmicting commit, in a fake environment nix-shell -A setups the right environment to build a package. But you can not write to the store

  45. Solving the nix-shell issue To make nix-shell more handy, it could generate a random $out on each invocation, and allow writes to that store location. We want a trade-ofg between correctness and ease of use. nix build --hack i3

  46. Nix* “OSI” model

  47. nix-shell is a zipper

  48. Going further nixos-rebuild test --hack i3 Drop me in a shell where I can patch i3, then use that for this nixos version.

  49. And even further We can even use caching when implemented! A “clean” nix-build could reuse results cached by a “hacky” build. TL;DR: Never compile the same build step twice. Well, if implemented.

  50. And even further We can even use caching when implemented! A “clean” nix-build could reuse results cached by a “hacky” build. TL;DR: Never compile the same build step twice. Well, if implemented.

  51. And even further We can even use caching when implemented! A “clean” nix-build could reuse results cached by a “hacky” build. TL;DR: Never compile the same build step twice. Well, if implemented.

  52. Nix store – Track changes

  53. /nix/store has many similar packages ฀ ฀ ฀ ฀ ฀ ฀ -Cflags: -DPOPPLER_DATADIR=/nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7/share/poppler ฀ ฀ ฀ Version: 0.4.7 ฀ ฀ ฀ Description: Encoding files for use with poppler ฀ ฀ ฀ Name: poppler-data ฀ ฀ ฀ diffoscope /nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7 /nix/store/ccc9py7hfgd5v4q7hk2fv3l4rjllh12i-poppler-data-0.4.7 ฀ ฀ ฀ +poppler_datadir=/nix/store/ccc9py7hfgd5v4q7hk2fv3l4rjllh12i-poppler-data-0.4.7/share/poppler ฀ ฀ ฀ -poppler_datadir=/nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7/share/poppler ฀ ฀ ฀ @@ -1,8 +1,8 @@ ฀ ฀ ฀฀฀ poppler-data.pc ฀ ฀฀฀ pkgconfig ฀฀฀ lib +++ /nix/store/ccc9py7hfgd5v4q7hk2fv3l4rjllh12i-poppler-data-0.4.7 --- /nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7 ฀ ฀ ฀ +Cflags: -DPOPPLER_DATADIR=/nix/store/ccc9py7hfgd5v4q7hk2fv3l4rjllh12i-poppler-data-0.4.7/share/poppler

  54. /nix/store has many similar packages

  55. Nix store --optimize $ du -shc /nix/store/{X,Y,Z}-poppler-data-0.4.7 12M /nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7 60K /nix/store/ccc9py7hfgd5v4q7hk2fv3l4rjllh12i-poppler-data-0.4.7 60K /nix/store/pshrgbbmvkxp6lf4hzwn04560brf52lp-poppler-data-0.4.7 13M total

  56. Nix store --optimize

  57. Mass rebuilds use a lot of network. Every week, unstable branch is merged into master. Every week, nixpkgs master receives mass-rebuild commits. Updating once per month makes you download a full new distro each time. Can we do better that that ?

  58. Binary difgs of substitutes By storing and sharing difgs of binary packages, we could save bandwidth and hydra space.

  59. Content addressed storage We can even go further for derivations whose only difgerence is their $out .

  60. Content addressed storage

  61. CAS & change propagation

  62. CAS & change propagation

  63. Content addressed storage 2. Cons: 1. Pros: ▶ Does not propagate changes to dependencies ▶ Less compiling ▶ Faster updates ▶ Not too diffjcult to implement ▶ Outsourcing reproducibility is easy ▶ Changes Nix ▶ Real impact is unknown

  64. CAS & refactorings

  65. CAS & Cached builds Caching builds cam make them less stable (reproducible) Content addressed store would help to catch unstable builds

  66. Conclusion There are still a lot of possible improvements to nix. I have started to work on cached builds, and CAS is under RFC. Comments welcome.

  67. Questions ?

Recommend


More recommend