forked from resonatehq/resonate
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
158 lines (137 loc) · 5.14 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
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
# This flake was initially generated by fh, the CLI for FlakeHub (version 0.1.10)
{
# A helpful description of the flake
description = "Resonate: a dead simple programming model for modern applications";
# Flake inputs
inputs = {
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*";
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
};
flake-schemas.url = "https://flakehub.com/f/DeterminateSystems/flake-schemas/*";
};
# Flake outputs that other flakes can use
outputs = { self, nixpkgs, gomod2nix, flake-schemas }:
let
# Version inference
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
version = "${builtins.substring 0 8 lastModifiedDate}-${self.shortRev or "dirty"}";
# Helpers for producing system-specific outputs
supportedSystems = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
inherit system;
});
in
{
# Schemas tell Nix about the structure of your flake's outputs
inherit (flake-schemas) schemas;
# Custom attributes for Nixpkgs
overlays.default = final: prev: {
buildGoApplication = gomod2nix.legacyPackages.${prev.stdenv.system}.buildGoApplication;
gomod2nixPkg = gomod2nix.packages.${prev.stdenv.system}.default;
};
# Development environments
devShells = forEachSupportedSystem ({ pkgs, system }: {
default = pkgs.mkShell {
# Pinned packages available in the environment
packages = with pkgs; [
# Go
go_1_21
gotools # goimports, godoc, etc.
golangci-lint # Go linter
# Nix + Go dependency management
gomod2nixPkg
# Tool for generating mocks
mockgen
# protoc
protobuf
protoc-gen-go
protoc-gen-go-grpc
# OpenAPI generator
oapi-codegen
# Nix formatter
nixpkgs-fmt
]
# Broken on aarch64-linux
++ pkgs.lib.optional (system != "aarch64-linux") (with pkgs; [ semgrep ]);
};
});
# Package outputs
packages = forEachSupportedSystem ({ pkgs, ... }: rec {
# The Resonate server
resonate = pkgs.buildGoApplication rec {
pname = "resonate";
inherit version;
src = self;
modules = ./gomod2nix.toml;
# Required for SQLite on Linux
CGO_ENABLED = 1;
# Make the binary static on Linux
ldflags = [
"-s"
"-w"
] ++ pkgs.lib.optional (pkgs.stdenv.isLinux) [
"-extldflags=-static"
"-linkmode=external"
];
# Use glibc on Linux
buildInputs = pkgs.lib.optional
(pkgs.stdenv.isLinux)
(with pkgs; [ glibc glibc.static ]);
# Provides the `installShellCompletion` shell function
nativeBuildInputs = with pkgs; [ installShellFiles ];
# Provides shell completion for bash, zsh, and fish
postInstall = ''
installShellCompletion --cmd ${pname} \
--bash <($out/bin/${pname} completion bash) \
--zsh <($out/bin/${pname} completion zsh) \
--fish <($out/bin/${pname} completion fish)
'';
};
# Test harness (TODO: make this a flake as well)
durable-promise-test-harness = pkgs.buildGo121Module rec {
name = "durable-promise-test-harness";
src = pkgs.fetchFromGitHub {
owner = "resonatehq";
repo = name;
rev = "43a2b602ca1ed5a019f0e9341efdab3484b3e2e0";
hash = "sha256-9IfrHQ+8CB/yLHtmZwcajvQ2yWrqZJi2frS+wBRsGfY=";
};
vendorHash = "sha256-n15ECdUjvwg8H0uVZzP40E9vpNSJrkvqxQWBTGkqcs8=";
};
# This enables you to use the shorthand `nix build` to build the server
default = resonate;
});
# Docker image outputs
dockerImages = forEachSupportedSystem ({ pkgs, ... }: rec {
# The Resonate server as an image
resonate =
let
# A version of Nixpkgs solely for x86_64 Linux (the built image's system)
linuxPkgs = pkgs.legacyPackages.x86_64-linux;
in
pkgs.dockerTools.buildLayeredImage {
name = "resonate-${version}";
# Extra packages for the image
contents = with linuxPkgs.dockerTools; [
# Standard requirement for HTTP and the like
caCertificates
];
config = {
# The image ENTRYPOINT (Nix automatically builds this path)
Entrypoint = [ "${self.packages.x86_64-linux.default}/bin/resonate" ];
# EXPOSE statements for ports
ExposedPorts = {
"8001" = { };
"50051" = { };
};
};
};
});
};
}