summary refs log tree commit diff
path: root/flake.nix
blob: 2d3d8925109efdc7babc2244a64084691689109b (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
97
98
99
100
101
102
103
104
{
  description = "Spacebar server, written in Typescript.";

  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
    flake-utils.url = "github:numtide/flake-utils";
  };

  outputs =
    {
      self,
      nixpkgs,
      flake-utils,
    }:
    nixpkgs.lib.recursiveUpdate
      (
        let
          rVersion =
            let
              rev = self.sourceInfo.shortRev or self.sourceInfo.dirtyShortRev;
              date = builtins.substring 0 8 self.sourceInfo.lastModifiedDate;
              time = builtins.substring 8 6 self.sourceInfo.lastModifiedDate;
            in
            "preview.${date}-${time}"; # +${rev}";
        in
        flake-utils.lib.eachSystem flake-utils.lib.allSystems (
          system:
          let
            pkgs = import nixpkgs {
              inherit system;
            };
            lib = pkgs.lib;
          in
          {
            packages = {
              default = (pkgs.callPackage (import ./default.nix { inherit self rVersion; })) { };
            };

            containers = {
              docker = {
                default = pkgs.dockerTools.buildLayeredImage {
                  name = "spacebar-server-ts";
                  tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.default.version;
                  contents = [ self.packages.${system}.default ];
                  config = {
                    Cmd = [ "${self.outputs.packages.${system}.default}/bin/start-bundle" ];
                    Expose = [ "3001" ];
                  };
                };
              }
              // lib.genAttrs [ "api" "cdn" "gateway" ] (
                mod:
                pkgs.dockerTools.buildLayeredImage {
                  name = "spacebar-server-ts-${mod}";
                  tag = builtins.replaceStrings [ "+" ] [ "_" ] self.packages.${system}.default.version;
                  contents = [
                    self.packages.${system}.default
                  ];
                  config = {
                    Cmd = [ "${self.outputs.packages.${system}.default}/bin/start-${mod}" ];
                    Expose = [ "3001" ];
                  };
                }
              );
            };

            devShells.default = pkgs.mkShell {
              buildInputs = with pkgs; [
                nodejs_24
                nodePackages.typescript
                nodePackages.patch-package
                nodePackages.prettier
                (pkgs.python3.withPackages (ps: with ps; [ setuptools ]))
              ];
            };
          }
        )
        // {
          nixosModules.default = import ./nix/modules/default self;
          testVm = import ./nix/testVm/default.nix { inherit self nixpkgs; };
          checks =
            let
              pkgs = import nixpkgs { system = "x86_64-linux"; };
              lib = pkgs.lib;
            in
            lib.recursiveUpdate (lib.attrsets.unionOfDisjoint { } self.packages) {
              x86_64-linux = {
                spacebar-server-tests = self.packages.x86_64-linux.default.passthru.tests;
              }
              // (lib.listToAttrs (
                lib.mapAttrsToList (name: container: {
                  name = "docker-${name}";
                  value = container;
                }) self.containers.x86_64-linux.docker
              ));
            };
        }
      )
      (
        import ./extra/admin-api/outputs.nix {
          inherit self nixpkgs flake-utils;
        }
      );
}