From 74d2bee2df85d7c574e41fb0a8779964908681ba Mon Sep 17 00:00:00 2001 From: Vika Date: Sat, 3 Aug 2024 17:47:01 +0300 Subject: Migrate from naersk to crane Naersk has been creating problems for me, and crane seems better maintained. --- kittybox.nix | 62 ++++++++++++++++++++++++++++++++++++++++-------------------- 1 file changed, 41 insertions(+), 21 deletions(-) (limited to 'kittybox.nix') 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'; }; -} +}) -- cgit 1.4.1