-
Notifications
You must be signed in to change notification settings - Fork 38
/
flake-module.nix
127 lines (115 loc) · 3.59 KB
/
flake-module.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
{ inputs, ... }: {
perSystem = { config, lib, pkgs, system, ... }:
let
inherit (inputs) crane;
inherit (pkgs) stdenv stdenvNoCC;
rustExtensions = [
"cargo"
"rust-src"
"rust-analyzer"
"rustfmt"
];
rustToolchain = pkgs.rust-bin.stable.latest.default.override {
extensions = rustExtensions;
targets = [ "wasm32-unknown-unknown" ];
};
craneLib = (crane.mkLib pkgs).overrideScope (final: prev: {
rustc = rustToolchain;
cargo = rustToolchain;
rustfmt = rustToolchain;
});
src = lib.cleanSourceWith {
src = craneLib.path ./.;
filter = path: type:
(lib.hasSuffix "\.wgsl" path) ||
(craneLib.filterCargoSources path type);
};
commonArgs = {
inherit src;
};
cargoArtifacts = craneLib.buildDepsOnly (commonArgs // {
pname = "flux-dependencies"; # TODO: throws warning otherwise
});
individualCrateArgs = {
inherit cargoArtifacts;
inherit (craneLib.crateNameFromCargoToml { inherit src; }) version;
};
fileSetForCrate = crate: lib.fileset.toSource {
root = ./.;
fileset = lib.fileset.unions [
./Cargo.toml
./Cargo.lock
./flux
./flux-desktop
./flux-wasm
./flux-gl
crate
];
};
in {
devShells = {
default = pkgs.mkShell {
packages = with pkgs; [nixfmt-rfc-style wasm-pack wgsl-analyzer cargo-outdated nodePackages.pnpm];
inputsFrom = with config.packages; [flux flux-desktop flux-wasm];
nativeBuildInputs = [rustToolchain];
};
};
packages = {
flux = craneLib.buildPackage (individualCrateArgs // {
pname = "flux";
src = fileSetForCrate ./flux;
cargoExtraArgs = "-p flux";
});
flux-desktop-wrapped =
let
runtimeLibraries = with pkgs; [
wayland
wayland-protocols
libxkbcommon
xorg.libX11
xorg.libXcursor
xorg.libXrandr
xorg.libXi
];
in
# Can’t use symlinkJoin because of the hooks are passed to the
# dependency-only build.
stdenvNoCC.mkDerivation {
name = "flux-desktop-wrapped";
inherit (config.packages.flux-desktop) version;
nativeBuildInputs = [pkgs.makeWrapper];
buildCommand = ''
mkdir -p $out/bin
cp ${config.packages.flux-desktop}/bin/flux-desktop $out/bin
wrapProgram $out/bin/flux-desktop \
--prefix LD_LIBRARY_PATH : ${pkgs.lib.makeLibraryPath runtimeLibraries}
'';
passthru.unwrapped = config.packages.flux-desktop;
};
flux-desktop = craneLib.buildPackage (individualCrateArgs // {
pname = "flux-desktop";
src = fileSetForCrate ./flux-desktop;
release = true;
cargoExtraArgs = "-p flux-desktop";
nativeBuildInputs =
lib.optionals stdenv.isDarwin
(with pkgs.darwin.apple_sdk.frameworks; [
AppKit
ApplicationServices
CoreFoundation
CoreGraphics
CoreVideo
Foundation
QuartzCore
]);
});
flux-wasm = craneLib.buildPackage (individualCrateArgs // {
pname = "flux-wasm";
src = fileSetForCrate ./flux-wasm;
cargoExtraArgs = "--package flux-wasm";
CARGO_BUILD_TARGET = "wasm32-unknown-unknown";
doCheck = false;
});
};
};
}