summary refs log tree commit diff
path: root/nix
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--nix/package.nix100
1 files changed, 77 insertions, 23 deletions
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;
+    };
   };
 }