forked from letsblockit/letsblockit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
110 lines (103 loc) · 4.22 KB
/
flake.nix
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
105
106
107
108
109
110
{
description = "letsblock.it server and helpers";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [
(final: prev: {
# Pin the golang version to 1.21 on nixos-23.11
pinnedGo = prev.go;
buildGoModule = prev.buildGoModule.override { go = final.pinnedGo; };
})
];
};
commonImageLabels = import ./nix/labels.nix;
# Scripts to wrap, with their dependencies, available via `nix run .#script-name`
scripts = with pkgs; {
add-migration = [ go-migrate ];
run-migrate = [ go-migrate ];
run-server = [ pinnedGo reflex self.packages.${system}.ory ];
run-tests = [ pinnedGo golangci-lint ];
update-assets = [ pinnedGo nodejs-slim-18_x nodePackages.npm ];
update-contributors = [ pinnedGo curl imagemagick git ];
update-codegen = [ mockgen self.packages.${system}.sqlc ];
update-labels = [ coreutils ];
update-vendorsha = [ nix-prefetch gnused ];
upgrade-deps = [ nodejs-slim-18_x nodePackages.npm pinnedGo nix-prefetch git ];
};
in
{
formatter = pkgs.nixpkgs-fmt;
defaultPackage = self.packages.${system}.run-server;
packages = {
render = pkgs.callPackage ./nix/letsblockit.nix { cmd = "render"; };
server = pkgs.callPackage ./nix/letsblockit.nix { cmd = "server"; };
ory = pkgs.callPackage ./nix/ory.nix { };
sqlc = pkgs.callPackage ./nix/sqlc.nix { };
render-container = pkgs.dockerTools.streamLayeredImage {
name = "ghcr.io/letsblockit/render";
tag = "latest";
created = builtins.substring 0 8 self.lastModifiedDate;
contents = self.packages.${system}.render;
config = {
Cmd = [ "render" ];
Labels = {
"org.opencontainers.image.title" = "letsblock.it render CLI";
"org.opencontainers.image.documentation" = "https://github.com/letsblockit/letsblockit/blob/main/cmd/render/README.md";
} // commonImageLabels;
};
};
server-container = pkgs.dockerTools.streamLayeredImage {
name = "ghcr.io/letsblockit/server";
tag = "latest";
created = builtins.substring 0 8 self.lastModifiedDate;
contents = [ pkgs.cacert self.packages.${system}.server ];
config = {
Cmd = [ "/bin/server" ];
Env = [ "LETSBLOCKIT_ADDRESS=:8765" "PATH=/bin" ];
ExposedPorts."8765/tcp" = { };
Labels = {
"org.opencontainers.image.title" = "letsblock.it server";
"org.opencontainers.image.documentation" = "https://github.com/letsblockit/letsblockit/blob/main/cmd/server/README.md";
} // commonImageLabels;
};
};
} // (builtins.mapAttrs
(name: deps: pkgs.writeShellApplication {
name = name;
runtimeInputs = deps;
text = ''
# Make nix-prefetch use nixpkgs from the flake lock
export NIX_PATH="nixpkgs=${nixpkgs.sourceInfo.outPath}"
./scripts/${name}.sh "$@"
'';
})
scripts);
apps = {
render = flake-utils.lib.mkApp {
drv = self.packages.${system}.render;
exePath = "/bin/render";
};
server = flake-utils.lib.mkApp {
drv = self.packages.${system}.server;
exePath = "/bin/server";
};
};
devShell = pkgs.mkShell {
# Build inputs from the packages
inputsFrom = builtins.attrValues self.packages.${system};
# Runtime inputs from the scripts
buildInputs = builtins.concatLists (builtins.attrValues scripts);
};
overlay = final: prev: {
letsblockit = self.packages.${system}.server;
ory = self.packages.${system}.ory;
};
});
}