Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` [email protected]...

128
Functional Package Management with Guix Ludovic Court ` es [email protected] European Lisp Symposium 3 June 2013, Madrid

Transcript of Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` [email protected]...

Page 1: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Functional Package Management with Guix

Ludovic [email protected]

European Lisp Symposium3 June 2013, Madrid

Page 2: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

¡Hola!

( )guile

NixOS

Page 3: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

¡Hola!

( )guile

NixOS

Page 4: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

¡Hola!

( )guile

NixOS

Page 5: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

what’s Guix?http://gnu.org/software/guix/

I functional package managerI written in Guile SchemeI a new programming layer for Nix

I GNU’s package managerI foundation for the GNU SystemI GNU(/Linux) distro, est. 2012I focus on user freedom + consistent user interface

Page 6: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

what’s Guix?http://gnu.org/software/guix/

I functional package managerI written in Guile SchemeI a new programming layer for Nix

I GNU’s package managerI foundation for the GNU SystemI GNU(/Linux) distro, est. 2012I focus on user freedom + consistent user interface

Page 7: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

so what’s Nix?http://nixos.org/nix/

I another functional package managerI basis of GuixI foundation of NixOS GNU/Linux

I GNU/Linux distro, est. 2006I i686, x86 64, armv5telI ≈8000 packages

I more on Nix later...

Page 8: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

so what’s Nix?http://nixos.org/nix/

I another functional package managerI basis of GuixI foundation of NixOS GNU/Linux

I GNU/Linux distro, est. 2006I i686, x86 64, armv5telI ≈8000 packages

I more on Nix later...

Page 9: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Guix’s main contributions

1. package description language embedded in Scheme

I benefit from Guile’s tooling (compiler, i18n, etc.)I leverage Scheme macros for domain-specific languages

2. build programs written in Scheme

I more expressive than Bash (!)I a single programming language→ two-tier system

Page 10: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Guix’s main contributions

1. package description language embedded in SchemeI benefit from Guile’s tooling (compiler, i18n, etc.)I leverage Scheme macros for domain-specific languages

2. build programs written in Scheme

I more expressive than Bash (!)I a single programming language→ two-tier system

Page 11: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Guix’s main contributions

1. package description language embedded in SchemeI benefit from Guile’s tooling (compiler, i18n, etc.)I leverage Scheme macros for domain-specific languages

2. build programs written in SchemeI more expressive than Bash (!)I a single programming language→ two-tier system

Page 12: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 13: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 14: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user, unprivileged package installation

alice@foo$ guix package --install=gcc

alice@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.17

/nix/store/...-gcc-4.8.0

...

bob@foo$ guix package --install=gcc-4.7.3

bob@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.13

/nix/store/...-gcc-4.7.3

...

Page 15: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user, unprivileged package installation

alice@foo$ guix package --install=gcc

alice@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.17

/nix/store/...-gcc-4.8.0

...

bob@foo$ guix package --install=gcc-4.7.3

bob@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.13

/nix/store/...-gcc-4.7.3

...

Page 16: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user, unprivileged package installation

alice@foo$ guix package --install=gcc

alice@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.17

/nix/store/...-gcc-4.8.0

...

bob@foo$ guix package --install=gcc-4.7.3

bob@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.13

/nix/store/...-gcc-4.7.3

...

Page 17: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user, unprivileged package installation

alice@foo$ guix package --install=gcc

alice@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.17

/nix/store/...-gcc-4.8.0

...

bob@foo$ guix package --install=gcc-4.7.3

bob@foo$ guix gc --references ‘which gcc‘

/nix/store/...-glibc-2.13

/nix/store/...-gcc-4.7.3

...

Page 18: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transparent binary/source deployment

alice@foo$ guix package --install=emacs

The following package will be installed:

emacs-24.3 out /nix/store/...-emacs-24.3

The following files will be downloaded:

/nix/store/...-emacs-24.3

/nix/store/...-libxpm-3.5.10

/nix/store/...-libxext-1.3.1

/nix/store/...-libxaw-1.0.11

Page 19: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transparent binary/source deployment

alice@foo$ guix package --install=emacs

The following package will be installed:

emacs-24.3 out /nix/store/...-emacs-24.3

The following files will be downloaded:

/nix/store/...-libxext-1.3.1

/nix/store/...-libxaw-1.0.11

The following derivations will be built:

/nix/store/...-emacs-24.3.drv

/nix/store/...-libxpm-3.5.10.drv

Page 20: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transactional upgrades

$ guix package --upgrade

The following packages will be installed:

hop-2.4.0 out /nix/store/...-hop-2.4.0

gdb-7.6 out /nix/store/...-gdb-7.6

geiser-0.4 out /nix/store/...-geiser-0.4

glibc-2.17 out /nix/store/...-glibc-2.17

guile-2.0.9 out /nix/store/...-guile-2.0.9

...

(interrupted right in the middle)

$ hop --version ; guile --version

Hop-

guile (GNU Guile)

Page 21: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transactional upgrades

$ guix package --upgrade

The following packages will be installed:

hop-2.4.0 out /nix/store/...-hop-2.4.0

gdb-7.6 out /nix/store/...-gdb-7.6

geiser-0.4 out /nix/store/...-geiser-0.4

glibc-2.17 out /nix/store/...-glibc-2.17

guile-2.0.9 out /nix/store/...-guile-2.0.9

...

(interrupted right in the middle)

$ hop --version ; guile --version

Hop-2.4.0

guile (GNU Guile) 2.0.9

Page 22: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transactional upgrades

$ guix package --upgrade

The following packages will be installed:

hop-2.4.0 out /nix/store/...-hop-2.4.0

gdb-7.6 out /nix/store/...-gdb-7.6

geiser-0.4 out /nix/store/...-geiser-0.4

glibc-2.17 out /nix/store/...-glibc-2.17

guile-2.0.9 out /nix/store/...-guile-2.0.9

...

(interrupted right in the middle)

$ hop --version ; guile --version

Hop-

guile (GNU Guile)

Page 23: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transactional upgrades

$ guix package --upgrade

The following packages will be installed:

hop-2.4.0 out /nix/store/...-hop-2.4.0

gdb-7.6 out /nix/store/...-gdb-7.6

geiser-0.4 out /nix/store/...-geiser-0.4

glibc-2.17 out /nix/store/...-glibc-2.17

guile-2.0.9 out /nix/store/...-guile-2.0.9

...

(interrupted right in the middle)

$ hop --version ; guile --version

Hop-1.3.1

guile (GNU Guile) 1.8.8

Page 24: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

transactional upgrades

$ guix package --upgrade

The following packages will be installed:

hop-2.4.0 out /nix/store/...-hop-2.4.0

gdb-7.6 out /nix/store/...-gdb-7.6

geiser-0.4 out /nix/store/...-geiser-0.4

glibc-2.17 out /nix/store/...-glibc-2.17

guile-2.0.9 out /nix/store/...-guile-2.0.9

...

(interrupted right in the middle)

$ hop --version ; guile --version

Hop-1.3.1

guile (GNU Guile) 1.8.8

Page 25: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user rollback

$ emacs --version

GNU Emacs 24.2

$ guix package --upgrade=emacs

The following packages will be installed:

emacs-24.3.1 out /nix/store/...-emacs-24.3.1

...

$ emacs --version

Segmentation Fault

$ guix package --roll-back

switching from generation 43 to 42

$ emacs --version

GNU Emacs 24.2

Page 26: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user rollback

$ emacs --version

GNU Emacs 24.2

$ guix package --upgrade=emacs

The following packages will be installed:

emacs-24.3.1 out /nix/store/...-emacs-24.3.1

...

$ emacs --version

Segmentation Fault

$ guix package --roll-back

switching from generation 43 to 42

$ emacs --version

GNU Emacs 24.2

Page 27: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user rollback

$ emacs --version

GNU Emacs 24.2

$ guix package --upgrade=emacs

The following packages will be installed:

emacs-24.3.1 out /nix/store/...-emacs-24.3.1

...

$ emacs --version

Segmentation Fault

$ guix package --roll-back

switching from generation 43 to 42

$ emacs --version

GNU Emacs 24.2

Page 28: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user rollback

$ emacs --version

GNU Emacs 24.2

$ guix package --upgrade=emacs

The following packages will be installed:

emacs-24.3.1 out /nix/store/...-emacs-24.3.1

...

$ emacs --version

Segmentation Fault

$ guix package --roll-back

switching from generation 43 to 42

$ emacs --version

GNU Emacs 24.2

Page 29: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

per-user rollback

$ emacs --version

GNU Emacs 24.2

$ guix package --upgrade=emacs

The following packages will be installed:

emacs-24.3.1 out /nix/store/...-emacs-24.3.1

...

$ emacs --version

Segmentation Fault

$ guix package --roll-back

switching from generation 43 to 42

$ emacs --version

GNU Emacs 24.2

Page 30: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 31: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional packagemanagement

regarding the build & installation processof a package as a pure function

Page 32: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

controlling the build environment... as pioneered by Nix

1. one directory per installed package2. immutable installation directories3. undeclared dependencies invisible to the build process4. build performed in chroot, with separate UID, etc.

Page 33: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

the store

/nix/store

c6jbqm2...-emacs-24.1 bin emacs

smkabrb...-gnutls-3.0.18 lib libgnutls.so

l9w6773...-lsh-2.0.4

bin lsh

sbin lshd

im276ak...-glibc-2.16 lib libc.so.6

Page 34: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

42

/nix/storepp56i0a01si5...-user-env

binicecatssh

l9w6773m1msy...-openssh-4.6p1bin

sshrpdqxnilb0cg...-icecat-3.5.4

binicecat

Page 35: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

42

/nix/storepp56i0a01si5...-user-env

binicecatssh

l9w6773m1msy...-openssh-4.6p1bin

sshrpdqxnilb0cg...-icecat-3.5.4

binicecat

aqn3wygq9jzk...-openssh-5.2p1bin

ssh

guix package --upgrade=openssh

Page 36: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

42

/nix/storepp56i0a01si5...-user-env

binicecatssh

l9w6773m1msy...-openssh-4.6p1bin

sshrpdqxnilb0cg...-icecat-3.5.4

binicecat

aqn3wygq9jzk...-openssh-5.2p1bin

sshi3d9vh6d8ip1...-user-env

binsshicecat

guix package --upgrade=openssh

Page 37: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

42

43

/nix/storepp56i0a01si5...-user-env

binicecatssh

l9w6773m1msy...-openssh-4.6p1bin

sshrpdqxnilb0cg...-icecat-3.5.4

binicecat

aqn3wygq9jzk...-openssh-5.2p1bin

sshi3d9vh6d8ip1...-user-env

binsshicecat

guix package --upgrade=openssh

Page 38: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

42

43

/nix/storepp56i0a01si5...-user-env

binicecatssh

l9w6773m1msy...-openssh-4.6p1bin

sshrpdqxnilb0cg...-icecat-3.5.4

binicecat

aqn3wygq9jzk...-openssh-5.2p1bin

sshi3d9vh6d8ip1...-user-env

binsshicecat

guix package --upgrade=openssh

Page 39: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

43

/nix/storepp56i0a01si5...-user-env

binicecatssh

l9w6773m1msy...-openssh-4.6p1bin

sshrpdqxnilb0cg...-icecat-3.5.4

binicecat

aqn3wygq9jzk...-openssh-5.2p1bin

sshi3d9vh6d8ip1...-user-env

binsshicecat

Page 40: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

user environments

$PATH

/nix/.../profiles

current

43

/nix/store

rpdqxnilb0cg...-icecat-3.5.4bin

icecataqn3wygq9jzk...-openssh-5.2p1

binssh

i3d9vh6d8ip1...-user-envbin

sshicecat

guix gc

Page 41: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

store file names

$ guix build guile

/nix/store/ h2g4sc09h4... -guile-2.0.9

$ guix gc --references /nix/store/...-guile-2.0.9

/nix/store/4jl83jgzaac...-glibc-2.17

/nix/store/iplay43cg58...-libunistring-0.9.3

/nix/store/47p47v92cj9...-libffi-3.0.9

/nix/store/drkwck2j965...-gmp-5.0.5

...

Page 42: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

store file names

$ guix build guile

/nix/store/ h2g4sc09h4... -guile-2.0.9

$ guix gc --references /nix/store/...-guile-2.0.9

/nix/store/4jl83jgzaac...-glibc-2.17

/nix/store/iplay43cg58...-libunistring-0.9.3

/nix/store/47p47v92cj9...-libffi-3.0.9

/nix/store/drkwck2j965...-gmp-5.0.5

...

hash of all the dependencies

Page 43: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

store file names

$ guix build guile

/nix/store/ h2g4sc09h4... -guile-2.0.9

$ guix gc --references /nix/store/...-guile-2.0.9

/nix/store/4jl83jgzaac...-glibc-2.17

/nix/store/iplay43cg58...-libunistring-0.9.3

/nix/store/47p47v92cj9...-libffi-3.0.9

/nix/store/drkwck2j965...-gmp-5.0.5

...

Page 44: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

complete dependency specification

hello-2.3.drv

default-builder.sh

bash-4.0-p17.drv

bison-2.3.drv

gnum4-1.4.13.drv

curl-7.19.4.drv

openssl-0.9.8k.drv

zlib-1.2.3.drvperl-5.10.0.drv

binutils-2.19.1.drv

texinfo-4.13a.drv gmp-4.3.1.drv

mpfr-2.4.1.drv

lzma-4.32.7.drvncurses-5.7.drv gnum4-1.4.13.drv

linux-headers-2.6.28.5.drv

perl-5.10.0.drv

gawk-3.1.6.drv

coreutils-7.2.drv

gnupatch-2.5.4.drv gnutar-1.22.drv

findutils-4.4.1.drv

replace-2.24.drv gnused-4.1.5.drv gnumake-3.81.drv

diffutils-2.8.1.drv

gnugrep-2.5.4.drv

patchelf-0.4.drv gzip-1.3.12.drv

acl-2.2.47.drv

attr-2.4.43.drv

gettext-0.17.drv

libtool-2.2.6a.drv

perl-5.10.0.drvlzma-4.32.7.drvpcre-7.8.drv

bootstrap-glibc.drv

hello-2.3.tar.bz2.drv

stdenv-linux.drv

mirrors-list.drv

gcc-wrapper-4.3.3.drv

bash40-006.drv bash40-002.drvbash-4.0.tar.gz.drv

stdenv-linux-boot.drv

bzip2-1.0.5.drv

bash40-009.drv

bootstrap-tools.drv

bash40-012.drv bash40-008.drvbash40-013.drv bash40-007.drvbash40-003.drvbash40-001.drvbash40-017.drv bash40-015.drv bash40-005.drvbash40-016.drv bash40-010.drv bash40-004.drv bash40-014.drvbash40-011.drv

mirrors-list.drv

stdenv-linux-boot.drv

bison-2.3.tar.bz2.drv

gcc-wrapper-4.3.3.drv

m4-1.4.13.tar.bz2.drv curl-7.19.4.tar.bz2.drvopenssl-0.9.8k.tar.gz.drvperl-5.10.0.tar.gz.drv zlib-1.2.3.tar.gz.drv

gcc-4.3.3.drv

glibc-2.9.drv

gcc-core-4.3.3.tar.bz2.drv

stdenv-linux-boot.drv

gcc-g++-4.3.3.tar.bz2.drvtexinfo-4.13a.tar.lzma.drvgmp-4.3.1.tar.bz2.drv lzma-4.32.7.tar.gz.drvncurses-5.7.tar.gz.drvglibc-2.9-20081208.tar.bz2.drv

stdenv-linux-boot.drv

bootstrap-gcc.drv

bootstrap-gcc.drv

linux-2.6.28.5.tar.bz2.drv gawk-3.1.6.tar.bz2.drvcoreutils-7.2.tar.gz.drvbzip2-1.0.5.tar.gz.drv patch-2.5.4.tar.gz.drvacl_2.2.47-1.tar.gz.drvattr_2.4.43-1.tar.gz.drv tar-1.22.tar.bz2.drvgettext-0.17.tar.gz.drv findutils-4.4.1.tar.gz.drvreplace-2.24-src-11.11.tar.gz.drvsed-4.1.5.tar.gz.drv libtool-2.2.6a.tar.lzma.drv make-3.81.tar.bz2.drvdiffutils-2.8.1.tar.gz.drvmpfr-2.4.1.tar.bz2.drv grep-2.5.4.tar.bz2.drvpcre-7.8.tar.bz2.drvbinutils-2.19.1.tar.bz2.drv patchelf-0.4.tar.bz2.drv gzip-1.3.12.tar.gz.drv

builder.sh

prehook.sh builder.sh setup.sh

bzip2

bootstrap-tools.cpio.bz2.drv unpack-bootstrap-tools.sh

mkdir curl.bz2 cpio sh

write-mirror-list.sh

connect-timeout.patch

no-sys-dirs.patch setup-hook.sh

builder.sh ld-wrapper.sh gcc-wrapper.shutils.sh setup-hook.sh add-flags

pass-cxxcpp.patch builder.sh no-sys-dirs.patch

locale-override.patch rpcgen-path.patchbuilder.sh nss-skip-unavail.patch

prehook.sh

builder.sh implausible.patch

findutils-path.patch change_echo_path.patch

malloc.patch gettext-fix.patch impure-dirs.patchlog.patch

new-dtags.patch

gnulib-futimens.patch

download.sh ln

run-time dependencies inferred by conservative scanning

build-time dependencies of GNU Hello

Page 45: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

complete dependency specification

hello-2.3.drv

default-builder.sh

bash-4.0-p17.drv

bison-2.3.drv

gnum4-1.4.13.drv

curl-7.19.4.drv

openssl-0.9.8k.drv

zlib-1.2.3.drvperl-5.10.0.drv

binutils-2.19.1.drv

texinfo-4.13a.drv gmp-4.3.1.drv

mpfr-2.4.1.drv

lzma-4.32.7.drvncurses-5.7.drv gnum4-1.4.13.drv

linux-headers-2.6.28.5.drv

perl-5.10.0.drv

gawk-3.1.6.drv

coreutils-7.2.drv

gnupatch-2.5.4.drv gnutar-1.22.drv

findutils-4.4.1.drv

replace-2.24.drv gnused-4.1.5.drv gnumake-3.81.drv

diffutils-2.8.1.drv

gnugrep-2.5.4.drv

patchelf-0.4.drv gzip-1.3.12.drv

acl-2.2.47.drv

attr-2.4.43.drv

gettext-0.17.drv

libtool-2.2.6a.drv

perl-5.10.0.drvlzma-4.32.7.drvpcre-7.8.drv

bootstrap-glibc.drv

hello-2.3.tar.bz2.drv

stdenv-linux.drv

mirrors-list.drv

gcc-wrapper-4.3.3.drv

bash40-006.drv bash40-002.drvbash-4.0.tar.gz.drv

stdenv-linux-boot.drv

bzip2-1.0.5.drv

bash40-009.drv

bootstrap-tools.drv

bash40-012.drv bash40-008.drvbash40-013.drv bash40-007.drvbash40-003.drvbash40-001.drvbash40-017.drv bash40-015.drv bash40-005.drvbash40-016.drv bash40-010.drv bash40-004.drv bash40-014.drvbash40-011.drv

mirrors-list.drv

stdenv-linux-boot.drv

bison-2.3.tar.bz2.drv

gcc-wrapper-4.3.3.drv

m4-1.4.13.tar.bz2.drv curl-7.19.4.tar.bz2.drvopenssl-0.9.8k.tar.gz.drvperl-5.10.0.tar.gz.drv zlib-1.2.3.tar.gz.drv

gcc-4.3.3.drv

glibc-2.9.drv

gcc-core-4.3.3.tar.bz2.drv

stdenv-linux-boot.drv

gcc-g++-4.3.3.tar.bz2.drvtexinfo-4.13a.tar.lzma.drvgmp-4.3.1.tar.bz2.drv lzma-4.32.7.tar.gz.drvncurses-5.7.tar.gz.drvglibc-2.9-20081208.tar.bz2.drv

stdenv-linux-boot.drv

bootstrap-gcc.drv

bootstrap-gcc.drv

linux-2.6.28.5.tar.bz2.drv gawk-3.1.6.tar.bz2.drvcoreutils-7.2.tar.gz.drvbzip2-1.0.5.tar.gz.drv patch-2.5.4.tar.gz.drvacl_2.2.47-1.tar.gz.drvattr_2.4.43-1.tar.gz.drv tar-1.22.tar.bz2.drvgettext-0.17.tar.gz.drv findutils-4.4.1.tar.gz.drvreplace-2.24-src-11.11.tar.gz.drvsed-4.1.5.tar.gz.drv libtool-2.2.6a.tar.lzma.drv make-3.81.tar.bz2.drvdiffutils-2.8.1.tar.gz.drvmpfr-2.4.1.tar.bz2.drv grep-2.5.4.tar.bz2.drvpcre-7.8.tar.bz2.drvbinutils-2.19.1.tar.bz2.drv patchelf-0.4.tar.bz2.drv gzip-1.3.12.tar.gz.drv

builder.sh

prehook.sh builder.sh setup.sh

bzip2

bootstrap-tools.cpio.bz2.drv unpack-bootstrap-tools.sh

mkdir curl.bz2 cpio sh

write-mirror-list.sh

connect-timeout.patch

no-sys-dirs.patch setup-hook.sh

builder.sh ld-wrapper.sh gcc-wrapper.shutils.sh setup-hook.sh add-flags

pass-cxxcpp.patch builder.sh no-sys-dirs.patch

locale-override.patch rpcgen-path.patchbuilder.sh nss-skip-unavail.patch

prehook.sh

builder.sh implausible.patch

findutils-path.patch change_echo_path.patch

malloc.patch gettext-fix.patch impure-dirs.patchlog.patch

new-dtags.patch

gnulib-futimens.patch

download.sh ln

... down to the compiler’s compiler!

run-time dependenciesinferred by conservative scanning

build-time dependencies of GNU Hello

Page 46: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

complete dependency specification

hello-2.3

glibc-2.11

linux-headers-2.6.28.5

run-time dependencies inferred by conservative scanning

run-time dependencies of GNU Hello

Page 47: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional packaging summarized

I immutable software installationsI builds/installs have no side effectsI build & deployment ≡ calling a build functionI the store ≡ memoizationI garbage collection...

Page 48: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 49: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix is twofold

functional package deployment

I the storeI file name hashesI user environmentsI transactional upgrades, etc.I ...

Page 50: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix is twofold

functional package deployment

I the storeI file name hashesI user environmentsI transactional upgrades, etc.I ...

Nix packaging language

I to describe packagecomposition

I external DSLI dynamically-typed, lazyI easy integration of Bash

snippetsI ...

Page 51: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix multi-user setup

build processeschroot, separate UIDs

Bas

h,m

ake,

etc.

Bas

h,m

ake,

etc.

Bas

h,m

ake,

etc. Nix tools

interpreter

client lib

Nix build daemon

Page 52: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix multi-user setup

build processeschroot, separate UIDs

Bas

h,m

ake,

etc.

Bas

h,m

ake,

etc.

Bas

h,m

ake,

etc. Nix tools

interpreter

client lib

Nix build daemon RPCs

Page 53: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix multi-user setup

build processeschroot, separate UIDs

Bas

h,m

ake,

etc.

Bas

h,m

ake,

etc.

Bas

h,m

ake,

etc. Nix tools

interpreter

client lib

Nix build daemon RPCs

Page 54: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language build primitive

derivation {

name = "foo";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c" "echo hello > " $out " ];

}

; in derivation {

name = "bar";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c"

’’ mkdir -p "$out"

ln -s " ${dep} /some-result" "$out/my-result"

’’ ];

PATH = "${coreutils}/bin";

}

Page 55: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language build primitive

derivation {

name = "foo";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c" "echo hello > " $out " ];

}

; in derivation {

name = "bar";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c"

’’ mkdir -p "$out"

ln -s " ${dep} /some-result" "$out/my-result"

’’ ];

PATH = "${coreutils}/bin";

}

function call

/nix/store/...-foo

named arguments

Page 56: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language build primitive

let dep = derivation {

name = "foo";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c" "echo hello > " $out " ];

} ; in derivation {

name = "bar";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c"

’’ mkdir -p "$out"

ln -s " ${dep} /some-result" "$out/my-result"

’’ ];

PATH = "${coreutils}/bin";

}

Page 57: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language build primitive

let dep = derivation {

name = "foo";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c" "echo hello > " $out " ];

} ; in derivation {

name = "bar";

system = "x86 64-linux";

builder = "${./static-bash}";

args = [ "-c"

’’ mkdir -p "$out"

ln -s " ${dep} /some-result" "$out/my-result"

’’ ];

PATH = "${coreutils}/bin";

}

expands to /nix/store/...-foo

Page 58: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language high-level packaging

{ fetchurl, stdenv } :

stdenv . mkDerivation {

name = "hello-2.3";

src = fetchurl {

url = mirror://gnu/hello/hello-2.3.tar.bz2;

sha256 = "0c7vijq8y68...";

};

buildInputs = [ gettext ];

preCheck = "echo ’Test suite coming up!’";

meta = {

description = "Produces a friendly greeting";

homepage = http://www.gnu.org/software/hello/;

license = "GPLv3+";

};

}

function definition

formal parameters

function call

Page 59: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language high-level packaging

{ fetchurl, stdenv , gettext } :

stdenv . mkDerivation {

name = "hello-2.3";

src = fetchurl {

url = mirror://gnu/hello/hello-2.3.tar.bz2;

sha256 = "0c7vijq8y68...";

};

buildInputs = [ gettext ];

preCheck = "echo ’Test suite coming up!’";

meta = {

description = "Produces a friendly greeting";

homepage = http://www.gnu.org/software/hello/;

license = "GPLv3+";

};

}

dependency

gcc, make, etc.

Page 60: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix language high-level packaging

{ fetchurl, stdenv , gettext } :

stdenv . mkDerivation {

name = "hello-2.3";

src = fetchurl {

url = mirror://gnu/hello/hello-2.3.tar.bz2;

sha256 = "0c7vijq8y68...";

};

buildInputs = [ gettext ];

preCheck = "echo ’Test suite coming up!’";

meta = {

description = "Produces a friendly greeting";

homepage = http://www.gnu.org/software/hello/;

license = "GPLv3+";

};

}

Bash snippet

Page 61: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

and now for parentheses...

Page 62: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 63: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 64: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

The truth is that Lisp is not the rightlanguage for any particular problem.Rather, Lisp encourages one to attack anew problem by implementing newlanguages tailored to that problem.

– Albelson & Sussman, 1987

Page 65: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

from Nix...

functional package deployment

I the storeI file name hashesI user environmentsI transactional upgrades, etc.I ...

Nix packaging language

I to describe packagecomposition

I external DSLI dynamically-typed, lazyI easy integration of Bash

snippetsI ...

Page 66: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

from Nix to Guix

functional package deployment

I the storeI file name hashesI user environmentsI transactional upgrades, etc.I ...

Nix packaging language

I to describe packagecomposition

I external DSLI dynamically-typed, lazyI easy integration of Bash

snippetsI ...

reuse this

Scheme!

Scheme!

Page 67: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Guix architecture

build processeschroot, separate UIDs

Gui

le,m

ake,

etc.

Gui

le,m

ake,

etc.

Gui

le,m

ake,

etc. Guile

(guix packages)

(guix store)

Nix build daemon RPCs

Page 68: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

thesis

1. Scheme + EDSL at least as expressive asthe Nix language

2. Scheme better suited than the shell for buildprograms

3. Guix provides a unified & extensibleprogramming environment

Page 69: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 70: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

programming interface layers

1. declarative packaging layer2. Scheme build expressions3. derivation primitive (from Nix)

Page 71: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system)

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

Page 72: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system)

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

how do we reach thislevel of abstraction?

Page 73: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix’s derivation primitive in Scheme

(let* ((store (open-connection) )

(bash ( add-to-store store "static-bash"

#t "sha256"

"./static-bash")))

( derivation store "example-1.0"

"x86 64-linux"

bash

’("-c" "echo hello > $out")

’(("HOME" . "/homeless"))

’()))

=> "/nix/store/nsswy...-example-1.0 .drv "

=> #<derivation "example-1.0" ...>

Page 74: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix’s derivation primitive in Scheme

(let* ((store (open-connection) )

(bash ( add-to-store store "static-bash"

#t "sha256"

"./static-bash")))

( derivation store "example-1.0"

"x86 64-linux"

bash

’("-c" "echo hello > $out")

’(("HOME" . "/homeless"))

’()))

=> "/nix/store/nsswy...-example-1.0 .drv "

=> #<derivation "example-1.0" ...>

connect to the build daemon

Page 75: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix’s derivation primitive in Scheme

(let* ((store (open-connection) )

(bash ( add-to-store store "static-bash"

#t "sha256"

"./static-bash")))

( derivation store "example-1.0"

"x86 64-linux"

bash

’("-c" "echo hello > $out")

’(("HOME" . "/homeless"))

’()))

=> "/nix/store/nsswy...-example-1.0 .drv "

=> #<derivation "example-1.0" ...>

“intern” the file

/nix/store/...-static-bash

Page 76: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Nix’s derivation primitive in Scheme

(let* ((store (open-connection) )

(bash ( add-to-store store "static-bash"

#t "sha256"

"./static-bash")))

( derivation store "example-1.0"

"x86 64-linux"

bash

’("-c" "echo hello > $out")

’(("HOME" . "/homeless"))

’()))

=> "/nix/store/nsswy...-example-1.0 .drv "

=> #<derivation "example-1.0" ...>

compute “derivation”—i.e., build promise

Page 77: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build expressions

(let* ((store (open-connection) )

(builder ’( begin

(mkdir %output)

(call-with-output-file

(string-append %output "/test")

(lambda (p)

(display ’(hello guix) p)))))

(drv ( build-expression->derivation

store "foo" "x86 64-linux"

builder

’(("HOME" . "/nowhere")))))

( build-derivations store (list drv)))

Page 78: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build expressions

(let* ((store (open-connection) )

(builder ’( begin

(mkdir %output)

(call-with-output-file

(string-append %output "/test")

(lambda (p)

(display ’(hello guix) p)))))

(drv ( build-expression->derivation

store "foo" "x86 64-linux"

builder

’(("HOME" . "/nowhere")))))

( build-derivations store (list drv)))

build script, to be eval’d in chroot

Page 79: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build expressions

(let* ((store (open-connection) )

(builder ’( begin

(mkdir %output)

(call-with-output-file

(string-append %output "/test")

(lambda (p)

(display ’(hello guix) p)))))

(drv ( build-expression->derivation

store "foo" "x86 64-linux"

builder

’(("HOME" . "/nowhere")))))

( build-derivations store (list drv)))

compute derivation forthis builder, system,and env. vars

Page 80: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build expressions

(let* ((store (open-connection) )

(builder ’( begin

(mkdir %output)

(call-with-output-file

(string-append %output "/test")

(lambda (p)

(display ’(hello guix) p)))))

(drv ( build-expression->derivation

store "foo" "x86 64-linux"

builder

’(("HOME" . "/nowhere")))))

( build-derivations store (list drv)))

implicitly adds Guile asan input

Page 81: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build expressions

(let* ((store (open-connection) )

(builder ’( begin

(mkdir %output)

(call-with-output-file

(string-append %output "/test")

(lambda (p)

(display ’(hello guix) p)))))

(drv ( build-expression->derivation

store "foo" "x86 64-linux"

builder

’(("HOME" . "/nowhere")))))

( build-derivations store (list drv)))

build it!

Page 82: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system )

(inputs ‘(("gawk" , gawk )))

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

Page 83: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system )

(inputs ‘(("gawk" , gawk )))

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

dependencies

Page 84: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system )

(inputs ‘(("gawk" , gawk )))

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

dependencies

reference to a variable

Page 85: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system )

(inputs ‘(("gawk" , my-other-awk )))

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

reference to a variable

Page 86: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

declarative packaging layer

(define hello

(package

(name "hello")

(version "2.8")

(source (origin

(method url-fetch)

(uri (string-append

"http://ftp.gnu.org/.../hello-" version

".tar.gz"))

(sha256 (base32 "0wqd...dz6"))))(build-system gnu-build-system )

(inputs ‘(("gawk" , gawk )))

(synopsis "GNU Hello")

(description "Produce a friendly greeting.")

(home-page "http://www.gnu.org/software/hello/")

(license gpl3+)))

./configure && make install...

depends on gcc, make, bash, etc.

Page 87: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build-system protocol

(define gnu-build-system

(build-system (name ’gnu)

(description "./configure && make && make install")

(build gnu-build)

(cross-build gnu-cross-build)))

I python-build-system→ python setup.py

I perl-build-system→ perl Makefile.PL

I cmake-build-system→ cmake .

Page 88: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

build-system protocol

(define gnu-build-system

(build-system (name ’gnu)

(description "./configure && make && make install")

(build gnu-build)

(cross-build gnu-cross-build)))

I python-build-system→ python setup.py

I perl-build-system→ perl Makefile.PL

I cmake-build-system→ cmake .

Page 89: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

(use-modules (guix packages) (guix store)

(gnu packages base))

(define store

(open-connection) )

(package? hello)

=> #t

(define drv ( package-derivation store hello))

drv

=> "/nix/store/xyz...-hello-2.8.drv"

(build-derivations (list drv))

... daemon builds/downloads package on our behalf...

=> "/nix/store/pqr...-hello-2.8"

connect to the Nix build daemon

Page 90: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

(use-modules (guix packages) (guix store)

(gnu packages base))

(define store

(open-connection) )

(package? hello)

=> #t

(define drv ( package-derivation store hello))

drv

=> "/nix/store/xyz...-hello-2.8.drv"

(build-derivations (list drv))

... daemon builds/downloads package on our behalf...

=> "/nix/store/pqr...-hello-2.8"

compute “derivation”—i.e., build promise

Page 91: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

(use-modules (guix packages) (guix store)

(gnu packages base))

(define store

(open-connection) )

(package? hello)

=> #t

(define drv ( package-derivation store hello))

drv

=> "/nix/store/xyz...-hello-2.8.drv"

(build-derivations (list drv))

... daemon builds/downloads package on our behalf...

=> "/nix/store/pqr...-hello-2.8"

Page 92: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

(use-modules (guix packages) (guix store)

(gnu packages base))

(define store

(open-connection) )

(package? hello)

=> #t

(define drv ( package-derivation store hello))

drv

=> "/nix/store/xyz...-hello-2.8.drv"

(build-derivations (list drv))

... daemon builds/downloads package on our behalf...

=> "/nix/store/pqr...-hello-2.8"

Page 93: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

(use-modules (guix packages) (guix store)

(gnu packages base))

(define store

(open-connection) )

(package? hello)

=> #t

(define drv ( package-derivation store hello))

drv

=> "/nix/store/xyz...-hello-2.8.drv"

(build-derivations (list drv))

... daemon builds/downloads package on our behalf...=> "/nix/store/pqr...-hello-2.8"

Page 94: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

$ guix build hello

The following derivations will be built:

/nix/store/4gy79...-gawk-4.0.0.drv/nix/store/7m2r9...-hello-2.8.drv

.../nix/store/71aj1...-hello-2.8

Page 95: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

$ guix build hello

The following derivations will be built:

/nix/store/4gy79...-gawk-4.0.0.drv/nix/store/7m2r9...-hello-2.8.drv

.../nix/store/71aj1...-hello-2.8

Page 96: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

building packages

$ guix build --target=armel-linux-gnueabi hello

The following derivations will be built:

/nix/store/1gm99...-gcc-armel-linux-gnu-4.8.1.drv/nix/store/71ah1...-hello-2.8.drv

.../nix/store/7m2r9...-hello-2.8

Page 97: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

packages based on existing ones

(package ( inherit hello)

(version "2.7")

(source

(origin

(method url-fetch)

(uri "mirror://gnu/hello/hello-2.7.tar.gz")

(sha256

(base32 "7dqw3...")))))

copy fields from hello exceptfor version and source

Page 98: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package adapters

(define (static-package p)

;; Return a statically-linked variant of P.

(package (inherit p)

(arguments

‘(#:configure-flags ’("--disable-shared"

"LDFLAGS=-static")

,@(package-arguments p)))))

Page 99: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

system-dependent arguments

(define gawk

(package

(name "gawk")

(version "4.0.2")

(source (origin (method url-fetch)

(uri "http://ftp.gnu.org/...")

(sha256 (base32 "0sss..."))))

(build-system gnu-build-system)

(arguments

(if (string-prefix? "i686" ( %current-system ))

’(#:tests? #f) ; skip tests on 32-bit hosts

’()))

(inputs ‘(("libsigsegv" ,libsigsegv)))

(home-page "http://www.gnu.org/software/gawk/")

(synopsis "GNU Awk")))

Page 100: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

system-dependent arguments

(define gawk

(package

(name "gawk")

(version "4.0.2")

(source (origin (method url-fetch)

(uri "http://ftp.gnu.org/...")

(sha256 (base32 "0sss..."))))

(build-system gnu-build-system)

(arguments

(if (string-prefix? "i686" ( %current-system ))

’(#:tests? #f) ; skip tests on 32-bit hosts

’()))

(inputs ‘(("libsigsegv" ,libsigsegv)))

(home-page "http://www.gnu.org/software/gawk/")

(synopsis "GNU Awk")))

evaluated within the dynamicextent of package-derivation

dynamically-scopedparameter (SRFI-39)

Page 101: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

under the hood: fancy records(define-record-type* <package>

package make-package package?

(name package-name)

(version package-version)

(source package-source)

(build-system package-build-system)

(arguments package-arguments

(default ’()) ( thunked ))

(inputs package-inputs

(default ’()) (thunked))

;; ...

(location package-location

(default (current-source-location))))

Page 102: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

under the hood: fancy records(define-record-type* <package>

package make-package package?

(name package-name)

(version package-version)

(source package-source)

(build-system package-build-system)

(arguments package-arguments

(default ’()) ( thunked ))

(inputs package-inputs

(default ’()) (thunked))

;; ...

(location package-location

(default (current-source-location))))

enclose value in a thunk

generated macro

Page 103: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 104: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

builder side of gnu-build-system(define %standard-phases

‘((configure . ,configure)

(build . ,build)

;; ...))

(define* (gnu-build #:key (phases %standard-phases)

#:allow-other-keys

#:rest args)

;; Run all the PHASES in order, passing them ARGS.

(every (match-lambda

((name . proc)

(format #t "starting phase ‘~a’~%" name)

(let ((result (apply proc args)))

(format #t "phase ‘~a’ done~%" name)

result)))

phases))

Page 105: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

inserting a build phase

(define howdy

(package (inherit hello)

(arguments

’(#:phases

( alist-cons-after

’configure ’change-hello

(lambda* (#:key system #:allow-other-keys)

( substitute* "src/hello.c"

(("Hello, world!")

(string-append "Howdy! Running on "

system "."))))

%standard-phases )))))

Page 106: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

inserting a build phase

(define howdy

(package (inherit hello)

(arguments

’(#:phases

( alist-cons-after

’configure ’change-hello

(lambda* (#:key system #:allow-other-keys)

( substitute* "src/hello.c"

(("Hello, world!")

(string-append "Howdy! Running on "

system "."))))

%standard-phases )))))

builder-side expression

Page 107: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

inserting a build phase

(define howdy

(package (inherit hello)

(arguments

’(#:phases

( alist-cons-after

’configure ’change-hello

(lambda* (#:key system #:allow-other-keys)

( substitute* "src/hello.c"

(("Hello, world!")

(string-append "Howdy! Running on "

system "."))))

%standard-phases )))))

configure, build, check, install

add a phase before configure

Page 108: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

inserting a build phase

(define howdy

(package (inherit hello)

(arguments

’(#:phases

( alist-cons-after

’configure ’change-hello

(lambda* (#:key system #:allow-other-keys)

( substitute* "src/hello.c"

(("Hello, world!")

(string-append "Howdy! Running on "

system "."))))

%standard-phases )))))

patch things up a la sed

Page 109: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

downloading sources

(origin

(method url-fetch )

(uri (string-append "mirror://gnu/gcc/gcc-"

version "/gcc-" version

".tar.bz2"))

(sha256 (base32 "1hx9...")))

Page 110: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

downloading sources

(origin

(method url-fetch )

(uri (string-append "mirror://gnu/gcc/gcc-"

version "/gcc-" version

".tar.bz2"))

(sha256 (base32 "1hx9...")))

use Guile HTTP(S)/FTP client

Page 111: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

downloading sources

(origin

(method url-fetch )

(uri (string-append "mirror://gnu/gcc/gcc-"

version "/gcc-" version

".tar.bz2"))

(sha256 (base32 "1hx9...")))

use Guile HTTP(S)/FTP client

how is the very firsttarball downloaded?

Page 112: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

bootstrapping the distribution

0. statically-linked binaries of mkdir, tar, xz, bash, and Guile

1. derivation runs Bash script to untar Guile2. use Guile to download statically-linked binaries of GCC,

Binutils, libc, Coreutils et al., and Bash3. use that to build GNU Make4. ...

Page 113: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

bootstrapping the distribution

0. statically-linked binaries of mkdir, tar, xz, bash, and Guile1. derivation runs Bash script to untar Guile

2. use Guile to download statically-linked binaries of GCC,Binutils, libc, Coreutils et al., and Bash

3. use that to build GNU Make4. ...

Page 114: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

bootstrapping the distribution

0. statically-linked binaries of mkdir, tar, xz, bash, and Guile1. derivation runs Bash script to untar Guile2. use Guile to download statically-linked binaries of GCC,

Binutils, libc, Coreutils et al., and Bash

3. use that to build GNU Make4. ...

Page 115: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

bootstrapping the distribution

0. statically-linked binaries of mkdir, tar, xz, bash, and Guile1. derivation runs Bash script to untar Guile2. use Guile to download statically-linked binaries of GCC,

Binutils, libc, Coreutils et al., and Bash3. use that to build GNU Make4. ...

Page 116: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

functional package managementfeaturesfoundationsNix’s approach

from Nix to Guixrationaleprogramming interfacesbuilder-side code

discussion

Page 117: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

status

I API/language support for builds & compositionI builder-side libs equiv. to wget, find, grep, sed, etc.I expressive enough to build a variety of packages

Page 118: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

benefits of DSL embedding

1. Guile tools readily available

I libraries, macros, compiler, etc.I i18n support (for package descriptions)I development environment: Emacs + Geiser

2. simplified implementation of auxiliary tools

I off-line & on-line package auto-updaterI description synchronization with external DBI searching packages by keyword

Page 119: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

benefits of DSL embedding

1. Guile tools readily availableI libraries, macros, compiler, etc.I i18n support (for package descriptions)I development environment: Emacs + Geiser

2. simplified implementation of auxiliary toolsI off-line & on-line package auto-updaterI description synchronization with external DBI searching packages by keyword

Page 120: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

GNU/Linux distribution

I installable atop a running GNU/Linux systemI self-contained (pure!)I transactional upgrade/roll-back, pre-built binaries, etc.I ≈400 packages

I TeX Live, Xorg, GCC, ...I and 6 Scheme implementations! :-)

Page 121: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

pushing the limits: booting to Guile(expression->initrd

’(begin

(mkdir "/proc")

(mount "none" "/proc" "proc")

;; Load Linux kernel modules.

(let ((slurp (lambda (module)

(call-with-input-file

(string-append "/modules/" module)

get-bytevector-all))))

(for-each (compose load-linux-module slurp)

(list "md4.ko" "ecb.ko" "cifs.ko")))

;; Turn eth0 up.

(let ((sock (socket AF_INET SOCK_STREAM 0)))

(set-network-interface-flags sock "eth0" IFF_UP))

;; At last, the warm and friendly REPL.

(start-repl)))

Page 122: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

road map

I short-termI tweak more packages for cross-compilationI port to mips64el (N64), and armel (?)I more packages: GTK+ stack, applications

I medium-termI stand-alone, bootable distribution!I with NixOS-style whole-system configuration EDSLI with the Guile-powered DMD init system

Page 123: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

road map

I short-termI tweak more packages for cross-compilationI port to mips64el (N64), and armel (?)I more packages: GTK+ stack, applications

I medium-termI stand-alone, bootable distribution!I with NixOS-style whole-system configuration EDSLI with the Guile-powered DMD init system

Page 124: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

road map

I short-termI tweak more packages for cross-compilationI port to mips64el (N64), and armel (?)I more packages: GTK+ stack, applications

I medium-termI stand-alone, bootable distribution!I with NixOS-style whole-system configuration EDSLI with the Guile-powered DMD init system

Your help needed!

Page 125: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

the first no-compromise GNU distribution

Page 126: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

summary

I featuresI transactional upgrades; rollback; per-user profilesI full power of Guile to build & compose packagesI unified packaging development environment

I foundationsI purely functional package managementI packaging DSL embedded in SchemeI second tier: flexible builds programs in Scheme

Page 127: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

[email protected] http://gnu.org/software/guix/

Page 128: Ludovic Courtes` ludo@gnu · Functional Package Management with Guix Ludovic Courtes` ludo@gnu.org European Lisp Symposium 3 June 2013, Madrid

Copyright c© 2010, 2012, 2013 Ludovic Courtes [email protected] of user environments is:Copyright c© 2009 Eelco Dolstra [email protected] of other images included in this document is held by their respective owners.

This work is licensed under the Creative Commons Attribution-Share Alike 3.0 License. To view a copyof this license, visit http://creativecommons.org/licenses/by-sa/3.0/ or send a letter to CreativeCommons, 171 Second Street, Suite 300, San Francisco, California, 94105, USA.

At your option, you may instead copy, distribute and/or modify this document under the terms of theGNU Free Documentation License, Version 1.3 or any later version published by the Free SoftwareFoundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of thelicense is available at http://www.gnu.org/licenses/gfdl.html.

The source of this document is available from http://git.sv.gnu.org/cgit/guix/maintenance.git.