-
Notifications
You must be signed in to change notification settings - Fork 5
/
flake.nix
executable file
·75 lines (75 loc) · 2.34 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
crane = {
url = "github:ipetkov/crane";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = {
nixpkgs,
rust-overlay,
crane,
...
}: let
inherit (nixpkgs) lib;
withSystem = f:
lib.fold lib.recursiveUpdate {}
(map f ["x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"]);
in
withSystem (
system: let
pkgs = import nixpkgs {
inherit system;
overlays = [rust-overlay.overlays.default];
};
inherit (pkgs) stdenv lib;
toolchain = pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml;
craneLib = (crane.mkLib pkgs).overrideToolchain toolchain;
buildDeps =
[]
++ lib.optionals stdenv.isDarwin (with pkgs.darwin.apple_sdk.frameworks; [
SystemConfiguration
]);
crate = craneLib.buildPackage {
# Filter src to only .rs, .toml, and .scm files to avoid needless recompiles
src = let
schemeFilter = path: _type: builtins.match ".*scm$" path != null;
schemeOrCargo = path: type:
(schemeFilter path type) || (craneLib.filterCargoSources path type);
in
lib.cleanSourceWith {
src = craneLib.path ./.;
filter = schemeOrCargo;
};
strictDeps = true;
buildInputs = buildDeps;
nativeBuildInputs = lib.optionals stdenv.isLinux [pkgs.pkg-config];
doNotSign = stdenv.isDarwin; # Build seems to break when this is true on Darwin
};
in {
apps.${system}.default = let
name = crate.pname or crate.name;
exe = crate.passthru.exePath or "/bin/${name}";
in {
type = "app";
program = "${crate}${exe}";
};
packages.${system}.default = crate;
checks.${system} = {inherit crate;};
devShells.${system}.default = pkgs.mkShell {
packages = with pkgs;
[
toolchain
rust-analyzer-unwrapped
]
++ buildDeps;
RUST_SRC_PATH = "${toolchain}/lib/rustlib/src/rust/library";
};
}
);
}