Skip to content

Commit 8d3a8c2

Browse files
Desktop: Add nix package to flake (#3258)
* update cargo-gpu, remove legacy-target-specs to fix nix builds * add nix package to flake * update cargo hash * fix merge --------- Co-authored-by: firestar99 <[email protected]>
1 parent 3509f0b commit 8d3a8c2

File tree

4 files changed

+155
-91
lines changed

4 files changed

+155
-91
lines changed

.nix/cef.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{ pkgs }:
2+
3+
let
4+
libcef = pkgs.libcef.overrideAttrs (_: _: {
5+
postInstall = ''
6+
strip $out/lib/*
7+
'';
8+
});
9+
cefPath = pkgs.runCommand "cef-path" {} ''
10+
mkdir -p $out
11+
12+
ln -s ${libcef}/include $out/include
13+
find ${libcef}/lib -type f -name "*" -exec ln -s {} $out/ \;
14+
find ${libcef}/libexec -type f -name "*" -exec ln -s {} $out/ \;
15+
cp -r ${libcef}/share/cef/* $out/
16+
17+
echo '${builtins.toJSON {
18+
type = "minimal";
19+
name = builtins.baseNameOf libcef.src.url;
20+
sha1 = "";
21+
}}' > $out/archive.json
22+
'';
23+
in
24+
{
25+
CEF_PATH = cefPath;
26+
}

.nix/flake.nix

Lines changed: 86 additions & 89 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,6 @@
1212
# - Development shell: `nix develop .nix` from the project root
1313
# - Run in dev shell with direnv: add `use flake` to .envrc
1414
{
15-
description = "Development environment and build configuration";
16-
1715
inputs = {
1816
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
1917
rust-overlay = {
@@ -40,78 +38,22 @@
4038
extensions = rustExtensions;
4139
};
4240

43-
rustGPUToolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
44-
extensions = rustExtensions ++ [ "rustc-dev" "llvm-tools" ];
45-
};
46-
rustGPUToolchainRustPlatform = pkgs.makeRustPlatform {
47-
cargo = rustGPUToolchainPkg;
48-
rustc = rustGPUToolchainPkg;
49-
};
50-
rustc_codegen_spirv = rustGPUToolchainRustPlatform.buildRustPackage (finalAttrs: {
51-
pname = "rustc_codegen_spirv";
52-
version = "0-unstable-2025-08-04";
53-
src = pkgs.fetchFromGitHub {
54-
owner = "Rust-GPU";
55-
repo = "rust-gpu";
56-
rev = "c12f216121820580731440ee79ebc7403d6ea04f";
57-
hash = "sha256-rG1cZvOV0vYb1dETOzzbJ0asYdE039UZImobXZfKIno=";
58-
};
59-
cargoHash = "sha256-AEigcEc5wiBd3zLqWN/2HSbkfOVFneAqNvg9HsouZf4=";
60-
cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-compiled-tools" "--no-default-features" ];
61-
doCheck = false;
62-
});
63-
rustGpuCargo = pkgs.writeShellScriptBin "cargo" ''
64-
#!${pkgs.lib.getExe pkgs.bash}
65-
66-
filtered_args=()
67-
for arg in "$@"; do
68-
case "$arg" in
69-
+nightly|+nightly-*) ;;
70-
*) filtered_args+=("$arg") ;;
71-
esac
72-
done
73-
74-
exec ${rustGPUToolchainPkg}/bin/cargo ${"\${filtered_args[@]}"}
75-
'';
76-
rustGpuPathOverride = "${rustGpuCargo}/bin:${rustGPUToolchainPkg}/bin";
77-
78-
libcef = pkgs.libcef.overrideAttrs (_: _: {
79-
postInstall = ''
80-
strip $out/lib/*
81-
'';
82-
});
83-
libcefPath = pkgs.runCommand "libcef-path" {} ''
84-
mkdir -p $out
85-
86-
ln -s ${libcef}/include $out/include
87-
find ${libcef}/lib -type f -name "*" -exec ln -s {} $out/ \;
88-
find ${libcef}/libexec -type f -name "*" -exec ln -s {} $out/ \;
89-
cp -r ${libcef}/share/cef/* $out/
90-
91-
echo '${builtins.toJSON {
92-
type = "minimal";
93-
name = builtins.baseNameOf libcef.src.url;
94-
sha1 = "";
95-
}}' > $out/archive.json
96-
'';
97-
98-
# Shared build inputs - system libraries that need to be in LD_LIBRARY_PATH
99-
buildInputs = with pkgs; [
100-
# System libraries
101-
wayland
102-
openssl
103-
vulkan-loader
104-
libraw
105-
libGL
41+
# Shared build inputs; libraries that need to be in LD_LIBRARY_PATH
42+
buildInputs = [
43+
pkgs.wayland
44+
pkgs.openssl
45+
pkgs.vulkan-loader
46+
pkgs.libraw
47+
pkgs.libGL
10648

10749
# X11 libraries, not needed on wayland! Remove when x11 is finally dead
108-
libxkbcommon
109-
xorg.libXcursor
110-
xorg.libxcb
111-
xorg.libX11
50+
pkgs.libxkbcommon
51+
pkgs.xorg.libXcursor
52+
pkgs.xorg.libxcb
53+
pkgs.xorg.libX11
11254
];
11355

114-
# Development tools that don't need to be in LD_LIBRARY_PATH
56+
# Packages needed to build the package
11557
buildTools = [
11658
rust
11759
pkgs.nodejs
@@ -120,40 +62,95 @@
12062
pkgs.wasm-bindgen-cli
12163
pkgs.wasm-pack
12264
pkgs.pkg-config
123-
pkgs.git
12465
pkgs.cargo-about
66+
];
67+
68+
# Development tools; not needed to build the package
69+
devTools = [
70+
pkgs.git
71+
72+
pkgs.cargo-watch
73+
pkgs.cargo-nextest
74+
pkgs.cargo-expand
12575

12676
# Linker
12777
pkgs.mold
128-
];
129-
# Development tools that don't need to be in LD_LIBRARY_PATH
130-
devTools = with pkgs; [
131-
cargo-watch
132-
cargo-nextest
133-
cargo-expand
13478

13579
# Profiling tools
136-
gnuplot
137-
samply
138-
cargo-flamegraph
80+
pkgs.gnuplot
81+
pkgs.samply
82+
pkgs.cargo-flamegraph
13983
];
84+
85+
cefEnv = import ./cef.nix { inherit pkgs; };
86+
rustGPUEnv = import ./rust-gpu.nix { inherit pkgs; };
87+
88+
libPath = "${pkgs.lib.makeLibraryPath buildInputs}:${cefEnv.CEF_PATH}";
14089
in
14190
{
142-
# Development shell configuration
143-
devShells.default = pkgs.mkShell {
91+
devShells.default = pkgs.mkShell ({
14492
packages = buildInputs ++ buildTools ++ devTools;
14593

146-
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath buildInputs}:${libcefPath}";
147-
CEF_PATH = libcefPath;
148-
XDG_DATA_DIRS="${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
149-
150-
RUST_GPU_PATH_OVERRIDE = rustGpuPathOverride;
151-
RUSTC_CODEGEN_SPIRV_PATH = "${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
94+
LD_LIBRARY_PATH = libPath;
95+
XDG_DATA_DIRS = "${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
15296

15397
shellHook = ''
15498
alias cargo='mold --run cargo'
15599
'';
156-
};
100+
} // cefEnv // rustGPUEnv);
101+
102+
packages.default = pkgs.stdenv.mkDerivation(finalAttrs: {
103+
pname = "graphite-editor";
104+
version = "unstable";
105+
src = pkgs.lib.cleanSource ./..;
106+
107+
cargoDeps = pkgs.rustPlatform.fetchCargoVendor {
108+
src = finalAttrs.src;
109+
hash = "sha256-BVIQIZbGW19Rof0J7U2r6XFCUC52hb7+uaE1di4bV4A=";
110+
};
111+
112+
npmDeps = pkgs.fetchNpmDeps {
113+
inherit (finalAttrs) pname version;
114+
src = "${finalAttrs.src}/frontend";
115+
hash = "sha256-UWuJpKNYj2Xn34rpMDZ75pzMYUOLQjPeGuJ/QlPbX9A=";
116+
};
117+
118+
npmRoot = "frontend";
119+
npmConfigScript = "setup";
120+
makeCacheWritable = true;
121+
122+
buildInputs = buildInputs;
123+
nativeBuildInputs = buildTools ++ [
124+
pkgs.rustPlatform.cargoSetupHook
125+
pkgs.npmHooks.npmConfigHook
126+
pkgs.makeWrapper
127+
];
128+
129+
env = cefEnv // rustGPUEnv;
130+
131+
buildPhase = ''
132+
export HOME="$TMPDIR"
133+
134+
npm run build-desktop
135+
'';
136+
137+
installPhase = ''
138+
mkdir -p $out/bin
139+
cp target/release/graphite-desktop $out/bin/graphite-editor
140+
141+
mkdir -p $out/share/applications
142+
cp $src/desktop/assets/*.desktop $out/share/applications/
143+
144+
mkdir -p $out/share/icons/hicolor/scalable/apps
145+
cp $src/desktop/assets/graphite-icon-color.svg $out/share/icons/hicolor/scalable/apps/
146+
'';
147+
148+
postFixup = ''
149+
wrapProgram "$out/bin/graphite-editor" \
150+
--prefix LD_LIBRARY_PATH : "${libPath}" \
151+
--set CEF_PATH "${cefEnv.CEF_PATH}"
152+
'';
153+
});
157154
}
158155
);
159156
}

.nix/rust-gpu.nix

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
{ pkgs }:
2+
3+
let
4+
toolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
5+
extensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" "rustc-dev" "llvm-tools" ];
6+
};
7+
toolchainRustPlatform = pkgs.makeRustPlatform {
8+
cargo = toolchainPkg;
9+
rustc = toolchainPkg;
10+
};
11+
rustc_codegen_spirv = toolchainRustPlatform.buildRustPackage (finalAttrs: {
12+
pname = "rustc_codegen_spirv";
13+
version = "0-unstable-2025-08-04";
14+
src = pkgs.fetchFromGitHub {
15+
owner = "Rust-GPU";
16+
repo = "rust-gpu";
17+
rev = "c12f216121820580731440ee79ebc7403d6ea04f";
18+
hash = "sha256-rG1cZvOV0vYb1dETOzzbJ0asYdE039UZImobXZfKIno=";
19+
};
20+
cargoHash = "sha256-AEigcEc5wiBd3zLqWN/2HSbkfOVFneAqNvg9HsouZf4=";
21+
cargoBuildFlags = [ "-p" "rustc_codegen_spirv" "--features=use-compiled-tools" "--no-default-features" ];
22+
doCheck = false;
23+
});
24+
cargoWrapper = pkgs.writeShellScriptBin "cargo" ''
25+
#!${pkgs.lib.getExe pkgs.bash}
26+
27+
filtered_args=()
28+
for arg in "$@"; do
29+
case "$arg" in
30+
+nightly|+nightly-*) ;;
31+
*) filtered_args+=("$arg") ;;
32+
esac
33+
done
34+
35+
exec ${toolchainPkg}/bin/cargo ${"\${filtered_args[@]}"}
36+
'';
37+
in
38+
{
39+
RUST_GPU_PATH_OVERRIDE = "${cargoWrapper}/bin:${toolchainPkg}/bin";
40+
RUSTC_CODEGEN_SPIRV_PATH = "${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
41+
}

frontend/package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"lint-fix": "eslint . --fix && tsc --noEmit",
2222
"---------- INTERNAL ----------": "",
2323
"setup": "node package-installer.js",
24-
"native:build-dev": "wasm-pack build ./wasm --dev --target=web --features native",
25-
"native:build-production": "wasm-pack build ./wasm --release --target=web --features native",
24+
"native:build-dev": "wasm-pack build ./wasm --dev --target=web --no-default-features --features native",
25+
"native:build-production": "wasm-pack build ./wasm --release --target=web --no-default-features --features native",
2626
"wasm:build-dev": "wasm-pack build ./wasm --dev --target=web",
2727
"wasm:build-profiling": "wasm-pack build ./wasm --profiling --target=web",
2828
"wasm:build-production": "wasm-pack build ./wasm --release --target=web",

0 commit comments

Comments
 (0)