-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathflake.nix
61 lines (60 loc) · 2.49 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
{
description = "A very basic flake";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
nixpkgs-compat.url = "github:nixos/nixpkgs?ref=23.05";
nixpkgs-compat.flake = false;
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs-compat, nixpkgs, flake-utils, rust-overlay }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ (import rust-overlay) ];
};
pkgs-compat = import nixpkgs-compat { inherit system; };
toUpper = pkgs.lib.strings.toUpper;
toolchain = (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml).override {
extensions = [ "rust-analyzer" ];
};
cargofy = s: builtins.replaceStrings [ "-" ] [ "_" ] s;
env = config: cc: {
nativeBuildInputs = [ cc ];
"CC_${cargofy config}" = "${cc}/bin/${cc.targetPrefix}cc";
"CXX_${cargofy config}" = "${cc}/bin/${cc.targetPrefix}c++";
"CARGO_TARGET_${toUpper (cargofy config)}_LINKER" = "${cc}/bin/${cc.targetPrefix}cc";
};
in
{
formatter = pkgs.nixpkgs-fmt;
devShells.default =
with pkgs; mkShell (lib.zipAttrsWith
(name: values: if builtins.isList (builtins.head values) then builtins.concatLists values else builtins.head values)
[
{
nativeBuildInputs = [
pkg-config
cmake
rust-bindgen
toolchain
];
}
(with pkgsCross.mingwW64; (env "x86_64-pc-windows-gnu" (stdenv.cc.override {
extraBuildCommands = ''
echo '-L ${windows.mingw_w64_pthreads}/lib' >> $out/nix-support/cc-ldflags
'';
})))
(with pkgsCross.aarch64-multiplatform-musl; env targetPlatform.config stdenv.cc)
(with pkgsCross.musl64; env targetPlatform.config stdenv.cc)
(with pkgsCross.aarch64-darwin; env targetPlatform.config stdenv.cc)
(with pkgsCross.x86_64-darwin; env targetPlatform.config stdenv.cc)
(with pkgs-compat.pkgsCross.aarch64-multiplatform; env targetPlatform.config stdenv.cc)
(with pkgs-compat.pkgsCross.gnu64; env targetPlatform.config stdenv.cc)
]);
});
}