build(flake): refactor

This commit is contained in:
electria 2026-11-09 17:39:03 -08:00
commit a016fddff6
Signed by: electria
SSH key fingerprint: SHA256:8LlB3ucPbBHqozqkhsNbaV5oG3SlzzqUj8FZDL6IPQs

View file

@ -16,43 +16,44 @@
lib = pkgs.lib; lib = pkgs.lib;
craneLib = inputs.crane.mkLib pkgs; 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 = { commonArgs = {
# all that's needed for artifacts and checks
nativeBuildInputs = with pkgs; [
# pkg-config
];
buildInputs = with pkgs; [
];
src = ./.; src = ./.;
};
# Build *just* the cargo dependencies, strictDeps = true;
# to reuse them for build and test derivations. __structuredAttrs = true;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs; cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself, cargoToml = fromTOML (builtins.readFile (commonArgs.src + "/Cargo.toml"));
# reusing the dependency artifacts from above. 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 = crate =
let let
desktopItem = pkgs.makeDesktopItem { desktopItem = pkgs.makeDesktopItem {
@ -63,25 +64,11 @@
}; };
in in
craneLib.buildPackage ( craneLib.buildPackage (
commonArgs binArgs
// { // {
inherit cargoArtifacts;
nativeBuildInputs = commonArgs.nativeBuildInputs ++ [
pkgs.autoPatchelfHook
];
buildInputs = commonArgs.buildInputs ++ [
pkgs.libgcc
];
runtimeDependencies = dlDeps;
doCheck = false;
postFixup = '' postFixup = ''
mkdir -p "$out/share/applications" cp -rs "${desktopItem}"/* "$out"
ln -s "${desktopItem}"/share/applications/* "$out/share/applications/"
''; '';
} }
); );
@ -101,9 +88,8 @@
}; };
devShells.default = craneLib.devShell { devShells.default = craneLib.devShell {
LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps; LD_LIBRARY_PATH = lib.makeLibraryPath binArgs.runtimeDependencies;
inputsFrom = [ crate ];
packages = with pkgs; [ packages = with pkgs; [
rust-analyzer rust-analyzer
mold mold