-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathflake.nix
More file actions
87 lines (77 loc) · 2.91 KB
/
flake.nix
File metadata and controls
87 lines (77 loc) · 2.91 KB
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
{
description = "Native build & dev shell for git_sync with Rust 1.88.0 (musl tools available on Linux)";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay.url = "github:oxalica/rust-overlay";
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
normalizedRustTarget = target:
if target == "arm64-apple-darwin" then "aarch64-apple-darwin" else target;
nativeTarget = normalizedRustTarget pkgs.stdenv.hostPlatform.config;
muslTarget = "x86_64-unknown-linux-musl";
extraRustTargets = pkgs.lib.optional pkgs.stdenv.hostPlatform.isLinux muslTarget;
extraDevInputs = pkgs.lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.musl;
rustToolchain = pkgs.rust-bin.stable."1.88.0".default.override {
extensions = [ "rust-src" "rust-std" ];
targets = [ nativeTarget ] ++ extraRustTargets;
};
envVars = {
SOURCE_DATE_EPOCH = "315532800";
RUSTFLAGS = "--remap-path-prefix=$(pwd)=.";
};
cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml);
version = cargoToml.package.version;
commonBuildInputs = [
rustToolchain
pkgs.pkg-config
pkgs.openssl
pkgs.openssl.dev
pkgs.cargo-audit
pkgs.cargo-auditable
pkgs.git
] ++ extraDevInputs;
in {
packages = rec {
git_sync = pkgs.rustPlatform.buildRustPackage {
pname = "git_sync";
version = version;
src = ./.;
cargoLock = {
lockFile = ./Cargo.lock;
};
buildInputs = commonBuildInputs;
buildPhase = ''
export SOURCE_DATE_EPOCH=${envVars.SOURCE_DATE_EPOCH}
export RUSTFLAGS="${envVars.RUSTFLAGS}"
cargo auditable build --release
'';
installPhase = ''
mkdir -p $out/bin
cp target/release/git_sync $out/bin/
'';
doCheck = true;
};
default = git_sync;
};
devShells.default = pkgs.mkShell {
buildInputs = commonBuildInputs;
shellHook = ''
export SOURCE_DATE_EPOCH=${envVars.SOURCE_DATE_EPOCH}
export RUSTFLAGS="${envVars.RUSTFLAGS}"
if [[ "${pkgs.stdenv.hostPlatform.system}" == *-linux ]]; then
echo "You can also build for musl with: cargo auditable build --release --target ${muslTarget}"
fi
echo "Native Rust toolchain ready for ${nativeTarget}."
echo "Build native with: cargo auditable build --release"
'';
};
}
);
}