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; lib = pkgs.lib;
craneLib = inputs.crane.mkLib pkgs; 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; name = cargoToml.package.name;
dlDeps = binArgs = commonArgs // {
inherit cargoArtifacts;
nativeBuildInputs = with pkgs; [
autoPatchelfHook
];
buildInputs = with pkgs; [
libgcc
];
runtimeDependencies =
with pkgs; with pkgs;
[ [
# needed for both x11 and wayland
libxkbcommon libxkbcommon
libGL libGL
@ -36,23 +52,8 @@
wayland wayland
]; ];
commonArgs = { doCheck = false;
# 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.
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Build the actual crate itself,
# reusing the dependency artifacts from above.
crate = crate =
let let
desktopItem = pkgs.makeDesktopItem { desktopItem = pkgs.makeDesktopItem {
@ -63,25 +64,10 @@
}; };
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 +87,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