build(flake): refactor

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

View file

@ -16,13 +16,29 @@
lib = pkgs.lib;
craneLib = inputs.crane.mkLib pkgs;
cargoToml = fromTOML (builtins.readFile ./Cargo.toml);
commonArgs = {
src = ./.;
strictDeps = true;
__structuredAttrs = true;
};
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
cargoToml = fromTOML (builtins.readFile (commonArgs.src + "/Cargo.toml"));
name = cargoToml.package.name;
dlDeps =
binArgs = commonArgs // {
inherit cargoArtifacts;
nativeBuildInputs = with pkgs; [
autoPatchelfHook
];
buildInputs = with pkgs; [
libgcc
];
runtimeDependencies =
with pkgs;
[
# needed for both x11 and wayland
libxkbcommon
libGL
@ -36,23 +52,8 @@
wayland
];
commonArgs = {
# all that's needed for artifacts and checks
nativeBuildInputs = with pkgs; [
# pkg-config
];
buildInputs = with pkgs; [
];
src = ./.;
doCheck = false;
};
# Build *just* the cargo dependencies,
# to reuse them for build and test derivations.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself,
# reusing the dependency artifacts from above.
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