build(flake): refactor
This commit is contained in:
parent
63c797e346
commit
ef1785628e
1 changed files with 33 additions and 48 deletions
87
flake.nix
87
flake.nix
|
|
@ -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,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
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue