summaryrefslogtreecommitdiff
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
parent9518e130263dd547eaee66b6cae846809ba2d160 (diff)
chore(flake): improve nix infrastructure
-rw-r--r--flake.lock55
-rw-r--r--flake.nix32
-rw-r--r--nix/package.nix98
3 files changed, 150 insertions, 35 deletions
diff --git a/flake.lock b/flake.lock
index ebd3e0a..8312692 100644
--- a/flake.lock
+++ b/flake.lock
@@ -1,5 +1,21 @@
{
"nodes": {
+ "advisory-db": {
+ "flake": false,
+ "locked": {
+ "lastModified": 1727881133,
+ "narHash": "sha256-nnfwJjLA0uVIBgrGNYt9ButjBQFyj/I6MohQUHhJ78A=",
+ "owner": "rustsec",
+ "repo": "advisory-db",
+ "rev": "a68ca4a1ec3950da7c82c522e8cfc424e28ca7f0",
+ "type": "github"
+ },
+ "original": {
+ "owner": "rustsec",
+ "repo": "advisory-db",
+ "type": "github"
+ }
+ },
"cachix": {
"inputs": {
"devenv": "devenv_2",
@@ -30,6 +46,21 @@
"type": "github"
}
},
+ "crane": {
+ "locked": {
+ "lastModified": 1728344376,
+ "narHash": "sha256-lxTce2XE6mfJH8Zk6yBbqsbu9/jpwdymbSH5cCbiVOA=",
+ "owner": "ipetkov",
+ "repo": "crane",
+ "rev": "fd86b78f5f35f712c72147427b1eb81a9bd55d0b",
+ "type": "github"
+ },
+ "original": {
+ "owner": "ipetkov",
+ "repo": "crane",
+ "type": "github"
+ }
+ },
"devenv": {
"inputs": {
"cachix": "cachix",
@@ -83,6 +114,27 @@
"type": "github"
}
},
+ "fenix": {
+ "inputs": {
+ "nixpkgs": [
+ "nixpkgs"
+ ],
+ "rust-analyzer-src": []
+ },
+ "locked": {
+ "lastModified": 1728369208,
+ "narHash": "sha256-5B1ugdw1apI/eW6g0eDvC0xXX/aSQwbE/uld62TmNG8=",
+ "owner": "nix-community",
+ "repo": "fenix",
+ "rev": "1938b54a55c1cab94be7b9d8dbaf58007a607e24",
+ "type": "github"
+ },
+ "original": {
+ "owner": "nix-community",
+ "repo": "fenix",
+ "type": "github"
+ }
+ },
"flake-compat": {
"flake": false,
"locked": {
@@ -485,7 +537,10 @@
},
"root": {
"inputs": {
+ "advisory-db": "advisory-db",
+ "crane": "crane",
"devenv": "devenv",
+ "fenix": "fenix",
"flake-parts": "flake-parts",
"mk-shell-bin": "mk-shell-bin",
"nix2container": "nix2container",
diff --git a/flake.nix b/flake.nix
index 65a3051..b671802 100644
--- a/flake.nix
+++ b/flake.nix
@@ -5,6 +5,17 @@
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
+ crane.url = "github:ipetkov/crane";
+ advisory-db = {
+ url = "github:rustsec/advisory-db";
+ flake = false;
+ };
+ fenix = {
+ url = "github:nix-community/fenix";
+ inputs.nixpkgs.follows = "nixpkgs";
+ inputs.rust-analyzer-src.follows = "";
+ };
+
nix2container.url = "github:nlewo/nix2container";
nix2container.inputs.nixpkgs.follows = "nixpkgs";
mk-shell-bin.url = "github:rrbutani/nix-mk-shell-bin";
@@ -14,29 +25,24 @@
outputs = inputs @ {flake-parts, ...}:
flake-parts.lib.mkFlake {inherit inputs;} {
- imports = [inputs.devenv.flakeModule];
+ imports = [
+ inputs.devenv.flakeModule
+ ./nix/package.nix
+ ];
systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
- perSystem = {
- lib,
- pkgs,
- ...
- }: {
- packages.default = pkgs.callPackage ./nix/package.nix {};
-
+ perSystem = {pkgs, ...}: {
devenv.shells.default = {
- env = {
- LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.openssl];
- PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig";
- };
+ # NOTE: env vars are maintained inside ./nix/package.nix.
languages = {
nix.enable = true;
rust.enable = true;
};
- packages = let inherit (pkgs) cargo-nextest openssl pkg-config; in [cargo-nextest openssl openssl.dev pkg-config];
+ # NOTE: build dependencies are maintained inside ./nix/package.nix.
+ packages = with pkgs; [cargo-nextest];
pre-commit.hooks.alejandra.enable = true;
};
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;
+ };
};
}