From 90c15edbc8c4b664704f4e205cffcfeff578f98c Mon Sep 17 00:00:00 2001 From: Alan Pearce Date: Fri, 30 Jun 2023 18:42:51 +0200 Subject: Build docker image --- flake.nix | 89 ++++++++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 65 insertions(+), 24 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index 9cf8588..e4067e5 100644 --- a/flake.nix +++ b/flake.nix @@ -1,38 +1,79 @@ { description = "My website, alanpearce.eu"; inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + inputs.flockenzeit.url = "github:balsoft/Flockenzeit"; inputs.flake-utils.url = "github:numtide/flake-utils"; inputs.flake-compat = { url = "github:edolstra/flake-compat"; flake = false; }; - outputs = { self, nixpkgs, flake-utils, flake-compat }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - packages = { - default = pkgs.stdenv.mkDerivation { - name = "alanpearce.eu"; - src = self; + outputs = { self, nixpkgs, flockenzeit, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem + (system: + let + pkgs = nixpkgs.legacyPackages.${system}; + nativeBuildInputs = with pkgs; [ + zola + nodePackages_latest.prettier + fd + brotli + gzip + zstd + git + ]; + in + rec { + packages = { + default = pkgs.stdenv.mkDerivation { + name = "alanpearce.eu"; + src = self; - enableParallelBuilding = true; - makeFlags = [ "PREFIX=$(out)" ]; + enableParallelBuilding = true; + makeFlags = [ "PREFIX=$(out)/public" ]; - nativeBuildInputs = with pkgs; [ - zola - nodePackages_latest.prettier - fd - brotli - gzip - zstd - git - ]; + inherit nativeBuildInputs; + + dontFixup = true; - dontFixup = true; + postInstall = '' + cp Caddyfile $out/ + ''; + }; + docker = pkgs.dockerTools.buildImage { + name = "alanpearce/website"; + fromImage = pkgs.dockerTools.pullImage { + imageName = "caddy"; + finalImageName = "caddy"; + finalImageTag = "2-alpine"; + imageDigest = "sha256:d4ca216d8dc515a49bc20fa22a449283ade6c8fc132eb6fa412ff351664d4917"; + sha256 = "auFzOG+6PSOVNXXXsRsEEThtIHJYM3JUkMQGcUt4cNQ="; + }; + created = flockenzeit.lib.ISO-8601 self.lastModified; + copyToRoot = pkgs.buildEnv { + name = "website"; + paths = with pkgs; [ + packages.default + nss.tools + ]; + pathsToLink = [ "/bin" "/public" ]; + }; + config = { + WorkingDir = "${packages.default}"; + ExposedPorts = { + "80/tcp" = { }; + }; + Volumes = { + "/data" = { }; + }; + }; + }; + }; + devShell = pkgs.mkShell { + buildInputs = [ + nativeBuildInputs + pkgs.flyctl + ]; }; - }; - }); + }); } -- cgit 1.4.1