imagey/flake.nix

130 lines
3.3 KiB
Nix

{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
crane.url = "github:ipetkov/crane";
flake-utils.url = "github:numtide/flake-utils";
};
outputs =
inputs:
inputs.flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import inputs.nixpkgs { inherit system; };
lib = pkgs.lib;
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
vulkan-loader
wayland
libx11
libxcursor
libxi
libxcb
];
commonArgs = {
# all that's needed for artifacts and checks
nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
libjxl
];
src = ./.;
};
LD_LIBRARY_PATH = lib.makeLibraryPath dlDeps;
# 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 {
inherit name;
desktopName = name;
icon = name;
exec = name;
mimeTypes = [
"image/png"
"image/jpeg"
"image/gif"
"image/webp"
"image/avif"
"image/jxl"
"image/tiff"
"image/bmp"
"image/vnd.microsoft.icon" # .ico
];
};
in
craneLib.buildPackage (
commonArgs
// {
inherit cargoArtifacts;
nativeBuildInputs =
commonArgs.nativeBuildInputs
++ [
pkgs.autoPatchelfHook
]
++ lib.optional pkgs.stdenv.hostPlatform.isLinux pkgs.makeBinaryWrapper;
buildInputs = commonArgs.buildInputs ++ [
pkgs.libgcc
pkgs.zenity
];
runtimeDependencies = dlDeps;
doCheck = false;
postFixup = ''
mkdir -p "$out/share/applications"
ln -s "${desktopItem}"/share/applications/* "$out/share/applications/"
''
+ lib.optionalString pkgs.stdenv.hostPlatform.isLinux /* sh */ ''
wrapProgram $out/bin/${name} --inherit-argv0 \
--prefix PATH : ${lib.makeBinPath [ pkgs.zenity ]}
'';
}
);
in
{
packages.default = crate;
checks = {
crate-clippy = craneLib.cargoClippy (
commonArgs
// {
inherit cargoArtifacts;
cargoClippyExtraArgs = "-- --deny warnings";
}
);
};
devShells.default = craneLib.devShell {
inherit LD_LIBRARY_PATH;
inputsFrom = [ crate ];
packages = [ pkgs.rust-analyzer ];
};
}
);
}