about summary refs log tree commit diff
path: root/kittybox.nix
blob: eea7006569341ada2a38c2c80396033c8a2cfa98 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
{ stdenv, lib, naersk, lld, mold, typescript
, useWebAuthn ? false, openssl, zlib, pkg-config, protobuf
, usePostgres ? true, postgresql, postgresqlTestHook
, nixosTest }:

assert useWebAuthn -> openssl != null && pkg-config != null;
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"];

  doCheck = stdenv.hostPlatform == stdenv.targetPlatform;
  cargoBuildOptions = x: x ++ [
    "--no-default-features"
    "--features=\"${featureMatrix { webauthn = useWebAuthn; postgres = usePostgres; rustls = !useWebAuthn; }}\""
  ];
  cargoTestOptions = cargoBuildOptions;

  buildInputs = lib.optional useWebAuthn openssl;
  nativeBuildInputs = [ typescript ] ++ (lib.optional useWebAuthn pkg-config);

  nativeCheckInputs = lib.optionals usePostgres [
    postgresql postgresqlTestHook
  ];

  # Tests create arbitrary databases; we need to be prepared for that
  postgresqlTestUserOptions = "LOGIN SUPERUSER";
  postgresqlTestSetupPost = ''
    export DATABASE_URL="postgres://localhost?host=$PGHOST&user=$PGUSER&dbname=$PGDATABASE"
  '';

  passthru = {
    tests = {
      distributed = nixosTest ./nixos-tests/distributed-test.nix;
      smokeTest = nixosTest ./nixos-tests/smoke-test.nix;
    } // (lib.optionalAttrs usePostgres {
      webmention = nixosTest ./nixos-tests/webmention-test.nix;
      postgresSmokeTest = nixosTest ./nixos-tests/postgres-smoke-test.nix;
    });

    hasPostgres = usePostgres;
  };

  meta = with lib.meta; {
    maintainers = with lib.maintainers; [ vikanezrimaya ];
    platforms = ["aarch64-linux" "x86_64-linux"];
    mainProgram = "kittybox";
  };
}