This commit is contained in:
2026-08-31 09:52:01 +01:00
parent 0d9d960ed4
commit edcb418d64
8 changed files with 3839 additions and 0 deletions
+106
View File
@@ -0,0 +1,106 @@
{
description = "Build a cargo project without extra checks";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
{
self,
nixpkgs,
crane,
flake-utils,
...
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = nixpkgs.legacyPackages.${system};
craneLib = crane.mkLib pkgs;
# Runtime/shared libraries required by iced/iced_layershell/winit.
# winit dlopens libwayland at runtime, so these must be on
# LD_LIBRARY_PATH (see https://github.com/iced-rs/iced/issues/2385).
guiLibs = [
pkgs.wayland
pkgs.wayland-protocols
pkgs.libxkbcommon
pkgs.vulkan-loader
pkgs.libx11
pkgs.libxcursor
pkgs.libxrandr
pkgs.libxi
pkgs.libxcb
];
# Common arguments can be set here to avoid repeating them later
# Note: changes here will rebuild all dependency crates
commonArgs = {
# Exclude build outputs regardless of git state (this repo is not
# git-initialized, so cleanCargoSource would otherwise copy target/).
src = pkgs.lib.cleanSourceWith {
src = ./.;
filter = path: type:
let
base = baseNameOf (toString path);
in
!(type == "directory" && (base == "target" || base == "result" || base == ".direnv"));
};
strictDeps = true;
nativeBuildInputs = [
pkgs.pkg-config
];
buildInputs =
guiLibs
++ pkgs.lib.optionals pkgs.stdenv.hostPlatform.isDarwin [
# Additional darwin specific inputs can be set here
pkgs.libiconv
];
};
my-crate = craneLib.buildPackage (
commonArgs
// {
cargoArtifacts = craneLib.buildDepsOnly commonArgs;
# Additional environment variables or build phases/hooks can be set
# here *without* rebuilding all dependency crates
# MY_CUSTOM_VAR = "some value";
}
);
in
{
checks = {
inherit my-crate;
};
packages.default = my-crate;
apps.default = flake-utils.lib.mkApp {
drv = my-crate;
};
devShells.default = craneLib.devShell {
# Inherit inputs from checks.
checks = self.checks.${system};
# Put the GUI shared libraries on the runtime library path so winit
# can dlopen libwayland and wgpu can find the vulkan loader.
shellHook = ''
export LD_LIBRARY_PATH="$LD_LIBRARY_PATH:${pkgs.lib.makeLibraryPath guiLibs}"
'';
# Extra inputs can be added here; cargo and rustc are provided by default.
packages = guiLibs;
};
}
);
}