From a434c31af9376c739837b2d1fadaf8c1b84c843e Mon Sep 17 00:00:00 2001 From: Sophie Forrest Date: Wed, 9 Oct 2024 12:35:49 +1300 Subject: chore(flake): improve nix infrastructure --- nix/package.nix | 100 +++++++++++++++++++++++++++++++++++++++++++------------- 1 file changed, 77 insertions(+), 23 deletions(-) (limited to 'nix/package.nix') diff --git a/nix/package.nix b/nix/package.nix index 1ee01ff..ef9ac8f 100644 --- a/nix/package.nix +++ b/nix/package.nix @@ -1,29 +1,83 @@ -{ - lib, - pkgs, - rustPlatform, - ... -}: -rustPlatform.buildRustPackage { - pname = "vuw_course_scraper"; - version = "0.1.0"; - - src = builtins.path { - name = "vuw_course_scraper"; - path = ../.; - }; +{inputs, ...}: { + perSystem = { + lib, + system, + pkgs, + ... + }: let + inherit (inputs) advisory-db crane fenix; + + craneLib = crane.mkLib pkgs; + src = craneLib.cleanCargoSource ../.; + + commonArgs = { + inherit src; + strictDeps = true; + + nativeBuildInputs = with pkgs; [openssl openssl.dev pkg-config]; + + LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.openssl]; + PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; + }; + + craneLibLlvmTools = + craneLib.overrideToolchain + (fenix.packages.${system}.complete.withComponents [ + "cargo" + "llvm-tools" + "rustc" + ]); + + cargoArtifacts = craneLib.buildDepsOnly commonArgs; + + vuw-scraper = craneLib.buildPackage (commonArgs + // { + inherit cargoArtifacts; + }); + in { + checks = { + inherit vuw-scraper; + + vuw-scraper-clippy = craneLib.cargoClippy (commonArgs + // { + inherit cargoArtifacts; + cargoClippyExtraArgs = "--all-targets -- --deny warnings"; + }); + + vuw-scraper-doc = craneLib.cargoDoc (commonArgs + // { + inherit cargoArtifacts; + }); + + vuw-scraper-audit = craneLib.cargoAudit { + inherit src advisory-db; + }; - cargoLock.lockFile = ../Cargo.lock; - useNextest = true; + vuw-scraper-nextest = craneLib.cargoNextest (commonArgs + // { + inherit cargoArtifacts; + partitions = 1; + partitionType = "count"; + }); + }; - nativeBuildInputs = let inherit (pkgs) openssl pkg-config; in [openssl openssl.dev pkg-config]; + packages = + { + default = vuw-scraper; + } + // lib.optionalAttrs (!pkgs.stdenv.isDarwin) { + vuw-scraper-llvm-coverage = craneLibLlvmTools.cargoLlvmCov (commonArgs + // { + inherit cargoArtifacts; + }); + }; - PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig"; - LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.openssl]; + devenv.shells.default = { + env = { + inherit (commonArgs) LD_LIBRARY_PATH PKG_CONFIG_PATH; + }; - meta = with lib; { - description = "Scraper that can parse all of Victoria University of Wellington's courses, and output them in a computer-readable JSON file."; - homepage = "https://codeberg.org/sophieforrest/vuw_course_scraper"; - license = licenses.agpl3Plus; + packages = commonArgs.nativeBuildInputs; + }; }; } -- cgit 1.4.1