Skip to content

Commit f6302ee

Browse files
desktop simple nix ci
1 parent e42950b commit f6302ee

File tree

13 files changed

+280
-138
lines changed

13 files changed

+280
-138
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: Build Nix Package
2+
3+
on:
4+
push:
5+
pull_request:
6+
7+
jobs:
8+
build:
9+
runs-on: ubuntu-latest
10+
permissions:
11+
contents: read
12+
steps:
13+
- uses: actions/checkout@v4
14+
- uses: DeterminateSystems/nix-installer-action@main
15+
- uses: DeterminateSystems/magic-nix-cache-action@main
16+
17+
- name: Build Nix Package Dev
18+
run: nix build .nix#graphite-dev --print-build-logs

.nix/cef.nix renamed to .nix/deps/cef.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
{ pkgs }:
1+
{ pkgs, inputs, ... }:
22

33
let
44
libcef = pkgs.libcef.overrideAttrs (_: _: {
@@ -22,5 +22,5 @@ let
2222
'';
2323
in
2424
{
25-
CEF_PATH = cefPath;
25+
env.CEF_PATH = cefPath;
2626
}

.nix/deps/crane.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{ pkgs, inputs, ... }:
2+
3+
{
4+
lib = inputs.crane.mkLib pkgs;
5+
}
Lines changed: 25 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,24 @@
1-
{ pkgs }:
1+
{ pkgs, inputs, ... }:
22

33
let
4-
toolchainPkg = pkgs.rust-bin.nightly."2025-06-23".default.override {
5-
extensions =
6-
[ "rust-src" "rust-analyzer" "clippy" "cargo" "rustc-dev" "llvm-tools" ];
4+
extensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" "rustc-dev" "llvm-tools" ];
5+
toolchain = pkgs.rust-bin.nightly."2025-06-23".default.override {
6+
inherit extensions;
77
};
8-
toolchainRustPlatform = pkgs.makeRustPlatform {
9-
cargo = toolchainPkg;
10-
rustc = toolchainPkg;
11-
};
12-
rustc_codegen_spirv = toolchainRustPlatform.buildRustPackage (finalAttrs: {
8+
cargo = pkgs.writeShellScriptBin "cargo" ''
9+
#!${pkgs.lib.getExe pkgs.bash}
10+
11+
filtered_args=()
12+
for arg in "$@"; do
13+
case "$arg" in
14+
+nightly|+nightly-*) ;;
15+
*) filtered_args+=("$arg") ;;
16+
esac
17+
done
18+
19+
exec ${toolchain}/bin/cargo ${"\${filtered_args[@]}"}
20+
'';
21+
rustc_codegen_spirv = (pkgs.makeRustPlatform { cargo = toolchain; rustc = toolchain; }).buildRustPackage (finalAttrs: {
1322
pname = "rustc_codegen_spirv";
1423
version = "0-unstable-2025-08-04";
1524
src = pkgs.fetchFromGitHub {
@@ -27,21 +36,11 @@ let
2736
];
2837
doCheck = false;
2938
});
30-
cargoWrapper = pkgs.writeShellScriptBin "cargo" ''
31-
#!${pkgs.lib.getExe pkgs.bash}
32-
33-
filtered_args=()
34-
for arg in "$@"; do
35-
case "$arg" in
36-
+nightly|+nightly-*) ;;
37-
*) filtered_args+=("$arg") ;;
38-
esac
39-
done
40-
41-
exec ${toolchainPkg}/bin/cargo ${"\${filtered_args[@]}"}
42-
'';
43-
in {
44-
RUST_GPU_PATH_OVERRIDE = "${cargoWrapper}/bin:${toolchainPkg}/bin";
45-
RUSTC_CODEGEN_SPIRV_PATH =
46-
"${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
39+
in
40+
{
41+
toolchain = toolchain;
42+
env = {
43+
RUST_GPU_PATH_OVERRIDE = "${cargo}/bin:${toolchain}/bin";
44+
RUSTC_CODEGEN_SPIRV_PATH = "${rustc_codegen_spirv}/lib/librustc_codegen_spirv.so";
45+
};
4746
}

.nix/dev.nix

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
{ info, pkgs, inputs, deps, libs, tools, ... }:
2+
3+
pkgs.mkShell ({
4+
packages = tools.all;
5+
6+
LD_LIBRARY_PATH = "${pkgs.lib.makeLibraryPath libs.desktop-all}:${deps.cef.env.CEF_PATH}";
7+
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";
8+
9+
shellHook = ''
10+
alias cargo='mold --run cargo'
11+
'';
12+
} // deps.cef.env // deps.rustGPU.env)

.nix/flake.lock

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

.nix/flake.nix

Lines changed: 60 additions & 99 deletions
Original file line numberDiff line numberDiff line change
@@ -19,52 +19,68 @@
1919
inputs.nixpkgs.follows = "nixpkgs";
2020
};
2121
flake-utils.url = "github:numtide/flake-utils";
22+
crane.url = "github:ipetkov/crane";
2223

2324
# This is used to provide a identical development shell at `shell.nix` for users that do not use flakes
2425
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.tar.gz";
2526
};
2627

27-
outputs = { nixpkgs, rust-overlay, flake-utils, ... }:
28-
flake-utils.lib.eachDefaultSystem (system:
29-
let
30-
overlays = [ (import rust-overlay) ];
31-
pkgs = import nixpkgs { inherit system overlays; };
32-
33-
rustExtensions = [ "rust-src" "rust-analyzer" "clippy" "cargo" ];
34-
rust = pkgs.rust-bin.stable.latest.default.override {
35-
targets = [ "wasm32-unknown-unknown" ];
36-
extensions = rustExtensions;
37-
};
38-
39-
# Shared build inputs; libraries that need to be in LD_LIBRARY_PATH
40-
buildInputs = [
28+
outputs = inputs: inputs.flake-utils.lib.eachDefaultSystem (system:
29+
let
30+
info = {
31+
pname = "graphite";
32+
version = "unstable";
33+
src = ./..;
34+
};
35+
36+
pkgs = import inputs.nixpkgs {
37+
inherit system;
38+
overlays = [ (import inputs.rust-overlay) ];
39+
};
40+
41+
deps = {
42+
rust = import ./deps/rust.nix { inherit pkgs inputs; };
43+
crane = import ./deps/crane.nix { inherit pkgs inputs; };
44+
cef = import ./deps/cef.nix { inherit pkgs inputs; };
45+
rustGPU = import ./deps/rust-gpu.nix { inherit pkgs inputs; };
46+
};
47+
48+
libs = rec {
49+
desktop = [
4150
pkgs.wayland
4251
pkgs.openssl
4352
pkgs.vulkan-loader
4453
pkgs.libraw
4554
pkgs.libGL
46-
47-
# X11 libraries, not needed on wayland! Remove when x11 is finally dead
55+
];
56+
desktop-x11 = [
4857
pkgs.libxkbcommon
4958
pkgs.xorg.libXcursor
5059
pkgs.xorg.libxcb
5160
pkgs.xorg.libX11
5261
];
62+
desktop-all = desktop ++ desktop-x11;
63+
};
5364

54-
# Packages needed to build the package
55-
buildTools = [
56-
rust
65+
tools = rec {
66+
desktop = [
67+
pkgs.pkg-config
68+
];
69+
frontend = [
70+
pkgs.lld
5771
pkgs.nodejs
5872
pkgs.nodePackages.npm
5973
pkgs.binaryen
6074
pkgs.wasm-bindgen-cli_0_2_100
6175
pkgs.wasm-pack
62-
pkgs.pkg-config
6376
pkgs.cargo-about
6477
];
78+
dev = [
79+
pkgs.rustc
80+
pkgs.cargo
81+
pkgs.rust-analyzer
82+
pkgs.clippy
6583

66-
# Development tools; not needed to build the package
67-
devTools = [
6884
pkgs.git
6985

7086
pkgs.cargo-watch
@@ -79,81 +95,26 @@
7995
pkgs.samply
8096
pkgs.cargo-flamegraph
8197
];
82-
83-
cefEnv = import ./cef.nix { inherit pkgs; };
84-
rustGPUEnv = import ./rust-gpu.nix { inherit pkgs; };
85-
86-
libPath = "${pkgs.lib.makeLibraryPath buildInputs}:${cefEnv.CEF_PATH}";
87-
in {
88-
devShells.default = pkgs.mkShell ({
89-
packages = buildInputs ++ buildTools ++ devTools;
90-
91-
LD_LIBRARY_PATH = libPath;
92-
XDG_DATA_DIRS =
93-
"${pkgs.gsettings-desktop-schemas}/share/gsettings-schemas/${pkgs.gsettings-desktop-schemas.name}:${pkgs.gtk3}/share/gsettings-schemas/${pkgs.gtk3.name}:$XDG_DATA_DIRS";
94-
95-
shellHook = ''
96-
alias cargo='mold --run cargo'
97-
'';
98-
} // cefEnv // rustGPUEnv);
99-
100-
packages.default = pkgs.rustPlatform.buildRustPackage (finalAttrs: {
101-
pname = "graphite-editor";
102-
version = "unstable";
103-
src = pkgs.lib.cleanSource ./..;
104-
105-
cargoLock = {
106-
lockFile = ../Cargo.lock;
107-
allowBuiltinFetchGit = true;
108-
};
109-
110-
# TODO: Remove the need for this hash by using individual package resolutions and hashes from package-lock.json
111-
npmDeps = pkgs.fetchNpmDeps {
112-
inherit (finalAttrs) pname version;
113-
src = "${finalAttrs.src}/frontend";
114-
hash = "sha256-UWuJpKNYj2Xn34rpMDZ75pzMYUOLQjPeGuJ/QlPbX9A=";
115-
};
116-
117-
npmRoot = "frontend";
118-
npmConfigScript = "setup";
119-
makeCacheWritable = true;
120-
121-
buildInputs = buildInputs;
122-
nativeBuildInputs = buildTools ++ [
123-
pkgs.rustPlatform.cargoSetupHook
124-
pkgs.npmHooks.npmConfigHook
125-
pkgs.makeWrapper
126-
];
127-
128-
env = cefEnv // rustGPUEnv;
129-
130-
buildPhase = ''
131-
export HOME="$TMPDIR"
132-
133-
pushd frontend
134-
npm run build-native
135-
popd
136-
cargo build -r -p graphite-desktop
137-
'';
138-
139-
installPhase = ''
140-
mkdir -p $out/bin
141-
cp target/release/graphite-desktop $out/bin/graphite-editor
142-
143-
mkdir -p $out/share/applications
144-
cp $src/desktop/assets/*.desktop $out/share/applications/
145-
146-
mkdir -p $out/share/icons/hicolor/scalable/apps
147-
cp $src/desktop/assets/graphite-icon-color.svg $out/share/icons/hicolor/scalable/apps/
148-
'';
149-
150-
doCheck = false;
151-
152-
postFixup = ''
153-
wrapProgram "$out/bin/graphite-editor" \
154-
--prefix LD_LIBRARY_PATH : "${libPath}" \
155-
--set CEF_PATH "${cefEnv.CEF_PATH}"
156-
'';
157-
});
158-
});
98+
all = frontend ++ dev;
99+
};
100+
in
101+
{
102+
packages = rec {
103+
graphiteWithArgs = args: (import ./pkgs/graphite.nix {
104+
pkgs = pkgs // { inherit graphene-raster-nodes-shaders; };
105+
inherit info inputs deps libs tools;
106+
}) args;
107+
graphite = graphiteWithArgs { };
108+
graphite-dev = graphiteWithArgs { dev = true; };
109+
graphite-without-resources = graphiteWithArgs { embeddedResources = false; };
110+
graphite-without-resources-dev = graphiteWithArgs { embeddedResources = false; dev = true; };
111+
#TODO: graphene-cli = import ./pkgs/graphene-cli.nix { inherit info pkgs inputs deps libs tools; };
112+
graphene-raster-nodes-shaders = import ./pkgs/graphene-raster-nodes-shaders.nix { inherit info pkgs inputs deps libs tools; };
113+
114+
default = graphite;
115+
};
116+
117+
devShells.default = import ./dev.nix { inherit pkgs deps libs tools; };
118+
}
119+
);
159120
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
{ info, pkgs, deps, libs, tools, ... }:
2+
3+
(deps.crane.lib.overrideToolchain (_: deps.rustGPU.toolchain)).buildPackage {
4+
pname = "graphene-raster-nodes-shaders";
5+
inherit (info) version src;
6+
7+
cargoVendorDir = deps.crane.lib.vendorMultipleCargoDeps {
8+
inherit (deps.crane.lib.findCargoFiles (deps.crane.lib.cleanCargoSource info.src)) cargoConfigs;
9+
cargoLockList = [
10+
"${info.src}/Cargo.lock"
11+
"${deps.rustGPU.toolchain.passthru.availableComponents.rust-src}/lib/rustlib/src/rust/library/Cargo.lock"
12+
];
13+
};
14+
15+
strictDeps = true;
16+
17+
env = deps.rustGPU.env;
18+
19+
buildPhase = ''
20+
cargo build -r -p graphene-raster-nodes-shaders
21+
'';
22+
23+
installPhase = ''
24+
cp target/spirv-builder/spirv-unknown-naga-wgsl/release/deps/graphene_raster_nodes_shaders_entrypoint.wgsl $out
25+
'';
26+
27+
doCheck = false;
28+
}

0 commit comments

Comments
 (0)