|
12 | 12 | # - Development shell: `nix develop .nix` from the project root |
13 | 13 | # - Run in dev shell with direnv: add `use flake` to .envrc |
14 | 14 | { |
15 | | - description = "Development environment and build configuration"; |
16 | | - |
17 | 15 | inputs = { |
18 | 16 | nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; |
19 | 17 | rust-overlay = { |
|
40 | 38 | extensions = rustExtensions; |
41 | 39 | }; |
42 | 40 |
|
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 |
106 | 48 |
|
107 | 49 | # 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 |
112 | 54 | ]; |
113 | 55 |
|
114 | | - # Development tools that don't need to be in LD_LIBRARY_PATH |
| 56 | + # Packages needed to build the package |
115 | 57 | buildTools = [ |
116 | 58 | rust |
117 | 59 | pkgs.nodejs |
|
120 | 62 | pkgs.wasm-bindgen-cli |
121 | 63 | pkgs.wasm-pack |
122 | 64 | pkgs.pkg-config |
123 | | - pkgs.git |
124 | 65 | 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 |
125 | 75 |
|
126 | 76 | # Linker |
127 | 77 | 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 |
134 | 78 |
|
135 | 79 | # Profiling tools |
136 | | - gnuplot |
137 | | - samply |
138 | | - cargo-flamegraph |
| 80 | + pkgs.gnuplot |
| 81 | + pkgs.samply |
| 82 | + pkgs.cargo-flamegraph |
139 | 83 | ]; |
| 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}"; |
140 | 89 | in |
141 | 90 | { |
142 | | - # Development shell configuration |
143 | | - devShells.default = pkgs.mkShell { |
| 91 | + devShells.default = pkgs.mkShell ({ |
144 | 92 | packages = buildInputs ++ buildTools ++ devTools; |
145 | 93 |
|
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"; |
152 | 96 |
|
153 | 97 | shellHook = '' |
154 | 98 | alias cargo='mold --run cargo' |
155 | 99 | ''; |
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 | + }); |
157 | 154 | } |
158 | 155 | ); |
159 | 156 | } |
0 commit comments