summaryrefslogtreecommitdiff
path: root/nix
diff options
context:
space:
mode:
authorSophie Forrest <git@sophieforrest.com>2024-10-09 12:35:49 +1300
committerSophie Forrest <git@sophieforrest.com>2024-10-09 12:35:49 +1300
commita434c31af9376c739837b2d1fadaf8c1b84c843e (patch)
treea4b21d68dc81fe61005503beb93ad58ce599d9df /nix
parent9518e130263dd547eaee66b6cae846809ba2d160 (diff)
chore(flake): improve nix infrastructure
Diffstat (limited to '')
-rw-r--r--nix/package.nix98
1 files changed, 76 insertions, 22 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";
+{inputs, ...}: {
+ perSystem = {
+ lib,
+ system,
+ pkgs,
+ ...
+ }: let
+ inherit (inputs) advisory-db crane fenix;
- src = builtins.path {
- name = "vuw_course_scraper";
- path = ../.;
- };
+ 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;
+ };
};
}