-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
40 lines (40 loc) · 1.62 KB
/
default.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
let
rust-overlay = (import (builtins.fetchTarball
"https://github.com/oxalica/rust-overlay/archive/7c94410d52d4e8bd72803fc1fe6c51fe179edaf5.tar.gz"));
in { pkgs ? (import <nixpkgs>) { overlays = [ rust-overlay ]; } }:
let
# MacOS X is supported as tier 2, for development purposes.
isMacOS = pkgs.stdenv.isDarwin;
# We compile to a static binary on Linux, which is also used to create releases, otherwise use the default.
# Right now, we hardcode Apple silicon macs.
target = if isMacOS then "aarch64-apple-darwin" else "x86_64-unknown-linux-musl";
stable-rust = pkgs.rust-bin.stable.latest.default.override {
extensions = [ "rust-src" ];
targets = [ target ];
};
rustPlatform = pkgs.makeRustPlatform {
cargo = stable-rust;
rustc = stable-rust;
};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
in rustPlatform.buildRustPackage {
name = cargoToml.package.name;
version = cargoToml.package.version;
src = pkgs.lib.cleanSourceWith {
filter = name: type: baseNameOf name != "target";
src = (pkgs.lib.cleanSource ./.);
};
cargoLock = { lockFile = ./Cargo.lock; };
# Note that we don't really need `podman` as a native build input, but it is
# helpful for running locally in a `nix-shell`.
nativeBuildInputs = with pkgs; [ podman ]
++ (if isMacOS then with darwin.apple_sdk.frameworks; [ SystemConfiguration qemu ] else []);
buildPhase = ''
cargo build --release --offline --target=${target}
'';
installPhase = ''
mkdir -p $out/bin
cp target/${target}/release/${cargoToml.package.name} $out/bin
'';
PODMAN_IS_REMOTE=if isMacOS then "true" else "false";
}