summaryrefslogtreecommitdiff
path: root/nix/static.nix
diff options
context:
space:
mode:
Diffstat (limited to 'nix/static.nix')
-rw-r--r--nix/static.nix38
1 files changed, 38 insertions, 0 deletions
diff --git a/nix/static.nix b/nix/static.nix
new file mode 100644
index 0000000..22fbad6
--- /dev/null
+++ b/nix/static.nix
@@ -0,0 +1,38 @@
+{
+ lib,
+ pkgsStatic,
+ fenix,
+ naersk,
+ teawiebot,
+}: let
+ inherit (pkgsStatic.stdenv) cc;
+
+ target = pkgsStatic.stdenv.hostPlatform.config;
+ target' = builtins.replaceStrings ["-"] ["_"] target;
+ targetUpper = lib.toUpper target';
+
+ toolchain = with fenix;
+ combine [
+ minimal.cargo
+ minimal.rustc
+ targets.${target}.latest.rust-std
+ ];
+
+ naersk' = naersk.override {
+ cargo = toolchain;
+ rustc = toolchain;
+ };
+in
+ (teawiebot.override {
+ naersk = naersk';
+ lto = true;
+ optimizeSize = true;
+ })
+ .overrideAttrs (new: old: {
+ env = {
+ "CC_${target'}" = "${cc}/bin/${cc.targetPrefix}cc";
+ CARGO_BUILD_TARGET = target;
+ CARGO_BUILD_RUSTFLAGS = old.env.CARGO_BUILD_RUSTFLAGS + " -C target-feature=+crt-static";
+ "CARGO_TARGET_${targetUpper}_LINKER" = new.env."CC_${target'}";
+ };
+ })