# SPDX-FileCopyrightText: 2024 Simon Bruder # # SPDX-License-Identifier: MPL-2.0 { inputs = { flake-utils.url = "github:numtide/flake-utils"; nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; rust-overlay.url = "github:oxalica/rust-overlay"; naersk.url = "github:nix-community/naersk"; git-hooks.url = "github:cachix/git-hooks.nix"; }; outputs = { self, flake-utils, nixpkgs, rust-overlay, naersk, git-hooks }: flake-utils.lib.eachDefaultSystem (system: let pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlays.default ]; }; rustPackage = pkgs.rust-bin.stable.latest.default; rustPackageNightly = pkgs.rust-bin.nightly.latest.default; naerskStable = pkgs.callPackage naersk { rustc = rustPackage; cargo = rustPackage; }; naerskNightly = pkgs.callPackage naersk { rustc = rustPackageNightly; cargo = rustPackageNightly; }; cargoTestOptions = o: o ++ [ "--workspace" ]; in { checks = { pre-commit-check = git-hooks.lib.${system}.run { src = self; hooks = { cargo-check = { enable = true; package = rustPackageNightly; }; cargo-deny = { enable = true; name = "cargo-deny"; entry = "cargo deny --workspace check"; pass_filenames = false; }; clippy = { enable = true; settings = { denyWarnings = true; }; packageOverrides = { cargo = rustPackageNightly; clippy = rustPackageNightly; }; }; nixpkgs-fmt.enable = true; reuse = { enable = true; name = "reuse"; entry = "reuse lint"; pass_filenames = false; }; rustfmt = { enable = true; packageOverrides = { cargo = rustPackageNightly; rustfmt = rustPackageNightly; }; }; }; }; }; packages = rec { embed-licensing = naerskStable.buildPackage { src = self; doCheck = true; doDoc = true; doDocFail = true; inherit cargoTestOptions; }; embed-licensing_nightly = naerskNightly.buildPackage { name = "embed-licensing_nightly"; src = self; doCheck = true; doDoc = true; doDocFail = true; inherit cargoTestOptions; RUSTDOCFLAGS = "--cfg docsrs"; }; embed-licensing_feature_tests = naerskStable.buildPackage { name = "embed-licensing_feature_tests"; src = self; nativeBuildInputs = with pkgs; [ cargo-all-features ]; doCheck = true; # no $cargo_test_options as --workspace does not work with cargo-all-features cargoTestCommands = _: nixpkgs.lib.singleton "cargo $cargo_options test-all-features"; cargoBuild = _: ""; # mode = "test" does not respect cargoTestCommands, so this is set to avoid building }; default = embed-licensing; ci = pkgs.linkFarm "ci" (map (pkg: { name = pkg.name; path = pkg; }) [ embed-licensing embed-licensing_nightly embed-licensing_feature_tests ]); }; devShells.default = pkgs.mkShell { buildInputs = [ rustPackageNightly ] ++ (with pkgs; [ cargo-all-features cargo-deny clippy reuse ]); shellHook = '' ${self.checks.${system}.pre-commit-check.shellHook} ''; }; }); }