From 3b9f4792dc4184c55b2c14219a11a7b9c11d4e03 Mon Sep 17 00:00:00 2001 From: Philippe Loctaux Date: Fri, 17 Nov 2023 22:33:50 +0100 Subject: [PATCH] nix: copy assets in docker, need to finish env --- flake.nix | 37 +++++++++++++++++++++++++++++++++---- 1 file changed, 33 insertions(+), 4 deletions(-) diff --git a/flake.nix b/flake.nix index 102f6e0..7f9e07d 100644 --- a/flake.nix +++ b/flake.nix @@ -87,10 +87,30 @@ }); # Build crate - ezidam = craneLib.buildPackage (commonArgs // { + ezidamBinary = craneLib.buildPackage (commonArgs // { cargoArtifacts = ezidamClippy; }); + ezidamAssetTemplate = ./crates/ezidam/templates; + ezidamAssetStatic = ./crates/ezidam/static; + + ezidamAssets = [ + ezidamAssetTemplate + ezidamAssetStatic + ]; + + ezidam = pkgs.stdenv.mkDerivation { + inherit ezidamBinary ezidamAssets; + name = metadata.pname; + phases = [ "unpackPhase" "installPhase" ]; + dontUnpack = true; + installPhase = '' + mkdir -p $out + cp -rv $ezidamBinary $out + cp -rv $ezidamAssets $out + ''; + }; + # Docker image dockerImage = pkgs.dockerTools.buildLayeredImage { # Meta @@ -102,20 +122,29 @@ contents = pkgs.buildEnv { name = "image-root"; paths = [ - ezidam + ezidamBinary + ezidamAssets ]; pathsToLink = [ "/bin" ]; }; - # Container config config = { - Cmd = [ "${ezidam}/bin/ezidam" ]; + Cmd = [ "${ezidamBinary}/bin/ezidam" ]; + Env = [ + "EZIDAM_TEMPLATE_DIR=${ezidamAssetTemplate}" + "EZIDAM_STATIC_DIR=${ezidamAssetStatic}" + ]; }; }; in { + apps.default = { + type = "app"; + program = "${ezidamBinary}/bin/ezidam"; + }; + packages = { inherit ezidam dockerImage; default = ezidam;