From ef1785628e8a7e22481245df52057aca6a983940 Mon Sep 17 00:00:00 2001 From: electria Date: Mon, 9 Nov 2026 17:39:03 -0800 Subject: [PATCH] build(flake): refactor --- flake.nix | 87 +++++++++++++++++++++++-------------------------------- 1 file changed, 36 insertions(+), 51 deletions(-) diff --git a/flake.nix b/flake.nix index e17d2c2..cb64500 100644 --- a/flake.nix +++ b/flake.nix @@ -16,43 +16,44 @@ lib = pkgs.lib; craneLib = inputs.crane.mkLib pkgs; - cargoToml = fromTOML (builtins.readFile ./Cargo.toml); - name = cargoToml.package.name; - - dlDeps = - with pkgs; - [ - # needed for both x11 and wayland - libxkbcommon - libGL - - libx11 - libxcursor - libxi - libxcb - ] - ++ lib.optionals stdenv.hostPlatform.isLinux [ - vulkan-loader - wayland - ]; - commonArgs = { - # all that's needed for artifacts and checks - nativeBuildInputs = with pkgs; [ - # pkg-config - ]; - buildInputs = with pkgs; [ - ]; - src = ./.; - }; - # Build *just* the cargo dependencies, - # to reuse them for build and test derivations. + strictDeps = true; + __structuredAttrs = true; + }; cargoArtifacts = craneLib.buildDepsOnly commonArgs; - # Build the actual crate itself, - # reusing the dependency artifacts from above. + cargoToml = fromTOML (builtins.readFile (commonArgs.src + "/Cargo.toml")); + name = cargoToml.package.name; + + binArgs = commonArgs // { + inherit cargoArtifacts; + + nativeBuildInputs = with pkgs; [ + autoPatchelfHook + ]; + buildInputs = with pkgs; [ + libgcc + ]; + runtimeDependencies = + with pkgs; + [ + libxkbcommon + libGL + + libx11 + libxcursor + libxi + libxcb + ] + ++ lib.optionals stdenv.hostPlatform.isLinux [ + vulkan-loader + wayland + ]; + + doCheck = false; + }; crate = let desktopItem = pkgs.makeDesktopItem { @@ -63,25 +64,10 @@ }; in craneLib.buildPackage ( - commonArgs + binArgs // { - inherit cargoArtifacts; - - nativeBuildInputs = commonArgs.nativeBuildInputs ++ [ - pkgs.autoPatchelfHook - ]; - - buildInputs = commonArgs.buildInputs ++ [ - pkgs.libgcc - ]; - - runtimeDependencies = dlDeps; - - doCheck = false; - postFixup = '' - mkdir -p "$out/share/applications" - ln -s "${desktopItem}"/share/applications/* "$out/share/applications/" + cp -rs "${desktopItem}"/* "$out" ''; } ); @@ -101,9 +87,8 @@ }; devShells.default = craneLib.devShell { - LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps; + LD_LIBRARY_PATH = lib.makeLibraryPath binArgs.runtimeDependencies; - inputsFrom = [ crate ]; packages = with pkgs; [ rust-analyzer mold