-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
150 lines (142 loc) · 4.31 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
{
inputs = {
nixpkgs.url = "nixpkgs/nixos-24.05";
utils.url = "github:numtide/flake-utils";
naersk.url = "github:nix-community/naersk";
naersk.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "utils";
cross-naersk.url = "github:icewind1991/cross-naersk";
cross-naersk.inputs.nixpkgs.follows = "nixpkgs";
cross-naersk.inputs.naersk.follows = "naersk";
steam-fetcher = {
url = "github:nix-community/steam-fetcher";
inputs.nixpkgs.follows = "nixpkgs";
};
npmlock2nix.url = "github:nix-community/npmlock2nix";
npmlock2nix.flake = false;
};
outputs = {
self,
nixpkgs,
utils,
naersk,
rust-overlay,
cross-naersk,
steam-fetcher,
npmlock2nix,
}:
utils.lib.eachDefaultSystem (system: let
overlays = [
steam-fetcher.overlays.default
(import rust-overlay)
(import ./overlay.nix)
(final: prev: {
npmlock2nix = final.callPackage npmlock2nix {};
})
];
pkgs = (import nixpkgs) {
inherit system overlays;
};
inherit (pkgs) lib callPackage rust-bin mkShell;
inherit (lib.sources) sourceByRegex;
msrv = (fromTOML (readFile ./Cargo.toml)).package.rust-version;
inherit (builtins) fromTOML readFile;
toolchain = rust-bin.stable.latest.default;
msrvToolchain = rust-bin.stable."${msrv}".default;
hostTarget = pkgs.hostPlatform.config;
targets = [
"x86_64-unknown-linux-musl"
"x86_64-pc-windows-gnu"
hostTarget
];
releaseTargets = lib.lists.remove hostTarget targets;
naersk' = callPackage naersk {
rustc = toolchain;
cargo = toolchain;
};
msrvNaersk = callPackage naersk {
rustc = msrvToolchain;
cargo = msrvToolchain;
};
cross-naersk' = pkgs.callPackage cross-naersk {inherit naersk;};
buildMatrix = targets: {
include =
builtins.map (target: {
inherit target;
artifactSuffix = cross-naersk'.execSufficForTarget target;
})
targets;
};
src = sourceByRegex ./. ["Cargo.*" "(src|derive|benches|tests|examples.*)(/.*)?"];
nearskOpt = {
pname = "vbsp-to-gltf";
root = src;
};
in rec {
packages =
lib.attrsets.genAttrs targets (target:
(cross-naersk'.buildPackage target) nearskOpt)
// rec {
vbsp-to-gltf = packages.${hostTarget};
check = naersk'.buildPackage (nearskOpt
// {
mode = "check";
});
clippy = naersk'.buildPackage (nearskOpt
// {
mode = "clippy";
});
test = naersk'.buildPackage (nearskOpt
// {
release = false;
mode = "test";
});
msrv = msrvNaersk.buildPackage (nearskOpt
// {
mode = "check";
});
server = naersk'.buildPackage (nearskOpt
// {
pname = "vbsp-server";
preConfigure = ''
cargo_build_options="--features server $cargo_build_options"
'';
GLTFPACK = "${pkgs.meshoptimizer}/bin/gltfpack";
});
assets = pkgs.vbsp-server-assets;
viewer = pkgs.vbsp-server-viewer;
server-with-assets = server.overrideAttrs (old: {
buildInputs = server.buildInputs ++ [pkgs.makeWrapper];
postInstall = ''
wrapProgram "$out/bin/vbsp-server" --set TF_DIR "${assets}"
'';
});
vbsp-server = pkgs.vbsp-server;
default = vbsp-to-gltf;
};
matrix = buildMatrix targets;
releaseMatrix = buildMatrix releaseTargets;
devShells = let
tools = with pkgs; [
bacon
cargo-edit
cargo-outdated
cargo-audit
cargo-msrv
meshoptimizer
];
in {
default = mkShell {
nativeBuildInputs = [toolchain] ++ tools;
};
msrv = mkShell {
nativeBuildInputs = [msrvToolchain] ++ tools;
};
};
})
// {
overlays.default = import ./overlay.nix;
};
}