-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
139 lines (122 loc) · 4.62 KB
/
flake.nix
File metadata and controls
139 lines (122 loc) · 4.62 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
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
{
description = "Bevy Game development environment";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-25.05";
# nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
nixgl = {
url = "github:guibou/nixGL";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, nixgl }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgsOrig = import nixpkgs {inherit system; };
forced = builtins.trace "Current system is: ${system}" null;
isLinux = (builtins.match ".*linux.*" system) != null;
isDarwin = (builtins.match ".*darwin.*" system) != null;
isImpure = builtins.hasAttr "currentTime" builtins;
pkgs = import nixpkgs {
inherit system;
overlays = if (isLinux && isImpure)
then [ nixgl.overlays.default ]
else [ ];
};
linuxPackages = with pkgs; [
alsa-lib
alsa-plugins
udev
];
linuxImpurePackages = with pkgs; [
pkgs.nixgl.auto.nixGLDefault
];
sdkVersion = "15";
appleSDK = pkgs."apple-sdk_${sdkVersion}";
appleLibs = if isDarwin then ([
appleSDK
]) else [];
# Platform-specific packages
platformPackages =
(if (isLinux && !isImpure) then
linuxPackages
else if isLinux then
linuxPackages ++ linuxImpurePackages
else if isDarwin then
appleLibs
else
[ ]);
# Common bindgen configuration
commonBindgenIncludes = with pkgs; [
''-I"${llvmPackages_latest.libclang.lib}/lib/clang/${llvmPackages_latest.libclang.version}/include"''
];
# Platform-specific bindgen configuration
platformBindgenInputs = if isLinux then
with pkgs; [
glibc.dev
]
else [];
platformBindgenIncludes = if isLinux then
with pkgs; [
''-I"${glib.dev}/include/glib-2.0"''
''-I${glib.out}/lib/glib-2.0/include/''
]
else [];
# It's standard in nix to pin the versions for reproducibility; here's where we
# pin the Rust toolchain.
overrides = (builtins.fromTOML (builtins.readFile (self + "/nix/rust-toolchain.toml")));
# Platform-specific shell hook
platformShellHook = if isLinux then ''
alias gl='nixGL'
export ALSA_PLUGIN_DIR=${pkgs.alsa-plugins}/lib/alsa-lib
''
else
"";
libPath = with pkgs; lib.makeLibraryPath [
# load external libraries that you need in your rust project here
];
in
{
devShells.default = pkgs.mkShell rec {
nativeBuildInputs = [ pkgs.pkg-config ];
buildInputs = with pkgs; [
clang
llvmPackages.bintools
# shouldn't need this, but rustup (andt thus cargo), is too old for 2024 edition requirements:
# https://github.com/NixOS/nixpkgs/pull/397177
cargo
rustup
vulkan-loader
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr
libxkbcommon
] ++ platformPackages;
RUSTC_VERSION = overrides.toolchain.channel;
RUSTC_COMPONENTS = nixpkgs.lib.escapeShellArgs (nixpkgs.lib.concatMap (c: ["-c" c]) overrides.toolchain.components);
LIBCLANG_PATH = pkgs.lib.makeLibraryPath [ pkgs.llvmPackages_latest.libclang.lib ];
FORCED = forced;
shellHook = ''
rustup toolchain install $RUSTC_VERSION $RUSTC_COMPONENTS
export PATH=$PATH:''${CARGO_HOME:-~/.cargo}/bin
export PATH=''${RUSTUP_HOME:-~/.rustup}/toolchains/$RUSTC_VERSION-x86_64-unknown-linux-gnu/bin/:$PATH
${platformShellHook}
'';
# Add precompiled library to rustc search path
RUSTFLAGS = (builtins.map (a: ''-L ${a}/lib'') [
# add libraries here (e.g. pkgs.libvmi)
]);
LD_LIBRARY_PATH =
(pkgs.lib.makeLibraryPath (buildInputs ++ nativeBuildInputs)) +
# packages with non-standard lib paths:
(if isLinux then ":${pkgs.alsa-plugins}/lib/alsa-lib" else "");
# Add clang and other headers to bindgen search path
BINDGEN_EXTRA_CLANG_ARGS =
(builtins.map (a: ''-I"${a}/include"'') platformBindgenInputs)
++ commonBindgenIncludes
++ platformBindgenIncludes;
};
}
);
}