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";
|
2023-03-13 16:32:23 +00:00
|
|
|
};
|
|
|
|
|
2023-05-09 13:39:29 +00:00
|
|
|
outputs = { self, nixpkgs, cargo2nix, flake-utils, fenix }:
|
|
|
|
flake-utils.lib.eachSystem [
|
|
|
|
"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
|
|
|
};
|
|
|
|
|
|
|
|
shell = pkgs.mkShell {
|
2023-03-13 16:32:23 +00:00
|
|
|
buildInputs = [
|
|
|
|
cargo2nix.packages.x86_64-linux.default
|
|
|
|
];
|
|
|
|
};
|
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;
|
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}"
|
|
|
|
'');
|
|
|
|
rustDebug = pkgs.rustBuilder.makePackageSet({
|
|
|
|
packageFun = import ./Cargo.nix;
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
})
|
|
|
|
];
|
|
|
|
});
|
|
|
|
|
|
|
|
# binary extract
|
2023-05-11 07:27:49 +00:00
|
|
|
bin = pkgs.stdenv.mkDerivation {
|
|
|
|
pname = "aerogramme-bin";
|
|
|
|
version = "0.0.1";
|
|
|
|
dontUnpack = true;
|
|
|
|
dontBuild = true;
|
|
|
|
installPhase = ''
|
|
|
|
cp ${(rustRelease.workspace.aerogramme {}).bin}/bin/aerogramme $out
|
|
|
|
'';
|
|
|
|
};
|
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;
|
|
|
|
config = {
|
|
|
|
Cmd = [ "${bin}" ];
|
|
|
|
};
|
|
|
|
};
|
2023-05-10 14:01:29 +00:00
|
|
|
|
2023-05-09 13:39:29 +00:00
|
|
|
in {
|
|
|
|
devShells.default = shell;
|
2023-05-10 14:01:29 +00:00
|
|
|
packages.debug = (rustDebug.workspace.aerogramme {}).bin;
|
2023-05-11 07:27:49 +00:00
|
|
|
packages.aerogramme = bin;
|
|
|
|
packages.container = container;
|
2023-05-09 13:39:29 +00:00
|
|
|
packages.default = self.packages.${targetHost}.aerogramme;
|
|
|
|
});
|
2023-03-13 16:32:23 +00:00
|
|
|
}
|