build(flake): refactor
This commit is contained in:
parent
63c797e346
commit
a016fddff6
1 changed files with 33 additions and 47 deletions
60
flake.nix
60
flake.nix
|
|
@ -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,11 @@
|
|||
};
|
||||
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 +88,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
|
||||
|
|
|
|||
Loading…
Reference in a new issue