This repository has been archived by the owner on Nov 22, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 37
/
Copy pathflake.nix
169 lines (151 loc) · 5.39 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
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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
{
description = "Description for the project";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
devenv.url = "github:cachix/devenv";
nix2container.url = "github:nlewo/nix2container";
nix2container.inputs.nixpkgs.follows = "nixpkgs";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
};
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.devenv.flakeModule
];
systems = ["x86_64-linux" "i686-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin"];
perSystem = {
config,
self',
inputs',
pkgs,
system,
...
}: let
cargoToml = builtins.fromTOML (builtins.readFile ./emergence_game/Cargo.toml);
# https://github.com/bevyengine/bevy/blob/latest/docs/linux_dependencies.md#nix
# https://github.com/NixOS/nixpkgs/blob/master/pkgs/games/jumpy/default.nix
buildInputs = with pkgs; [
zstd # may need to config pkg-config
udev
alsa-lib
vulkan-loader
xorg.libX11
xorg.libXcursor
xorg.libXi
xorg.libXrandr # To use the x11 feature
libxkbcommon
wayland # To use the wayland feature
];
env = {
ZSTD_SYS_USE_PKG_CONFIG = true;
};
# ++ lib.optionals stdenv.isDarwin [
# darwin.apple_sdk.frameworks.Cocoa
# rustPlatform.bindgenHook
# ];
nativeBuildInputs = with pkgs; [
pkg-config
llvmPackages.bintools # To use lld linker
];
# LD_LIBRARY_PATH = lib.makeLibraryPath buildInputs;
pname = cargoToml.package.name;
version = cargoToml.package.version;
ide = with pkgs;
vscode-with-extensions.override {
vscode = vscodium;
vscodeExtensions = with vscode-extensions; [
jnoortheen.nix-ide
tamasfe.even-better-toml
serayuzgur.crates
mkhl.direnv
rust-lang.rust-analyzer
github.copilot-chat
github.copilot
vadimcn.vscode-lldb
];
};
lib = pkgs.lib;
filterCargoSources = orig_path: type: let
path = toString orig_path;
base = baseNameOf path;
parentDir = baseNameOf (dirOf path);
matchesSuffix = lib.any (suffix: lib.hasSuffix suffix base) [
# Keep rust sources
".rs"
# Keep all toml files as they are commonly used to configure other
# cargo-based tools
".toml"
];
# Cargo.toml already captured above
isCargoFile = base == "Cargo.lock";
# .cargo/config.toml already captured above
isCargoConfig = parentDir == ".cargo" && base == "config";
in
type == "directory" || matchesSuffix || isCargoFile || isCargoConfig;
src = lib.cleanSourceWith {
# Apply the default source cleaning from nixpkgs
src = lib.cleanSource ./.;
# Then add our own filter on top
filter = filterCargoSources;
};
assets = ./emergence_game/assets;
built = with pkgs;
rustPlatform.buildRustPackage rec {
inherit pname version buildInputs nativeBuildInputs env src;
cargoLock = {
lockFile = ./Cargo.lock;
};
cargoBuildFlags = ["--bin" pname];
postInstall = ''
cp -r ${assets} $out/bin/assets
'';
postFixup = lib.optionalString stdenv.isLinux ''
patchelf $out/bin/${pname} \
--add-rpath ${lib.makeLibraryPath [vulkan-loader]}
'';
};
in {
# Per-system attributes can be defined here. The self' and inputs'
# module parameters provide easy access to attributes of the same
# system.
# Equivalent to inputs'.nixpkgs.legacyPackages.hello;
packages.ide = ide;
packages.default = built;
packages.blender = pkgs.blender;
devenv.shells.default = {
name = cargoToml.package.name;
imports = [
# This is just like the imports in devenv.nix.
# See https://devenv.sh/guides/using-with-flake-parts/#import-a-devenv-module
# ./devenv-foo.nix
];
# https://devenv.sh/reference/options/
packages = buildInputs ++ nativeBuildInputs;
languages.rust.enable = true;
pre-commit.hooks = {
alejandra.enable = true;
rustfmt.enable = true;
};
difftastic.enable = true;
scripts.ide.exec = ''
${ide}/bin/codium
'';
scripts.trunk-serve.exec = ''
${pkgs.trunk}/bin/trunk serve
'';
scripts.build-assets.exec = ''
${pkgs.blender}/bin/blender --background assets/assets.blend --python "convert.py"
'';
scripts.blender-open.exec = ''
${pkgs.blender}/bin/blender ./assets/assets.blend
'';
};
formatter = pkgs.alejandra;
};
flake = {
# The usual flake attributes can be defined here, including system-
# agnostic ones like nixosModule and system-enumerating ones, although
# those are more easily expressed in perSystem.
};
};
}