+77
cli/flake.lock
+77
cli/flake.lock
···
1
+
{
2
+
"nodes": {
3
+
"crane": {
4
+
"locked": {
5
+
"lastModified": 1754269165,
6
+
"narHash": "sha256-0tcS8FHd4QjbCVoxN9jI+PjHgA4vc/IjkUSp+N3zy0U=",
7
+
"owner": "ipetkov",
8
+
"repo": "crane",
9
+
"rev": "444e81206df3f7d92780680e45858e31d2f07a08",
10
+
"type": "github"
11
+
},
12
+
"original": {
13
+
"owner": "ipetkov",
14
+
"repo": "crane",
15
+
"type": "github"
16
+
}
17
+
},
18
+
"flake-utils": {
19
+
"inputs": {
20
+
"systems": "systems"
21
+
},
22
+
"locked": {
23
+
"lastModified": 1731533236,
24
+
"narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=",
25
+
"owner": "numtide",
26
+
"repo": "flake-utils",
27
+
"rev": "11707dc2f618dd54ca8739b309ec4fc024de578b",
28
+
"type": "github"
29
+
},
30
+
"original": {
31
+
"owner": "numtide",
32
+
"repo": "flake-utils",
33
+
"type": "github"
34
+
}
35
+
},
36
+
"nixpkgs": {
37
+
"locked": {
38
+
"lastModified": 1754214453,
39
+
"narHash": "sha256-Q/I2xJn/j1wpkGhWkQnm20nShYnG7TI99foDBpXm1SY=",
40
+
"owner": "NixOS",
41
+
"repo": "nixpkgs",
42
+
"rev": "5b09dc45f24cf32316283e62aec81ffee3c3e376",
43
+
"type": "github"
44
+
},
45
+
"original": {
46
+
"owner": "NixOS",
47
+
"ref": "nixos-unstable",
48
+
"repo": "nixpkgs",
49
+
"type": "github"
50
+
}
51
+
},
52
+
"root": {
53
+
"inputs": {
54
+
"crane": "crane",
55
+
"flake-utils": "flake-utils",
56
+
"nixpkgs": "nixpkgs"
57
+
}
58
+
},
59
+
"systems": {
60
+
"locked": {
61
+
"lastModified": 1681028828,
62
+
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
63
+
"owner": "nix-systems",
64
+
"repo": "default",
65
+
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
66
+
"type": "github"
67
+
},
68
+
"original": {
69
+
"owner": "nix-systems",
70
+
"repo": "default",
71
+
"type": "github"
72
+
}
73
+
}
74
+
},
75
+
"root": "root",
76
+
"version": 7
77
+
}
+30
-48
cli/flake.nix
+30
-48
cli/flake.nix
···
4
4
inputs = {
5
5
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
6
6
flake-utils.url = "github:numtide/flake-utils";
7
-
rust-overlay = {
8
-
url = "github:oxalica/rust-overlay";
7
+
crane = {
8
+
url = "github:ipetkov/crane";
9
9
inputs.nixpkgs.follows = "nixpkgs";
10
10
};
11
11
};
12
12
13
-
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
13
+
outputs = { self, nixpkgs, flake-utils, crane }:
14
14
flake-utils.lib.eachDefaultSystem (system:
15
15
let
16
-
overlays = [ (import rust-overlay) ];
17
-
pkgs = import nixpkgs { inherit system overlays; };
18
-
19
-
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
20
-
extensions = [ "rust-src" ];
21
-
targets = [
22
-
"x86_64-unknown-linux-gnu"
23
-
"x86_64-pc-windows-gnu"
24
-
"x86_64-apple-darwin"
25
-
"aarch64-apple-darwin"
26
-
"aarch64-unknown-linux-gnu"
27
-
];
28
-
};
16
+
pkgs = import nixpkgs { inherit system; };
17
+
18
+
craneLib = crane.mkLib pkgs;
19
+
20
+
src = craneLib.cleanCargoSource (craneLib.path ./.);
29
21
30
-
# Build function for different targets
31
-
buildGrainCLI = target: pkgs.stdenv.mkDerivation rec {
32
-
pname = "grain-cli-${target}";
33
-
version = "0.1.0";
34
-
35
-
src = ./.;
36
-
37
-
nativeBuildInputs = with pkgs; [
38
-
rustToolchain
39
-
pkg-config
40
-
] ++ pkgs.lib.optionals (target == "x86_64-pc-windows-gnu") [
41
-
pkgs.pkgsCross.mingwW64.stdenv.cc
42
-
];
22
+
commonArgs = {
23
+
inherit src;
24
+
strictDeps = true;
43
25
44
26
buildInputs = with pkgs; [
45
27
openssl
···
48
30
pkgs.darwin.apple_sdk.frameworks.SystemConfiguration
49
31
];
50
32
51
-
buildPhase = ''
52
-
export CARGO_HOME=$TMPDIR/cargo
53
-
export OPENSSL_NO_VENDOR=1
54
-
export PKG_CONFIG_PATH="${pkgs.openssl.dev}/lib/pkgconfig:$PKG_CONFIG_PATH"
55
-
56
-
${if target == "x86_64-pc-windows-gnu" then ''
57
-
export CC_x86_64_pc_windows_gnu="${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/x86_64-w64-mingw32-gcc"
58
-
export CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER="${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/x86_64-w64-mingw32-gcc"
59
-
export PKG_CONFIG_ALLOW_CROSS=1
60
-
'' else ""}
61
-
62
-
cargo build --release --target ${target}
63
-
'';
64
-
65
-
installPhase = ''
66
-
mkdir -p $out/bin
67
-
cp target/${target}/release/grain${if target == "x86_64-pc-windows-gnu" then ".exe" else ""} $out/bin/
68
-
'';
33
+
nativeBuildInputs = with pkgs; [
34
+
pkg-config
35
+
];
69
36
};
70
37
38
+
# Build dependencies first for caching
39
+
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
40
+
41
+
# Build function for different targets
42
+
buildGrainCLI = target: craneLib.buildPackage (commonArgs // {
43
+
inherit cargoArtifacts;
44
+
CARGO_BUILD_TARGET = target;
45
+
} // pkgs.lib.optionalAttrs (target == "x86_64-pc-windows-gnu") {
46
+
depsBuildBuild = with pkgs; [
47
+
pkgsCross.mingwW64.stdenv.cc
48
+
];
49
+
CARGO_TARGET_X86_64_PC_WINDOWS_GNU_LINKER = "${pkgs.pkgsCross.mingwW64.stdenv.cc}/bin/x86_64-w64-mingw32-gcc";
50
+
});
51
+
71
52
in {
72
53
packages = {
73
54
default = buildGrainCLI system;
···
83
64
devShells.default = pkgs.mkShell {
84
65
inputsFrom = [ self.packages.${system}.default ];
85
66
packages = with pkgs; [
86
-
rustToolchain
67
+
rustc
68
+
cargo
87
69
pkg-config
88
70
openssl
89
71
cargo-cross