nix: build with Mold linker on x86_64-linux
Some checks are pending
Rust / Test on aarch64-unknown-linux-gnu (push) Waiting to run
Rust / Test on x86_64-unknown-linux-gnu (push) Waiting to run

Signed-off-by: NotAShelf <raf@notashelf.dev>
Change-Id: I771c36297577aba189058a2183ec2b4a6a6a6964
This commit is contained in:
raf 2025-11-30 17:24:19 +03:00
commit 8c32f5f408
Signed by: NotAShelf
GPG key ID: 29D95B64378DB4BF
3 changed files with 27 additions and 6 deletions

View file

@ -1,14 +1,22 @@
{
lib,
rustPlatform,
stdenv,
stdenvAdapters,
rustPlatform,
llvm,
useMold ? stdenv.isLinux && !stdenv.hostPlatform.isAarch,
}: let
toml = (lib.importTOML ../Cargo.toml).package;
pname = toml.name;
inherit (toml) version;
# Select stdenv based on useMold flag
stdenv =
if useMold
then stdenvAdapters.useMoldLinker llvm.stdenv
else llvm.stdenv;
in
rustPlatform.buildRustPackage.override {stdenv = stdenvAdapters.useMoldLinker llvm.stdenv;} {
rustPlatform.buildRustPackage.override {inherit stdenv;} {
inherit pname version;
src = let
fs = lib.fileset;
@ -26,7 +34,14 @@ in
cargoLock.lockFile = ../Cargo.lock;
enableParallelBuilding = true;
env.RUSTFLAGS = "-C link-arg=-fuse-ld=mold";
buildNoDefaultFeatures = true;
doCheck = false;
# Only set RUSTFLAGS for mold if useMold is enabled
env = lib.optionalAttrs useMold {
CARGO_LINKER = "clang";
RUSTFLAGS = "-C link-arg=-fuse-ld=mold";
};
meta = {
description = "Microscopic fetch script in Rust, for NixOS systems";