about summary refs log tree commit diff
path: root/kittybox.nix
diff options
context:
space:
mode:
Diffstat (limited to 'kittybox.nix')
-rw-r--r--kittybox.nix62
1 files changed, 41 insertions, 21 deletions
diff --git a/kittybox.nix b/kittybox.nix
index 1d66fc7..de14cb7 100644
--- a/kittybox.nix
+++ b/kittybox.nix
@@ -1,4 +1,4 @@
-{ stdenv, lib, naersk, lld, mold, typescript
+{ crane, lib, nodePackages
 , useWebAuthn ? false, openssl, zlib, pkg-config, protobuf
 , usePostgres ? true, postgresql, postgresqlTestHook
 , nixosTests }:
@@ -8,27 +8,49 @@ assert usePostgres -> postgresql != null && postgresqlTestHook != null;
 
 let
   featureMatrix = features: lib.concatStringsSep " " (lib.attrNames (lib.filterAttrs (k: v: v) features));
-in
-naersk.buildPackage rec {
-  pname = "kittybox";
-  version = "0.1.0";
 
-  src = lib.sources.sourceFilesBySuffices ./. [".rs" ".toml" ".sql" ".ts" ".css" ".html" ".lock" ".json"];
+  suffixes = [ ".sql" ".ts" ".css" ".html" ".json" ];
+  suffixFilter = suffixes: name: type:
+      let base = baseNameOf (toString name);
+      in type == "directory" || lib.any (ext: lib.hasSuffix ext base) suffixes;
+  srcFilter = path: type: (suffixFilter suffixes path type) || (crane.filterCargoSources path type);
 
-  doCheck = stdenv.hostPlatform == stdenv.targetPlatform;
-  cargoBuildOptions = x: x ++ [
-    "--no-default-features"
-    "--features=\"${featureMatrix { webauthn = useWebAuthn; postgres = usePostgres; rustls = !useWebAuthn; }}\""
-  ];
-  cargoTestOptions = cargoBuildOptions;
+  src = lib.cleanSourceWith {
+    src = ./.; # The original, unfiltered source
+    filter = srcFilter;
+    name = "source"; # Be reproducible, regardless of the directory name
+  };
+
+  cargoFeatures = "--no-default-features --features=\"${featureMatrix {
+    webauthn = useWebAuthn;
+    postgres = usePostgres;
+    rustls   = !useWebAuthn;
+  }}\"";
 
-  buildInputs = lib.optional useWebAuthn openssl;
-  nativeBuildInputs = [ typescript ] ++ (lib.optional useWebAuthn pkg-config);
+  args = {
+    inherit src;
+    strictDeps = true;
 
+    cargoExtraArgs = cargoFeatures;
+
+    buildInputs = lib.optional useWebAuthn openssl;
+    nativeBuildInputs = [ nodePackages.typescript ] ++ (lib.optional useWebAuthn pkg-config);
+
+    meta = with lib.meta; {
+      maintainers = with lib.maintainers; [ vikanezrimaya ];
+      platforms = ["aarch64-linux" "x86_64-linux"];
+      mainProgram = "kittybox";
+    };
+  };
+
+  cargoArtifacts = crane.buildDepsOnly args;
+  args' = args // { inherit cargoArtifacts; };
+
+in crane.buildPackage (args' // {
   nativeCheckInputs = lib.optionals usePostgres [
     postgresql postgresqlTestHook
   ];
-
+  
   # Tests create arbitrary databases; we need to be prepared for that
   postgresqlTestUserOptions = "LOGIN SUPERUSER";
   postgresqlTestSetupPost = ''
@@ -38,11 +60,9 @@ naersk.buildPackage rec {
   passthru = {
     tests = nixosTests;
     hasPostgres = usePostgres;
-  };
 
-  meta = with lib.meta; {
-    maintainers = with lib.maintainers; [ vikanezrimaya ];
-    platforms = ["aarch64-linux" "x86_64-linux"];
-    mainProgram = "kittybox";
+    inherit cargoArtifacts;
+
+    clippy = crane.cargoClippy args';
   };
-}
+})