-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathflake.nix
More file actions
157 lines (129 loc) · 4.92 KB
/
flake.nix
File metadata and controls
157 lines (129 loc) · 4.92 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
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
nixpkgs-codium.url = "github:nixos/nixpkgs?ref=91c9a64ce2a84e648d0cf9671274bb9c2fb9ba60";
fenix = {
url = "github:nix-community/fenix";
inputs.nixpkgs.follows = "nixpkgs";
};
crane.url = "github:ipetkov/crane";
};
inputs.self.lfs = true;
outputs = { self, nixpkgs, nixpkgs-codium, fenix, crane }: let
inherit (nixpkgs) lib;
pkgs = nixpkgs.legacyPackages."x86_64-linux";
pkgs-codium = nixpkgs-codium.legacyPackages."x86_64-linux";
fenixLib = fenix.packages."x86_64-linux";
toolchain_sha = "sha256-dXoddWaPL6UtPscTpxMUMBDL83jFtqeDtmH/+bXBs3E=";
rustToolchain = fenixLib.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = toolchain_sha;
};
wasmToolchain = fenixLib.combine [
(fenixLib.targets.wasm32-unknown-unknown.fromToolchainFile {
file = ./rust-toolchain.toml;
sha256 = toolchain_sha;
})
rustToolchain
];
neededPackages = with pkgs; [
wayland
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
libxkbcommon
openssl
vulkan-headers vulkan-loader
];
built_overrides = {
# info for built
# BUILT_OVERRIDE_factory_GIT_DIRTY = if self.revDirty then "true" else "false";
BUILT_OVERRIDE_factory_GIT_HEAD_REF = self.ref or null;
BUILT_OVERRIDE_factory_GIT_COMMIT_HASH = self.rev or null;
BUILT_OVERRIDE_factory_GIT_COMMIT_HASH_SHORT = self.revShort or null;
SOURCE_DATE_EPOCH = self.lastModified;
};
client_package_for_target = {
target, toolchain
}: ((crane.mkLib nixpkgs.legacyPackages.${pkgs.system}).overrideToolchain toolchain).buildPackage ({
name = "factory";
BUILT_OVERRIDE_factory_GIT_COMMIT_HASH_SHORT = "BLUB";
CARGO_BUILD_TARGET = target;
meta = {
homepage = "https://www.github.com/BloodStainedCrow/FactoryGame/";
maintainers = with lib.maintainers; [ BloodStainedCrow ];
mainProgram = "factory";
};
src = ./.;
buildInputs = neededPackages;
nativeBuildInputs = [ pkgs.pkg-config pkgs.makeWrapper ];
cargoHash = "sha256-83+1Y486PUHM9+uyFw+yJ9bNMlMbN/fc8cYRzKmDdb8=";
# cargoLock.lockFile = ./Cargo.lock;
doCheck = false;
postInstall = ''
wrapProgram "$out/bin/factory" --prefix LD_LIBRARY_PATH : "${builtins.toString (pkgs.lib.makeLibraryPath neededPackages)}"
'';
} // built_overrides);
client_package = client_package_for_target { target = "x86_64-unknown-linux-gnu"; toolchain = rustToolchain; };
in {
devShells."x86_64-linux".codium = pkgs.mkShell {
buildInputs = with pkgs; [
bashInteractive
rustToolchain
perf
samply
bacon
(vscode-with-extensions.override {
vscode = pkgs-codium.vscodium;
vscodeExtensions = with pkgs-codium.vscode-extensions; [
rust-lang.rust-analyzer
vadimcn.vscode-lldb
gruntfuggly.todo-tree
a5huynh.vscode-ron
];
})
] ++ neededPackages;
LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${builtins.toString (pkgs.lib.makeLibraryPath neededPackages)}";
shellHook = ''
export SHELL="${pkgs.bashInteractive}/bin/bash"
'';
# env.RUST_SRC_PATH = "${rustToolchain.rust-src}";
};
packages."x86_64-linux".default = client_package;
packages."x86_64-linux".dedicated_server = client_package.overrideAttrs ( oldAttrs: { cargoBuildFlags = [ "--no-default-features" "-F logging" ]; });
"wasm" = (client_package_for_target { target = "wasm32-unknown-unknown"; toolchain = wasmToolchain; }).overrideAttrs ( oldAttrs: {
nativeBuildInputs = oldAttrs.nativeBuildInputs ++ [ pkgs.wabt pkgs.binaryen ];
postInstall = ''
mkdir -p $out/lib
ls -lR $out
wasm-strip $out/bin/factory.wasm -o $out/lib/factory.wasm
# TODO: Use wasm-opt
# wasm-opt $out/lib/factory.wasm -o $out/lib/factory.wasm -O4
rm -r $out/bin
wasm-validate $out/lib/factory.wasm
'';
# We cannot run tests on a wasm binary
doCheck = false;
});
"trunk" = ((crane.mkLib nixpkgs.legacyPackages.${pkgs.system}).overrideToolchain wasmToolchain).buildTrunkPackage ({
nativeBuildInputs = [ pkgs.lld ];
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
src = ./.;
wasm-bindgen-cli = pkgs.buildWasmBindgenCli rec {
src = pkgs.fetchCrate {
pname = "wasm-bindgen-cli";
version = "0.2.108";
hash = "sha256-UsuxILm1G6PkmVw0I/JF12CRltAfCJQFOaT4hFwvR8E=";
# hash = lib.fakeHash;
};
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
inherit src;
inherit (src) pname version;
hash = "sha256-iqQiWbsKlLBiJFeqIYiXo3cqxGLSjNM8SOWXGM9u43E=";
# hash = lib.fakeHash;
};
};
} // built_overrides);
};
}