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

incremental package builds
SMART_READER_LITE
LIVE PREVIEW

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


slide-1
SLIDE 1

Incremental Package Builds

Guillaume Maudoux

@layus

NixCon 2017

slide-2
SLIDE 2
slide-3
SLIDE 3

Louvain-la-Neuve hold a huge bike event

slide-4
SLIDE 4

@layus

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

slide-5
SLIDE 5

@layus

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

slide-6
SLIDE 6

@layus

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

slide-7
SLIDE 7

I contributed to build a castle in France

slide-8
SLIDE 8

So I…

▶ like building stufgs

started a PhD on incremental builds want your feedback on this presentation

slide-9
SLIDE 9

So I…

▶ like building stufgs ▶ started a PhD on incremental builds

want your feedback on this presentation

slide-10
SLIDE 10

So I…

▶ like building stufgs ▶ started a PhD on incremental builds ▶ want your feedback on this presentation

slide-11
SLIDE 11

Incremental package builds

slide-12
SLIDE 12

Incremental

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

slide-13
SLIDE 13

Incremental

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

slide-14
SLIDE 14

Incremental build systems

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

slide-15
SLIDE 15

Plan

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

slide-16
SLIDE 16

Firefox – Small steps

slide-17
SLIDE 17

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

slide-18
SLIDE 18

We need checkpoints!

slide-19
SLIDE 19

We need checkpoints!

slide-20
SLIDE 20

We need checkpoints!

slide-21
SLIDE 21

We need checkpoints!

slide-22
SLIDE 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)

slide-23
SLIDE 23

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)

slide-24
SLIDE 24

Incremental builds is about small steps

▶ Nix is incremental at the package level. ▶ Nix is a package manager

Build systems are incremental at command level. let’s use that!

slide-25
SLIDE 25

Incremental builds is about small steps

▶ Nix is incremental at the package level. ▶ Nix is a package manager ▶ Build systems are incremental at command

level.

▶ let’s use that!

slide-26
SLIDE 26

Build systems details – make

  • 1. pros:

▶ well known

  • 2. cons:

▶ requires previous builds as an input ▶ uses timestamps to detect changes

slide-27
SLIDE 27

Build systems details – ccache

ccache memoizes compiler invocations sccache can share it’s cache on the network nix is much like sccache

slide-28
SLIDE 28

Build systems details – nix-make

slide-29
SLIDE 29

Build systems details – nix-make

let { inherit (import ../../lib) compileC link; hello = link {

  • bjects = compileC {

main = ./hello.c; }; }; body = [hello]; }

slide-30
SLIDE 30

Build systems details – nix-make

  • 1. pros:

▶ very small steps ▶ compatible with nix

  • 2. cons:

▶ every intermediate .o fjle ends up in the store ▶ requires to port projects to nix-make

slide-31
SLIDE 31

Build systems details – bazel

slide-32
SLIDE 32

Build systems details – bazel

  • 1. pros:

▶ caches arbitrary commands ▶ uses sandboxing to guarantee correctness

  • 2. cons:

▶ confmicts with nix

bazel = nix + build system

slide-33
SLIDE 33

Intermediate solution

▶ Use caching in the build system ▶ Control caching from nix-build

Easy to implement, if we trust the build system.

slide-34
SLIDE 34

Allow caching inside nix-build

slide-35
SLIDE 35

still a work in progress

slide-36
SLIDE 36

i3 – Reusing old builds

slide-37
SLIDE 37

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

slide-38
SLIDE 38

Typical debug session

▶ build a custom version (nix-shell) ▶ write an overlay for that package (nix-build) ▶ modify nixos to use it, and use debug fmags

(nixos-rebuild)

▶ test and restart

slide-39
SLIDE 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 !!

slide-40
SLIDE 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 !!

slide-41
SLIDE 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 !!

slide-42
SLIDE 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 !!

slide-43
SLIDE 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 !!

slide-44
SLIDE 44

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 !!

slide-45
SLIDE 45

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

slide-46
SLIDE 46

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

  • f use.

nix build --hack i3

slide-47
SLIDE 47

Nix* “OSI” model

slide-48
SLIDE 48

nix-shell is a zipper

slide-49
SLIDE 49

Going further

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

slide-50
SLIDE 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.

slide-51
SLIDE 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.

slide-52
SLIDE 52

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.

slide-53
SLIDE 53
slide-54
SLIDE 54

Nix store – Track changes

slide-55
SLIDE 55

/nix/store has many similar packages

diffoscope /nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7 /nix/store/ccc9py7hfgd5v4q7hk2fv3l4rjllh12i-poppler-data-0.4.7

  • -- /nix/store/4w573p7v5jjjkph5ndzmbwg55v2ids1y-poppler-data-0.4.7

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

slide-56
SLIDE 56

/nix/store has many similar packages

slide-57
SLIDE 57

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

slide-58
SLIDE 58

Nix store --optimize

slide-59
SLIDE 59

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 ?

slide-60
SLIDE 60

Binary difgs of substitutes

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

slide-61
SLIDE 61

Content addressed storage

We can even go further for derivations whose only difgerence is their $out.

slide-62
SLIDE 62

Content addressed storage

slide-63
SLIDE 63

CAS & change propagation

slide-64
SLIDE 64

CAS & change propagation

slide-65
SLIDE 65

Content addressed storage

  • 1. Pros:

▶ Does not propagate changes to dependencies ▶ Less compiling ▶ Faster updates ▶ Not too diffjcult to implement ▶ Outsourcing reproducibility is easy

  • 2. Cons:

▶ Changes Nix ▶ Real impact is unknown

slide-66
SLIDE 66

CAS & refactorings

slide-67
SLIDE 67

CAS & Cached builds

Caching builds cam make them less stable (reproducible) Content addressed store would help to catch unstable builds

slide-68
SLIDE 68

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.

slide-69
SLIDE 69

Questions ?