-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
92 lines (81 loc) · 3.12 KB
/
flake.nix
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
description = "nar-toolbox";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
crane.url = "github:ipetkov/crane";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, rust-overlay, crane }:
let
inherit (nixpkgs.lib) nameValuePair mergeAttrsList listToAttrs singleton;
# Pairs of localSystem tp multiple crossSystems.
systems = [
{ localSystem = "x86_64-linux"; crossSystems = singleton "aarch64-linux"; }
{ localSystem = "aarch64-linux"; crossSystems = singleton "x86_64-linux"; }
{ localSystem = "x86_64-darwin"; crossSystems = []; }
{ localSystem = "aarch64-darwin"; crossSystems = singleton "x86_64-darwin"; }
];
forAllSystems = f:
listToAttrs (map (args:
nameValuePair args.localSystem
(mergeAttrsList (map (crossSystem:
f {
localSystem = args.localSystem;
crossSystem = if crossSystem == null then args.localSystem else crossSystem;
}) (singleton args.localSystem ++ args.crossSystems)
))
) systems);
in
{
packages = forAllSystems ({ localSystem, crossSystem }:
let
overlays = [ (import rust-overlay) ];
pkgs = import nixpkgs {
inherit localSystem crossSystem overlays;
};
inherit (pkgs) lib;
target =
if crossSystem == "x86_64-linux" then "x86_64-unknown-linux-musl"
else if crossSystem == "aarch64-linux" then "aarch64-unknown-linux-musl"
else if crossSystem == "x86_64-darwin" then "x86_64-apple-darwin"
else if crossSystem == "aarch64-darwin" then "aarch64-apple-darwin"
else throw "unsupported target system";
toolchain = p: p.rust-bin.stable.latest.default.override {
targets = [target];
};
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
package =
{ openssl
, libiconv
, lib
, pkg-config
, stdenv
}:
craneLib.buildPackage {
src = craneLib.cleanCargoSource ./.;
strictDeps = true;
nativeBuildInputs = [
pkg-config
] ++ lib.optionals stdenv.buildPlatform.isDarwin [
libiconv
];
buildInputs = [
openssl
];
CARGO_BUILD_TARGET = target;
"CARGO_TARGET_${builtins.replaceStrings ["-"] ["_"] (lib.toUpper target)}_LINKER" = "${stdenv.cc.targetPrefix}cc";
CARGO_BUILD_RUSTFLAGS = "-C target-feature=+crt-static";
};
nar-toolbox = pkgs.callPackage package { openssl = pkgs.pkgsStatic.openssl; };
in ((lib.optionalAttrs (localSystem == crossSystem) {
inherit nar-toolbox;
default = nar-toolbox;
}) // (lib.optionalAttrs (localSystem != crossSystem) {
"cross-${crossSystem}-nar-toolbox" = nar-toolbox;
}))
);
};
}