summaryrefslogtreecommitdiffstats
path: root/flake.nix
blob: f59fbae96a04dd10c59b977bb302c33b2ca025f9 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
{
  description = "teamdraft.net";

  inputs = {
    devshell.url = "github:numtide/devshell";
    flake-parts.url = "github:hercules-ci/flake-parts";
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    process-compose-flake.url = "github:Platonic-Systems/process-compose-flake";
    services-flake.url = "github:juspay/services-flake";
    treefmt-nix.url = "github:numtide/treefmt-nix";
  };

  outputs = inputs @ {
    flake-parts,
    ...
  }:
    flake-parts.lib.mkFlake {inherit inputs;} {
      imports = [
        inputs.devshell.flakeModule
        inputs.process-compose-flake.flakeModule
        inputs.treefmt-nix.flakeModule
      ];
      systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"];
      perSystem = {
        config,
        self',
        inputs',
        pkgs,
        system,
        ...
      }:
        with builtins; rec {
          process-compose."services" = {
            imports = [
              inputs.services-flake.processComposeModules.default
            ];
            services.postgres."db" = {
              enable = true;
              package = pkgs.postgresql_16;
              extensions = extensions: [
                extensions.pgtap
                extensions.pgsodium
              ];

              initialScript.before = readFile ./src/db/init.sql;
              initialScript.after = readFile ./src/db/seed.sql;

              socketDir = "/tmp/db";
              superuser = "teamdraft";
            };
            settings = {
              log_location = "./logs/services.log";
            };
          };

          devshells.default = {
            commands = [
              {
                name = "db";
                help = "run postgresql";
                command = "nix run .#services";
              }
              {
                name = "reset";
                help = "recreate db and run postgresql";
                command = "rm -rf data && nix run .#services";
              }
              {
                name = "ci";
                help = "run all tests";
                command = "pg_prove";
              }
            ];
            packages = with pkgs; [
              gdb
              kcov
              perl538Packages.TAPParserSourceHandlerpgTAP
              pgcli
              pgformatter
              postgresql_16
              postgresql16Packages.pgtap
              sops
              zig
              zls
            ];
          };

          treefmt.config = {
            projectRootFile = "flake.nix";

            flakeCheck = true;
            flakeFormatter = true;
          };
        };
    };
}