From 0b3c704fab4f7d0a08fe4e639f925c5f954e897b Mon Sep 17 00:00:00 2001 From: Quentin Dufour Date: Thu, 6 Apr 2023 18:20:30 +0200 Subject: [PATCH] cross compile and docker image --- flake.nix | 24 ++++++++++++++++++------ 1 file changed, 18 insertions(+), 6 deletions(-) diff --git a/flake.nix b/flake.nix index 34a87a7..2ae58bc 100644 --- a/flake.nix +++ b/flake.nix @@ -16,8 +16,8 @@ inherit system; overlays = [ nixuniverse ]; }; - albatros = pkgs.buildGoModule rec { - pname = "albatros"; + gopkg = arch: (pkgs.buildGoModule rec { + pname = "albatros-go-module"; version = "0.9"; src = ./.; CGO_ENABLED = 0; @@ -29,17 +29,29 @@ license = licenses.agpl3; platforms = platforms.linux; }; + }).overrideAttrs (old: old // { GOOS = "linux"; GOARCH = arch; }); + albatros = arch: pkgs.stdenv.mkDerivation { + pname = "albatros"; + version = "0.9"; + unpackPhase = "true"; + installPhase = '' + cp `find ${gopkg arch}/bin -name albatros` $out + ''; }; - docker = pkgs.dockerTools.buildImage { + docker = staticBin: pkgs.dockerTools.buildImage { name = "dxflrs/albatros"; config = { - Cmd = [ "${albatros}/bin/albatros" ]; + Cmd = [ "${staticBin}" ]; }; }; in { - packages.x86_64-linux.albatros = albatros; - packages.x86_64-linux.docker.albatros = docker; + packages.aarch64-linux.albatros = albatros "arm64" ; + packages.aarch64-linux.docker.albatros = docker self.packages.aarch64-linux.albatros; + packages.aarch64-linux.default = self.packages.aarch64-linux.albatros; + + packages.x86_64-linux.albatros = albatros "amd64"; + packages.x86_64-linux.docker.albatros = docker self.packages.x86_64-linux.albatros; packages.x86_64-linux.default = self.packages.x86_64-linux.albatros; devShell.x86_64-linux = pkgs.mkShell { buildInputs = [ pkgs.kaniko pkgs.manifest-tool ]; };