Top Banner
Packaging services with Nix By Jonas Chevalier (aka. zimbatm)
17

Packaging Services with Nix

Jan 21, 2018

Download

Software

Outlyer
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Packaging Services with Nix

Packaging services with Nix

By Jonas Chevalier (aka. zimbatm)

Page 2: Packaging Services with Nix

Hi !

Page 3: Packaging Services with Nix

Real-world experience

“Excel on steroids”

http://www.alphasheets.com/

● Mono-repo

● Frontend written in React-js

● Backend written in Haskell +

python + Java + R

● Deploying on Kubernetes

Page 4: Packaging Services with Nix

What is Nix?

Pure build system + Functional language

≃Composable + Reproducible builds

https://nixos.org/nix/

Page 5: Packaging Services with Nix

Composable? Reproducible?

Key: “/nix/store/${sha256(build inputs)}”

Value: sandbox-build(build inputs)

=> tree

Page 6: Packaging Services with Nix

Language?

{ lib, mkYarnPackage, srcPath ? ../../frontend }:

mkYarnPackage {

src = srcPath;

packageJson = srcPath + "/package.json";

yarnLock = srcPath + "/yarn.lock";

buildPhase = ''

yarn build

'';

installPhase = ''

mkdir -p $out/var

cp -r dist/ $out/var/www

'';

}

Page 7: Packaging Services with Nix

Nixpkgs

https://github.com/nixos/nixpkgs

~12k packages

Actively maintained w/ security updates

Binary cache

Page 8: Packaging Services with Nix

TODO apphttps://github.com/numtide/todo

mvc-nix

Use TodoMvc as an example

Page 9: Packaging Services with Nix

CI / CD pipeline

Monorepo -> Docker image -> Push to registry -> Deploy changes

Page 10: Packaging Services with Nix

What do we want?

CI

☐ Only build what has changed

☐ Run tests when the code has changed

☐ Build containers from each services

☐ Only ship the runtime dependencies

☐ Manage security updates

Developer

☐ Application dependencies available

☐ Reduced dev/prod parity for debugging

☐ Access to pre-built binaries

Page 11: Packaging Services with Nix

DemoWish me luck

Page 12: Packaging Services with Nix

What do we get?

CI

☑ Only build what has changed

☑ Run tests on all the code that has changed

☑ Push containers to registry

☑ Only ship the runtime dependencies

☑ Manage security updates

Developer

☑ Application dependencies available

☑ Reduced dev/prod parity for debugging

☑ Access to pre-built binaries

Page 13: Packaging Services with Nix

Some downsides

● Not mainstream yet, less StackOverflow juice

● Developers are now required to install Nix

● Limited incremental builds compared to language-specific

● Missing tool to cull the container images

● Nix slower than Yarn on fetch

Page 14: Packaging Services with Nix

The

endQuestions ?

Page 15: Packaging Services with Nix

Thanks

https://zimbatm.com/

https://twitter.com/zimbatm/

https://github.com/numtide/todomvc-nix

Page 16: Packaging Services with Nix

Docker Problems

● Unnecessary rebuilds

○ With shared libraries

● Handle security updates

● Only run tests for components that change

● Minimal containers, don’t ship build dependencies

● Developer dependencies

● Dockerfiles are not composable

Page 17: Packaging Services with Nix