From dfcab61d0232a2525e9b13b2b49e9f932ccca385 Mon Sep 17 00:00:00 2001 From: Akshay Karle <1443108+akshaykarle@users.noreply.github.com> Date: Thu, 17 Oct 2024 15:45:40 +0100 Subject: [PATCH] allow building docker images from nix * https://nixos.wiki/wiki/Docker * https://lucabrunox.github.io/2016/04/cheap-docker-images-with-nix_15.html --- .gitignore | 4 +++- flake.nix | 12 +++++++++++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index b7c10b4..d738668 100644 --- a/.gitignore +++ b/.gitignore @@ -160,4 +160,6 @@ cython_debug/ .idea/ .direnv/ -file_uploads/ \ No newline at end of file +file_uploads/ +# nix build results for docker and other packages +result \ No newline at end of file diff --git a/flake.nix b/flake.nix index 1c1cdb7..b7d6bf6 100644 --- a/flake.nix +++ b/flake.nix @@ -61,9 +61,18 @@ (final: _: { myapp = final.callPackage myapp { }; }) ]; }; + # build docker using nix to have smaller images. Inspiration from + # https://lucabrunox.github.io/2016/04/cheap-docker-images-with-nix_15.html + buildImage = pkgs.dockerTools.buildLayeredImage { + name = "pii"; + tag = "latest"; + created = "now"; + config.Entrypoint = [ "${pkgs.myapp}/bin/cli" ]; + }; in { packages.default = pkgs.myapp; + packages.dockerImage = buildImage; apps.default = { type = "app"; @@ -79,8 +88,9 @@ default = pkgs.mkShell { inputsFrom = [ pkgs.myapp ]; packages = [ - pkgs.vault + pkgs.docker pkgs.jq + pkgs.vault ]; };