Skip to content

Commit 73b497f

Browse files
committed
flake tweak
1 parent 1470f2d commit 73b497f

File tree

1 file changed

+18
-6
lines changed

1 file changed

+18
-6
lines changed

flake.nix

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -21,12 +21,28 @@
2121
overlays = [rust-overlay.overlays.default];
2222
pkgs = import nixpkgs {inherit overlays system;};
2323

24+
# Cross-compilation setup for musl
25+
pkgsCross = import nixpkgs {
26+
inherit overlays;
27+
localSystem = system;
28+
crossSystem = {
29+
config = "x86_64-unknown-linux-musl";
30+
isStatic = true;
31+
};
32+
};
33+
2434
rust = pkgs.rust-bin.stable.latest.default.override {extensions = ["rust-src"];};
2535
rustPlatform = pkgs.makeRustPlatform {
2636
cargo = rust;
2737
rustc = rust;
2838
};
2939

40+
# Use cross-compiled rustPlatform for musl builds
41+
rustPlatformCross = pkgsCross.makeRustPlatform {
42+
cargo = rust;
43+
rustc = rust;
44+
};
45+
3046
manifest = (pkgs.lib.importTOML ./Cargo.toml).package;
3147
in {
3248
# `nix develop`.
@@ -75,24 +91,20 @@
7591
};
7692

7793
# Static musl build for Linux distribution
78-
anonymiser-musl = rustPlatform.buildRustPackage {
94+
anonymiser-musl = rustPlatformCross.buildRustPackage {
7995
pname = "${manifest.name}-musl";
8096
version = manifest.version;
8197
src = pkgs.nix-gitignore.gitignoreSource [] ./.;
8298
cargoLock.lockFile = ./Cargo.lock;
8399

84-
# Target musl for static linking
85-
CARGO_BUILD_TARGET = "x86_64-unknown-linux-musl";
86-
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
87-
88100
# Compile-time dependencies.
89101
nativeBuildInputs = with pkgs; [
90102
pkg-config
91103
cmake
92104
perl # Required for vendored OpenSSL build
93105
];
94106

95-
# With vendored OpenSSL, we don't need runtime dependencies
107+
# With vendored OpenSSL and static linking, we don't need runtime dependencies
96108
buildInputs = [];
97109

98110
checkFlags = [

0 commit comments

Comments
 (0)