clean the nix file

This commit is contained in:
Quentin 2023-04-11 10:45:14 +02:00
parent e09714fecf
commit d9facbb79c
Signed by: quentin
GPG Key ID: E9602264D639FF68
1 changed files with 26 additions and 16 deletions

View File

@ -6,16 +6,15 @@
outputs = { self, nixpkgs }:
let
# @FIXME probably not a good idea to hardcode it...
system = "x86_64-linux";
nixuniverse = import (builtins.fetchGit {
url = "https://git.deuxfleurs.fr/quentin/nixuniverse.git";
ref = "main";
rev = "e94fa51007c9a51ac233e4fcfca09249102f74c5";
});
pkgs = import nixpkgs {
inherit system;
overlays = [ nixuniverse ];
overlays = [ ]; # we dropped the overlay we had, keep it as "skeleton".
};
# declare the go module of this package, allow for cross compilation
gopkg = arch: (pkgs.buildGoModule rec {
pname = "albatros-go-module";
version = "0.9";
@ -30,7 +29,9 @@
platforms = platforms.linux;
};
}).overrideAttrs (old: old // { GOOS = "linux"; GOARCH = arch; });
albatros = arch: pkgs.stdenv.mkDerivation {
# logic to build static binaries
albatrosStaticBin = arch: pkgs.stdenv.mkDerivation {
pname = "albatros";
version = "0.9";
unpackPhase = "true";
@ -38,6 +39,8 @@
cp `find ${gopkg arch}/bin -name albatros` $out
'';
};
# logic to build docker containers
docker = staticBin: arch: pkgs.dockerTools.buildImage {
name = "dxflrs/albatros";
architecture = arch;
@ -45,16 +48,23 @@
Cmd = [ "${staticBin}" ];
};
};
# map nixos/llvm arch to golang arch
archmap = {
"aarch64-linux" = "arm64";
"x86_64-linux" = "amd64";
"i686-linux" = "386";
"armv6l-linux" = "arm";
};
# generate packages for each architecture
packages = builtins.mapAttrs (name: value: rec {
albatros = (albatrosStaticBin value);
docker.albatros = (docker albatros value);
default = albatros;
}) archmap;
in
{
packages.aarch64-linux.albatros = albatros "arm64" ;
packages.aarch64-linux.docker.albatros = docker self.packages.aarch64-linux.albatros "arm64";
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 "amd64";
packages.x86_64-linux.default = self.packages.x86_64-linux.albatros;
devShell.x86_64-linux = pkgs.mkShell { buildInputs = [ pkgs.kaniko pkgs.manifest-tool ]; };
inherit packages;
};
}