albatros/flake.nix

157 lines
5.7 KiB
Nix
Raw Permalink Normal View History

2023-03-16 11:24:23 +00:00
{
description = "Albatros";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs";
2023-05-04 09:00:37 +00:00
flake-utils.url = "github:numtide/flake-utils";
2023-03-16 11:24:23 +00:00
};
2023-05-04 09:00:37 +00:00
outputs = { self, nixpkgs, flake-utils }:
with flake-utils.lib; let
archmap = {
aarch64-linux = {
GOOS = "linux";
GOARCH = "arm64";
};
x86_64-linux = {
GOOS = "linux";
GOARCH = "amd64";
};
i686-linux = {
GOOS = "linux";
GOARCH = "386";
};
armv6l-linux = {
GOOS = "linux";
GOARCH = "arm";
};
};
in eachSystem [
# supported systems
system.x86_64-linux
system.i686-linux
system.armv6l-linux
system.aarch64-linux
] (targetHost: let
2023-04-11 08:45:14 +00:00
2023-05-04 09:00:37 +00:00
# Should be configurable
buildSystem = system.x86_64-linux;
# generic config
albaVersion = "0.9";
# nix repository
2023-03-16 11:24:23 +00:00
pkgs = import nixpkgs {
2023-05-04 09:00:37 +00:00
system = buildSystem;
# we don't use nixos cross environment as it is slow and not required
#crossSystem = {
# config = targetHost;
#};
2023-04-11 08:45:14 +00:00
overlays = [ ]; # we dropped the overlay we had, keep it as "skeleton".
2023-05-04 09:00:37 +00:00
};
2023-04-11 08:45:14 +00:00
2023-05-04 09:00:37 +00:00
# declare the go module of this package
albatrosProject = (pkgs.buildGoModule rec {
2023-04-06 16:20:30 +00:00
pname = "albatros-go-module";
2023-05-04 09:00:37 +00:00
version = albaVersion;
src = builtins.path {
path = ./.;
name = "albatros-source";
filter = (path: type: type == "directory" || (builtins.match ".*\\.(go|sum|mod)" path) != null);
};
2023-03-16 11:33:39 +00:00
CGO_ENABLED = 0;
2023-05-04 09:00:37 +00:00
vendorSha256 = "sha256-KYjXb882jWLFO6zilQXlrZorL9tw/+6njQNkB6E9Er4=";
dontCheck=true;
2023-04-20 10:27:14 +00:00
buildPhase = ''
2023-05-04 09:00:37 +00:00
go build bin/ci.go
go build -tags containers_image_docker_daemon_stub,containers_image_storage_stub,containers_image_openpgp bin/alba.go
2023-04-20 10:27:14 +00:00
'';
installPhase = ''
2023-05-04 09:00:37 +00:00
mkdir -p $out
cp alba ci $out/
2023-04-20 10:27:14 +00:00
'';
2023-03-16 11:24:23 +00:00
meta = with pkgs.lib; {
2023-05-04 09:00:37 +00:00
description = "albatros is a collection of tools to build your software supply chain";
homepage = "https://git.deuxfleurs.fr/Deuxfleurs/albatros";
2023-03-16 11:24:23 +00:00
license = licenses.agpl3;
platforms = platforms.linux;
};
2023-05-04 09:00:37 +00:00
}).overrideAttrs (old: old // (builtins.getAttr targetHost archmap));
# get only a statically compiled ci
ci = pkgs.stdenv.mkDerivation {
pname = "albatros-ci";
version = albaVersion;
dontUnpack = true;
dontBuild = true;
installPhase = ''
cp ${albatrosProject}/ci $out
'';
};
# get only a statically compiled alba tool
alba = pkgs.stdenv.mkDerivation {
pname = "albatros-alba";
version = albaVersion;
dontUnpack = true;
dontBuild = true;
installPhase = ''
cp ${albatrosProject}/alba $out
'';
};
2023-04-11 08:45:14 +00:00
# logic to build docker containers
2023-05-04 09:00:37 +00:00
container = pkgs.dockerTools.buildImage {
name = "dxflrs/albatros-ci";
architecture = (builtins.getAttr targetHost archmap).GOARCH;
2023-03-16 11:24:23 +00:00
config = {
2023-05-23 08:17:14 +00:00
Cmd = [ "${ci}" ];
Env = [
"SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
];
2023-03-16 11:24:23 +00:00
};
};
2023-04-06 16:20:30 +00:00
2023-05-04 09:00:37 +00:00
# Exposed content
in {
packages = {
inherit ci alba container;
default = ci;
2023-05-04 12:59:44 +00:00
# ci/cd stuff, to be run with `nix run .#build-static` and so on
build-static = pkgs.writeScriptBin "albatros-build-static" ''
nix build --print-build-logs .#packages.x86_64-linux.ci -o static/linux/amd64/ci
nix build --print-build-logs .#packages.i686-linux.ci -o static/linux/386/ci
nix build --print-build-logs .#packages.aarch64-linux.ci -o static/linux/arm64/ci
nix build --print-build-logs .#packages.armv6l-linux.ci -o static/linux/arm/ci
nix build --print-build-logs .#packages.x86_64-linux.alba -o static/linux/amd64/alba
nix build --print-build-logs .#packages.i686-linux.alba -o static/linux/386/alba
nix build --print-build-logs .#packages.aarch64-linux.alba -o static/linux/arm64/alba
nix build --print-build-logs .#packages.armv6l-linux.alba -o static/linux/arm/alba
'';
publish-static = pkgs.writeScriptBin "albatros-push-static" ''
RTAG=''${TAG:-$COMMIT}
echo "selected release tag is $RTAG"
${alba} static push -t albatros:$RTAG static/ 's3://download.deuxfleurs.org?endpoint=garage.deuxfleurs.fr&s3ForcePathStyle=true&region=garage' 1>&2
2023-05-04 12:59:44 +00:00
'';
build-container = pkgs.writeScriptBin "albatros-build-container" ''
nix build --print-build-logs .#packages.x86_64-linux.container -o docker/linux.amd64.tar.gz
nix build --print-build-logs .#packages.armv6l-linux.container -o docker/linux.arm.tar.gz
nix build --print-build-logs .#packages.aarch64-linux.container -o docker/linux.arm64.tar.gz
nix build --print-build-logs .#packages.i686-linux.container -o docker/linux.386.tar.gz
'';
publish-garage = pkgs.writeScriptBin "albatros-publish-garage" ''
RTAG=''${TAG:-$COMMIT}
echo "selected release tag is $RTAG"
${alba} container push -t albatros:$RTAG docker/ 's3://registry.deuxfleurs.org?endpoint=garage.deuxfleurs.fr&s3ForcePathStyle=true&region=garage' 1>&2
2023-05-04 12:59:44 +00:00
'';
publish-docker-hub = pkgs.writeScriptBin "albatros-publish-dockerhub" ''
RTAG=''${TAG:-$COMMIT}
echo "selected release tag is $RTAG"
2023-05-04 14:15:12 +00:00
${alba} container push -t albatros:$RTAG docker/ "docker://docker.io/dxflrs/albatros:$RTAG" 1>&2
2023-05-04 12:59:44 +00:00
'';
2023-03-16 11:24:23 +00:00
};
2023-05-04 09:00:37 +00:00
});
2023-03-16 11:24:23 +00:00
}