nix: improve RUSTFLAGS + add overlay

This commit is contained in:
seth 2024-03-31 19:56:13 -04:00
parent 0b0779f8b7
commit 5cfb079e35
No known key found for this signature in database
GPG key ID: D31BD0D494BBEE86
4 changed files with 22 additions and 13 deletions

View file

@ -47,9 +47,3 @@ pedantic = "warn"
perf = "warn"
style = "warn"
suspicious = "deny"
[profile.release]
codegen-units = 1
opt-level = "s"
panic = "abort"
strip = "symbols"

View file

@ -28,7 +28,7 @@
buildWith = rustPlatform:
self'.packages.refraction.override {
inherit rustPlatform;
lto = true;
optimizeSize = true;
};
in {
packages =

View file

@ -4,7 +4,8 @@
rustPlatform,
darwin,
self,
lto ? false,
lto ? true,
optimizeSize ? false,
}:
rustPlatform.buildRustPackage {
pname = "refraction";
@ -35,11 +36,22 @@ rustPlatform.buildRustPackage {
SystemConfiguration
]);
env = {
CARGO_BUILD_RUSTFLAGS = lib.concatStringsSep " " (
lib.optionals lto ["-C" "lto=thin" "-C" "embed-bitcode=yes" "-Zdylib-lto"]
env = let
toRustFlags = lib.mapAttrs' (
name:
lib.nameValuePair
"CARGO_PROFILE_RELEASE_${lib.toUpper (builtins.replaceStrings ["-"] ["_"] name)}"
);
};
in
lib.optionalAttrs lto (toRustFlags {
lto = "thin";
})
// lib.optionalAttrs optimizeSize (toRustFlags {
codegen-units = "1";
opt-level = "s";
panic = "abort";
strip = "symbols";
});
meta = with lib; {
mainProgram = "refraction";

View file

@ -6,8 +6,11 @@
}: {
packages = {
refraction = pkgs.callPackage ./derivation.nix {inherit self;};
default = self'.packages.refraction;
};
};
flake.overlays.default = _: prev: {
refraction = prev.callPackage ./derivation.nix {inherit self;};
};
}