wip use naersk but doesn't split build in many derivations
Some checks failed
ci/woodpecker/push/debug Pipeline failed
Some checks failed
ci/woodpecker/push/debug Pipeline failed
This commit is contained in:
parent
39ac034de5
commit
40c2891ccd
3 changed files with 198 additions and 118 deletions
109
flake.lock
generated
109
flake.lock
generated
|
@ -1,28 +1,21 @@
|
||||||
{
|
{
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"cargo2nix": {
|
"fenix": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-compat": [
|
"nixpkgs": "nixpkgs",
|
||||||
"flake-compat"
|
"rust-analyzer-src": "rust-analyzer-src"
|
||||||
],
|
|
||||||
"flake-utils": "flake-utils",
|
|
||||||
"nixpkgs": [
|
|
||||||
"nixpkgs"
|
|
||||||
],
|
|
||||||
"rust-overlay": "rust-overlay"
|
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1705129117,
|
"lastModified": 1736836313,
|
||||||
"narHash": "sha256-LgdDHibvimzYhxBK3kxCk2gAL7k4Hyigl5KI0X9cijA=",
|
"narHash": "sha256-zdZ7/T6yG0/hzoVOiNpDiR/sW3zR6oSMrfIFJK2BrrE=",
|
||||||
"owner": "cargo2nix",
|
"owner": "nix-community",
|
||||||
"repo": "cargo2nix",
|
"repo": "fenix",
|
||||||
"rev": "ae19a9e1f8f0880c088ea155ab66cee1fa001f59",
|
"rev": "056c9393c821a4df356df6ce7f14c722dc8717ec",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "cargo2nix",
|
"owner": "nix-community",
|
||||||
"repo": "cargo2nix",
|
"repo": "fenix",
|
||||||
"rev": "ae19a9e1f8f0880c088ea155ab66cee1fa001f59",
|
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
@ -41,22 +34,54 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"flake-utils": {
|
"naersk": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs_2"
|
||||||
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1659877975,
|
"lastModified": 1736429655,
|
||||||
"narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=",
|
"narHash": "sha256-BwMekRuVlSB9C0QgwKMICiJ5EVbLGjfe4qyueyNQyGI=",
|
||||||
"owner": "numtide",
|
"owner": "nix-community",
|
||||||
"repo": "flake-utils",
|
"repo": "naersk",
|
||||||
"rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0",
|
"rev": "0621e47bd95542b8e1ce2ee2d65d6a1f887a13ce",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "numtide",
|
"owner": "nix-community",
|
||||||
"repo": "flake-utils",
|
"ref": "master",
|
||||||
|
"repo": "naersk",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1736701207,
|
||||||
|
"narHash": "sha256-jG/+MvjVY7SlTakzZ2fJ5dC3V1PrKKrUEOEE30jrOKA=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "ed4a395ea001367c1f13d34b1e01aa10290f67d6",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixos-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_2": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 0,
|
||||||
|
"narHash": "sha256-Pzyb+YNG5u3zP79zoi8HXYMs15Q5dfjDgwCdUI5B0nY=",
|
||||||
|
"path": "/nix/store/4hpdrd3qvj7nks3rrimqm2jdmcga8isc-source",
|
||||||
|
"type": "path"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"id": "nixpkgs",
|
||||||
|
"type": "indirect"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"nixpkgs_3": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1736692550,
|
"lastModified": 1736692550,
|
||||||
"narHash": "sha256-7tk8xH+g0sJkKLTJFOxphJxxOjMDFMWv24nXslaU2ro=",
|
"narHash": "sha256-7tk8xH+g0sJkKLTJFOxphJxxOjMDFMWv24nXslaU2ro=",
|
||||||
|
@ -74,34 +99,26 @@
|
||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"cargo2nix": "cargo2nix",
|
"fenix": "fenix",
|
||||||
"flake-compat": "flake-compat",
|
"flake-compat": "flake-compat",
|
||||||
"flake-utils": [
|
"naersk": "naersk",
|
||||||
"cargo2nix",
|
"nixpkgs": "nixpkgs_3"
|
||||||
"flake-utils"
|
|
||||||
],
|
|
||||||
"nixpkgs": "nixpkgs"
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-analyzer-src": {
|
||||||
"inputs": {
|
"flake": false,
|
||||||
"nixpkgs": [
|
|
||||||
"cargo2nix",
|
|
||||||
"nixpkgs"
|
|
||||||
]
|
|
||||||
},
|
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1736649126,
|
"lastModified": 1736690231,
|
||||||
"narHash": "sha256-XCw5sv/ePsroqiF3lJM6Y2X9EhPdHeE47gr3Q8b0UQw=",
|
"narHash": "sha256-g9gyxX+F6CrkT5gRIMKPnCPom0o9ZDzYnzzeNF86D6Q=",
|
||||||
"owner": "oxalica",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-analyzer",
|
||||||
"rev": "162ab0edc2936508470199b2e8e6c444a2535019",
|
"rev": "8364ef299790cb6ec22b9e09e873c97dbe9f2cb5",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
"owner": "oxalica",
|
"owner": "rust-lang",
|
||||||
"repo": "rust-overlay",
|
"ref": "nightly",
|
||||||
"rev": "162ab0edc2936508470199b2e8e6c444a2535019",
|
"repo": "rust-analyzer",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
207
flake.nix
207
flake.nix
|
@ -2,92 +2,155 @@
|
||||||
description =
|
description =
|
||||||
"Garage, an S3-compatible distributed object store for self-hosted deployments";
|
"Garage, an S3-compatible distributed object store for self-hosted deployments";
|
||||||
|
|
||||||
|
# Cross-compilation logic from here:
|
||||||
|
# https://mediocregopher.com/posts/x-compiling-rust-with-nix
|
||||||
|
# Thank you so much!!
|
||||||
|
|
||||||
# Nixpkgs 24.11 as of 2025-01-12 has rustc v1.82
|
# Nixpkgs 24.11 as of 2025-01-12 has rustc v1.82
|
||||||
inputs.nixpkgs.url =
|
inputs.nixpkgs.url =
|
||||||
"github:NixOS/nixpkgs/7c4869c47090dd7f9f1bdfb49a22aea026996815";
|
"github:NixOS/nixpkgs/7c4869c47090dd7f9f1bdfb49a22aea026996815";
|
||||||
|
|
||||||
inputs.flake-compat.url = "github:nix-community/flake-compat";
|
inputs.flake-compat.url = "github:nix-community/flake-compat";
|
||||||
|
|
||||||
inputs.cargo2nix = {
|
inputs.fenix.url = "github:nix-community/fenix";
|
||||||
# As of 2022-10-18: two small patches over unstable branch, one for clippy and one to fix feature detection
|
inputs.naersk.url = "github:nix-community/naersk/master";
|
||||||
#url = "github:Alexis211/cargo2nix/a7a61179b66054904ef6a195d8da736eaaa06c36";
|
|
||||||
|
|
||||||
# As of 2023-04-25:
|
outputs = { self, nixpkgs, fenix, naersk, ... }:
|
||||||
# - my two patches were merged into unstable (one for clippy and one to "fix" feature detection)
|
let
|
||||||
# - rustc v1.66
|
buildTargets = {
|
||||||
# url = "github:cargo2nix/cargo2nix/8fb57a670f7993bfc24099c33eb9c5abb51f29a2";
|
"x86_64-linux" = {
|
||||||
|
crossSystemConfig = "x86_64-unknown-linux-musl";
|
||||||
|
rustTarget = "x86_64-unknown-linux-musl";
|
||||||
|
};
|
||||||
|
|
||||||
# Mainline cargo2nix as of of 2025-01-12 (branch release-0.11.0)
|
"i686-linux" = {
|
||||||
url = "github:cargo2nix/cargo2nix/ae19a9e1f8f0880c088ea155ab66cee1fa001f59";
|
crossSystemConfig = "i686-unknown-linux-musl";
|
||||||
|
rustTarget = "i686-unknown-linux-musl";
|
||||||
|
};
|
||||||
|
|
||||||
# Rust overlay as of 2025-01-12
|
"aarch64-linux" = {
|
||||||
inputs.rust-overlay.url =
|
crossSystemConfig = "aarch64-unknown-linux-musl";
|
||||||
"github:oxalica/rust-overlay/162ab0edc2936508470199b2e8e6c444a2535019";
|
rustTarget = "aarch64-unknown-linux-musl";
|
||||||
|
};
|
||||||
|
|
||||||
inputs.nixpkgs.follows = "nixpkgs";
|
# Old Raspberry Pi's
|
||||||
inputs.flake-compat.follows = "flake-compat";
|
"armv6l-linux" = {
|
||||||
};
|
crossSystemConfig = "armv6l-unknown-linux-musleabihf";
|
||||||
|
rustTarget = "arm-unknown-linux-musleabihf";
|
||||||
|
};
|
||||||
|
};
|
||||||
|
|
||||||
inputs.flake-utils.follows = "cargo2nix/flake-utils";
|
# eachSystem [system] (system: ...)
|
||||||
|
#
|
||||||
|
# Returns an attrset with a key for every system in the given array, with
|
||||||
|
# the key's value being the result of calling the callback with that key.
|
||||||
|
eachSystem = supportedSystems: callback: builtins.foldl'
|
||||||
|
(overall: system: overall // { ${system} = callback system; })
|
||||||
|
{}
|
||||||
|
supportedSystems;
|
||||||
|
|
||||||
outputs = { self, nixpkgs, cargo2nix, flake-utils, ... }:
|
# eachCrossSystem [system] (buildSystem: targetSystem: ...)
|
||||||
let
|
#
|
||||||
git_version = self.lastModifiedDate;
|
# Returns an attrset with a key "$buildSystem.cross-$targetSystem" for
|
||||||
compile = import ./nix/compile.nix;
|
# every combination of the elements of the array of system strings. The
|
||||||
in
|
# value of the attrs will be the result of calling the callback with each
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
# combination.
|
||||||
let
|
#
|
||||||
pkgs = nixpkgs.legacyPackages.${system};
|
# There will also be keys "$system.default", which are aliases of
|
||||||
in
|
# "$system.cross-$system" for every system.
|
||||||
{
|
#
|
||||||
packages =
|
eachCrossSystem = supportedSystems: callback:
|
||||||
let
|
eachSystem supportedSystems (buildSystem: builtins.foldl'
|
||||||
packageFor = target: (compile {
|
(inner: targetSystem: inner // {
|
||||||
inherit system git_version target;
|
"cross-${targetSystem}" = callback buildSystem targetSystem;
|
||||||
pkgsSrc = nixpkgs;
|
})
|
||||||
cargo2nixOverlay = cargo2nix.overlays.default;
|
{ default = callback buildSystem buildSystem; }
|
||||||
release = true;
|
supportedSystems
|
||||||
}).workspace.garage { compileMode = "build"; };
|
);
|
||||||
in
|
|
||||||
{
|
mkPkgs = buildSystem: targetSystem: import nixpkgs ({
|
||||||
# default = native release build
|
system = buildSystem;
|
||||||
default = packageFor null;
|
} // (if targetSystem == null then {} else {
|
||||||
# other = cross-compiled, statically-linked builds
|
# The nixpkgs cache doesn't have any packages where cross-compiling has
|
||||||
amd64 = packageFor "x86_64-unknown-linux-musl";
|
# been enabled, even if the target platform is actually the same as the
|
||||||
i386 = packageFor "i686-unknown-linux-musl";
|
# build platform (and therefore it's not really cross-compiling). So we
|
||||||
arm64 = packageFor "aarch64-unknown-linux-musl";
|
# only set up the cross-compiling config if the target platform is
|
||||||
arm = packageFor "armv6l-unknown-linux-musl";
|
# different.
|
||||||
|
crossSystem.config = buildTargets.${targetSystem}.crossSystemConfig;
|
||||||
|
}));
|
||||||
|
|
||||||
|
in {
|
||||||
|
packages = eachCrossSystem
|
||||||
|
(builtins.attrNames buildTargets)
|
||||||
|
(buildSystem: targetSystem: let
|
||||||
|
pkgs = mkPkgs buildSystem null;
|
||||||
|
pkgsCross = mkPkgs buildSystem targetSystem;
|
||||||
|
rustTarget = buildTargets.${targetSystem}.rustTarget;
|
||||||
|
|
||||||
|
# TODO I'd prefer to use the toolchain file
|
||||||
|
# https://github.com/nix-community/fenix/issues/123
|
||||||
|
#toolchain = fenix.packages.${buildSystem}.fromToolchainFile {
|
||||||
|
# file = ./rust-toolchain.toml;
|
||||||
|
# sha256 = "sha256-LU4C/i+maIOqBZagUaXpFyWZyOVfQ3Ah5/JTz7v6CG4=";
|
||||||
|
#};
|
||||||
|
|
||||||
|
fenixPkgs = fenix.packages.${buildSystem};
|
||||||
|
|
||||||
|
mkToolchain = fenixPkgs: fenixPkgs.toolchainOf {
|
||||||
|
# TODO change compiler to stable
|
||||||
|
channel = "1.77";
|
||||||
|
sha256 = "sha256-7QfkHty6hSrgNM0fspycYkRcB82eEqYa4CoAJ9qA3tU=";
|
||||||
};
|
};
|
||||||
|
|
||||||
# ---- developpment shell, for making native builds only ----
|
toolchain = fenixPkgs.combine [
|
||||||
devShells =
|
(mkToolchain fenixPkgs).rustc
|
||||||
let
|
(mkToolchain fenixPkgs).cargo
|
||||||
shellWithPackages = (packages: (compile {
|
(mkToolchain fenixPkgs.targets.${rustTarget}).rust-std
|
||||||
inherit system git_version;
|
];
|
||||||
pkgsSrc = nixpkgs;
|
|
||||||
cargo2nixOverlay = cargo2nix.overlays.default;
|
|
||||||
}).workspaceShell { inherit packages; });
|
|
||||||
in
|
|
||||||
{
|
|
||||||
default = shellWithPackages
|
|
||||||
(with pkgs; [
|
|
||||||
rustfmt
|
|
||||||
clang
|
|
||||||
mold
|
|
||||||
]);
|
|
||||||
|
|
||||||
# import the full shell using `nix develop .#full`
|
buildPackageAttrs = if
|
||||||
full = shellWithPackages (with pkgs; [
|
builtins.hasAttr "makeBuildPackageAttrs" buildTargets.${targetSystem}
|
||||||
rustfmt
|
then
|
||||||
rust-analyzer
|
buildTargets.${targetSystem}.makeBuildPackageAttrs pkgsCross
|
||||||
clang
|
else
|
||||||
mold
|
{};
|
||||||
# ---- extra packages for dev tasks ----
|
|
||||||
cargo-audit
|
naersk-lib = pkgs.callPackage naersk {
|
||||||
cargo-outdated
|
cargo = toolchain;
|
||||||
cargo-machete
|
rustc = toolchain;
|
||||||
nixpkgs-fmt
|
|
||||||
]);
|
|
||||||
};
|
};
|
||||||
});
|
|
||||||
|
in
|
||||||
|
naersk-lib.buildPackage (buildPackageAttrs // rec {
|
||||||
|
name = "garage";
|
||||||
|
pname = "garage";
|
||||||
|
src = ./.;
|
||||||
|
strictDeps = true;
|
||||||
|
doCheck = false;
|
||||||
|
release = false; # for now
|
||||||
|
|
||||||
|
# TODO co uld be removed ?
|
||||||
|
OPENSSL_STATIC = "1";
|
||||||
|
OPENSSL_LIB_DIR = "${pkgsCross.pkgsStatic.openssl.out}/lib";
|
||||||
|
OPENSSL_INCLUDE_DIR = "${pkgsCross.pkgsStatic.openssl.dev}/include";
|
||||||
|
|
||||||
|
# TODO co uld be removed ?
|
||||||
|
# Required because ring crate is special. This also seems to have
|
||||||
|
# fixed some issues with the x86_64-windows cross-compile :shrug:
|
||||||
|
TARGET_CC = "${pkgsCross.stdenv.cc}/bin/${pkgsCross.stdenv.cc.targetPrefix}cc";
|
||||||
|
|
||||||
|
CARGO_BUILD_TARGET = rustTarget;
|
||||||
|
CARGO_BUILD_RUSTFLAGS = [
|
||||||
|
"-C" "target-feature=+crt-static"
|
||||||
|
|
||||||
|
# -latomic is required to build openssl-sys for armv6l-linux, but
|
||||||
|
# it doesn't seem to hurt any other builds.
|
||||||
|
"-C" "link-args=-static -latomic"
|
||||||
|
|
||||||
|
# https://github.com/rust-lang/cargo/issues/4133
|
||||||
|
"-C" "linker=${TARGET_CC}"
|
||||||
|
];
|
||||||
|
})
|
||||||
|
);
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue