summaryrefslogtreecommitdiff
path: root/nix/static.nix
blob: 22fbad6f4cda6b44183fc936d0897481ab1f7873 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
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'}";
    };
  })