2023-03-13 16:32:23 +00:00
|
|
|
{
|
|
|
|
description = "Aerogramme";
|
|
|
|
|
|
|
|
inputs = {
|
2023-05-09 15:22:17 +00:00
|
|
|
nixpkgs.url = "github:NixOS/nixpkgs/master";
|
|
|
|
flake-utils.url = "github:numtide/flake-utils";
|
|
|
|
|
|
|
|
# this patched version of cargo2nix makes easier to use clippy for building
|
2023-03-13 16:32:23 +00:00
|
|
|
cargo2nix = {
|
|
|
|
type = "github";
|
|
|
|
owner = "Alexis211";
|
|
|
|
repo = "cargo2nix";
|
|
|
|
ref = "custom_unstable";
|
|
|
|
};
|
2023-05-09 15:22:17 +00:00
|
|
|
|
|
|
|
# use rust project builds
|
2023-05-09 13:39:29 +00:00
|
|
|
fenix.url = "github:nix-community/fenix/monthly";
|
2024-02-10 16:29:32 +00:00
|
|
|
|
|
|
|
# import alba releasing tool
|
2024-02-10 17:04:27 +00:00
|
|
|
albatros.url = "git+https://git.deuxfleurs.fr/Deuxfleurs/albatros.git?ref=main";
|
2023-03-13 16:32:23 +00:00
|
|
|
};
|
|
|
|
|
2024-02-10 17:04:27 +00:00
|
|
|
outputs = { self, nixpkgs, cargo2nix, flake-utils, fenix, albatros }:
|
2024-02-10 16:29:32 +00:00
|
|
|
let platformArtifacts = flake-utils.lib.eachSystem [
|
2023-05-09 13:39:29 +00:00
|
|
|
"x86_64-unknown-linux-musl"
|
|
|
|
"aarch64-unknown-linux-musl"
|
|
|
|
"armv6l-unknown-linux-musleabihf"
|
|
|
|
] (targetHost: let
|
2023-05-09 15:22:17 +00:00
|
|
|
|
|
|
|
# with fenix, we get builds from the rust project.
|
|
|
|
# they are done with an old version of musl (prior to 1.2.x that is used in NixOS),
|
|
|
|
# however musl has a breaking change from 1.1.x to 1.2.x on 32 bit systems.
|
|
|
|
# so we pin the lib to 1.1.x to avoid recompiling rust ourselves.
|
|
|
|
muslOverlay = self: super: {
|
|
|
|
musl = super.musl.overrideAttrs(old: if targetHost == "armv6l-unknown-linux-musleabihf" then rec {
|
|
|
|
pname = "musl";
|
|
|
|
version = "1.1.24";
|
|
|
|
src = builtins.fetchurl {
|
|
|
|
url = "https://musl.libc.org/releases/${pname}-${version}.tar.gz";
|
|
|
|
sha256 = "sha256:18r2a00k82hz0mqdvgm7crzc7305l36109c0j9yjmkxj2alcjw0k";
|
|
|
|
};
|
|
|
|
} else {});
|
|
|
|
};
|
|
|
|
|
2023-05-09 13:39:29 +00:00
|
|
|
pkgs = import nixpkgs {
|
|
|
|
system = "x86_64-linux"; # hardcoded as we will cross compile
|
|
|
|
crossSystem = {
|
|
|
|
config = targetHost; # here we cross compile
|
|
|
|
isStatic = true;
|
|
|
|
};
|
2023-05-09 15:22:17 +00:00
|
|
|
overlays = [
|
|
|
|
cargo2nix.overlays.default
|
|
|
|
muslOverlay
|
|
|
|
];
|
2023-05-09 13:39:29 +00:00
|
|
|
};
|
|
|
|
|
2023-05-09 15:22:17 +00:00
|
|
|
rustTarget = if targetHost == "armv6l-unknown-linux-musleabihf" then "arm-unknown-linux-musleabihf" else targetHost;
|
2023-05-10 14:01:29 +00:00
|
|
|
|
|
|
|
# release builds
|
|
|
|
rustRelease = pkgs.rustBuilder.makePackageSet({
|
2023-05-09 15:22:17 +00:00
|
|
|
packageFun = import ./Cargo.nix;
|
|
|
|
target = rustTarget;
|
2023-05-10 14:01:29 +00:00
|
|
|
release = true;
|
2024-01-24 14:21:55 +00:00
|
|
|
rustcLinkFlags = [ "--cfg" "tokio_unstable" ];
|
|
|
|
rustcBuildFlags = [ "--cfg" "tokio_unstable" ];
|
2023-05-09 13:39:29 +00:00
|
|
|
rustToolchain = with fenix.packages.x86_64-linux; combine [
|
|
|
|
minimal.cargo
|
|
|
|
minimal.rustc
|
2023-05-09 15:22:17 +00:00
|
|
|
targets.${rustTarget}.latest.rust-std
|
2023-05-09 13:39:29 +00:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2023-05-10 14:01:29 +00:00
|
|
|
# debug builds with clippy as the compiler (hack to speed up compilation)
|
|
|
|
debugBuildEnv = (drv:
|
|
|
|
''
|
|
|
|
${drv.setBuildEnv or ""}
|
|
|
|
echo
|
|
|
|
echo --- BUILDING WITH CLIPPY ---
|
|
|
|
echo
|
|
|
|
|
|
|
|
export NIX_RUST_BUILD_FLAGS="''${NIX_RUST_BUILD_FLAGS} --deny warnings"
|
2023-05-15 16:23:23 +00:00
|
|
|
export NIX_RUST_LINK_FLAGS="''${NIX_RUST_LINK_FLAGS} --deny warnings"
|
2023-05-10 14:01:29 +00:00
|
|
|
export RUSTC="''${CLIPPY_DRIVER}"
|
|
|
|
'');
|
2023-07-25 22:11:48 +00:00
|
|
|
|
2023-05-10 14:01:29 +00:00
|
|
|
rustDebug = pkgs.rustBuilder.makePackageSet({
|
2023-07-25 22:11:48 +00:00
|
|
|
packageFun = import ./Cargo.nix;
|
2023-05-10 14:01:29 +00:00
|
|
|
target = rustTarget;
|
|
|
|
release = false;
|
|
|
|
rustToolchain = with fenix.packages.x86_64-linux; combine [
|
|
|
|
default.cargo
|
|
|
|
default.rustc
|
|
|
|
default.clippy
|
|
|
|
targets.${rustTarget}.latest.rust-std
|
|
|
|
];
|
|
|
|
packageOverrides = pkgs: pkgs.rustBuilder.overrides.all ++ [
|
|
|
|
(pkgs.rustBuilder.rustLib.makeOverride {
|
|
|
|
name = "aerogramme";
|
|
|
|
overrideAttrs = drv: {
|
|
|
|
setBuildEnv = (debugBuildEnv drv);
|
|
|
|
};
|
|
|
|
})
|
2023-07-25 22:11:48 +00:00
|
|
|
(pkgs.rustBuilder.rustLib.makeOverride {
|
|
|
|
name = "smtp-message";
|
|
|
|
overrideAttrs = drv: {
|
|
|
|
/*setBuildEnv = (traceBuildEnv drv);
|
|
|
|
propagatedBuildInputs = drv.propagatedBuildInputs or [ ] ++ [
|
|
|
|
traceRust
|
|
|
|
];*/
|
|
|
|
};
|
|
|
|
})
|
2023-05-10 14:01:29 +00:00
|
|
|
];
|
|
|
|
});
|
|
|
|
|
2024-02-10 17:04:27 +00:00
|
|
|
|
|
|
|
crate = (rustRelease.workspace.aerogramme {});
|
|
|
|
|
2023-05-10 14:01:29 +00:00
|
|
|
# binary extract
|
2023-05-11 07:27:49 +00:00
|
|
|
bin = pkgs.stdenv.mkDerivation {
|
2024-02-10 17:04:27 +00:00
|
|
|
pname = "${crate.name}-bin";
|
|
|
|
version = crate.version;
|
|
|
|
dontUnpack = true;
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
|
|
cp ${crate.bin}/bin/aerogramme $out
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
# fhs extract
|
|
|
|
fhs = pkgs.stdenv.mkDerivation {
|
|
|
|
pname = "${crate.name}-fhs";
|
|
|
|
version = crate.version;
|
2023-05-11 07:27:49 +00:00
|
|
|
dontUnpack = true;
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
2024-01-25 10:35:33 +00:00
|
|
|
mkdir -p $out/bin
|
2024-02-10 17:04:27 +00:00
|
|
|
cp ${crate.bin}/bin/aerogramme $out/bin/
|
2023-05-11 07:27:49 +00:00
|
|
|
'';
|
|
|
|
};
|
2023-05-10 14:01:29 +00:00
|
|
|
|
|
|
|
# docker packaging
|
2023-05-11 07:27:49 +00:00
|
|
|
archMap = {
|
|
|
|
"x86_64-unknown-linux-musl" = {
|
|
|
|
GOARCH = "amd64";
|
|
|
|
};
|
|
|
|
"aarch64-unknown-linux-musl" = {
|
|
|
|
GOARCH = "arm64";
|
|
|
|
};
|
|
|
|
"armv6l-unknown-linux-musleabihf" = {
|
|
|
|
GOARCH = "arm";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
container = pkgs.dockerTools.buildImage {
|
|
|
|
name = "dxflrs/aerogramme";
|
|
|
|
architecture = (builtins.getAttr targetHost archMap).GOARCH;
|
2024-02-10 17:04:27 +00:00
|
|
|
copyToRoot = fhs;
|
2023-05-11 07:27:49 +00:00
|
|
|
config = {
|
2024-01-25 10:35:33 +00:00
|
|
|
Env = [ "PATH=/bin" ];
|
|
|
|
Cmd = [ "aerogramme" "--dev" "provider" "daemon" ];
|
2023-05-11 07:27:49 +00:00
|
|
|
};
|
|
|
|
};
|
2023-05-10 14:01:29 +00:00
|
|
|
|
2023-05-09 13:39:29 +00:00
|
|
|
in {
|
2024-02-10 17:04:27 +00:00
|
|
|
meta = {
|
|
|
|
version = crate.version;
|
|
|
|
};
|
2024-02-10 16:29:32 +00:00
|
|
|
packages = {
|
2024-02-13 09:32:11 +00:00
|
|
|
inherit fhs container;
|
2024-02-10 16:29:32 +00:00
|
|
|
debug = (rustDebug.workspace.aerogramme {}).bin;
|
|
|
|
aerogramme = bin;
|
|
|
|
default = self.packages.${targetHost}.aerogramme;
|
|
|
|
};
|
2023-05-09 13:39:29 +00:00
|
|
|
});
|
2024-02-10 17:04:27 +00:00
|
|
|
|
|
|
|
###
|
|
|
|
#
|
|
|
|
# RELEASE STUFF
|
|
|
|
#
|
|
|
|
###
|
2024-02-10 16:29:32 +00:00
|
|
|
gpkgs = import nixpkgs {
|
|
|
|
system = "x86_64-linux"; # hardcoded as we will cross compile
|
|
|
|
};
|
2024-02-10 17:04:27 +00:00
|
|
|
alba = albatros.packages.x86_64-linux.alba;
|
2024-02-10 16:29:32 +00:00
|
|
|
|
2024-02-13 09:32:11 +00:00
|
|
|
# Shell
|
|
|
|
shell = gpkgs.mkShell {
|
|
|
|
buildInputs = [
|
|
|
|
cargo2nix.packages.x86_64-linux.default
|
|
|
|
fenix.packages.x86_64-linux.minimal.toolchain
|
|
|
|
fenix.packages.x86_64-linux.rust-analyzer
|
|
|
|
];
|
|
|
|
shellHook = ''
|
|
|
|
echo "AEROGRAME DEVELOPMENT SHELL ${fenix.packages.x86_64-linux.minimal.rustc}"
|
|
|
|
export RUST_SRC_PATH="${fenix.packages.x86_64-linux.latest.rust-src}/lib/rustlib/src/rust/library"
|
|
|
|
export RUST_ANALYZER_INTERNALS_DO_NOT_USE='this is unstable'
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
2024-02-10 17:04:27 +00:00
|
|
|
# Used only to fetch the "version"
|
|
|
|
version = platformArtifacts.meta.x86_64-unknown-linux-musl.version;
|
|
|
|
|
|
|
|
build = gpkgs.writeScriptBin "aerogramme-build" ''
|
2024-02-10 16:29:32 +00:00
|
|
|
set -euxo pipefail
|
|
|
|
|
|
|
|
# static
|
|
|
|
nix build --print-build-logs .#packages.x86_64-unknown-linux-musl.aerogramme -o static/linux/amd64/aerogramme
|
|
|
|
nix build --print-build-logs .#packages.aarch64-unknown-linux-musl.aerogramme -o static/linux/arm64/aerogramme
|
|
|
|
nix build --print-build-logs .#packages.armv6l-unknown-linux-musleabihf.aerogramme -o static/linux/arm/aerogramme
|
|
|
|
|
|
|
|
# containers
|
|
|
|
nix build --print-build-logs .#packages.x86_64-unknown-linux-musl.container -o docker/linux.amd64.tar.gz
|
|
|
|
nix build --print-build-logs .#packages.aarch64-unknown-linux-musl.container -o docker/linux.arm64.tar.gz
|
|
|
|
nix build --print-build-logs .#packages.armv6l-unknown-linux-musleabihf.container -o docker/linux.arm.tar.gz
|
|
|
|
'';
|
2024-02-10 17:04:27 +00:00
|
|
|
|
|
|
|
push = gpkgs.writeScriptBin "aerogramme-publish" ''
|
|
|
|
set -euxo pipefail
|
|
|
|
|
|
|
|
${alba} static push -t aerogramme:${version} static/ 's3://download.deuxfleurs.org?endpoint=garage.deuxfleurs.fr&s3ForcePathStyle=true®ion=garage' 1>&2
|
|
|
|
${alba} container push -t aerogramme:${version} docker/ 's3://registry.deuxfleurs.org?endpoint=garage.deuxfleurs.fr&s3ForcePathStyle=true®ion=garage' 1>&2
|
|
|
|
${alba} container push -t aerogramme:${version} docker/ "docker://docker.io/dxflrs/aerogramme:$RTAG" 1>&2
|
|
|
|
'';
|
|
|
|
|
2024-02-10 16:29:32 +00:00
|
|
|
in
|
|
|
|
{
|
2024-02-13 09:32:11 +00:00
|
|
|
devShells.x86_64-linux.default = shell;
|
2024-02-10 16:29:32 +00:00
|
|
|
packages = {
|
|
|
|
x86_64-linux = {
|
2024-02-10 17:04:27 +00:00
|
|
|
inherit build push;
|
2024-02-10 16:29:32 +00:00
|
|
|
};
|
|
|
|
} // platformArtifacts.packages;
|
|
|
|
};
|
2023-03-13 16:32:23 +00:00
|
|
|
}
|