-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
108 lines (106 loc) · 3.18 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
{
description = "Nix flake for Neon";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
gomod2nix = {
url = "github:nix-community/gomod2nix";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs =
{
self,
nixpkgs,
flake-utils,
gomod2nix,
}:
flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ gomod2nix.overlays.default ];
};
readFileOr = (path: default: with builtins; if pathExists path then (readFile path) else default);
repoName = "github.com/bow/neon";
tagFile = "${self}/.tag";
revFile = "${self}/.rev";
version = readFileOr tagFile "0.0.0";
commit = readFileOr revFile "";
app = gomod2nix.legacyPackages.${system}.buildGoApplication {
src = ./.;
pwd = ./.;
name = "neon";
doCheck = false;
CGO_ENABLED = 0;
ldflags = [
"-w" # do not generate debug output
"-s" # strip symbols table
"-X ${repoName}/internal.version=${version}"
"-X ${repoName}/internal.gitCommit=${commit}"
];
};
in
{
devShells = {
default = pkgs.mkShell {
packages = with pkgs; [
# go-only
go
gocover-cobertura
golangci-lint
gomod2nix.packages.${system}.default
gopls
gosec
gotestsum
gotools
(go-migrate.overrideAttrs (_final: _prev: { tags = [ "sqlite" ]; }))
mockgen
protobuf
protoc-gen-go
protoc-gen-go-grpc
# nix-only
deadnix
nixfmt-rfc-style
statix
# others
gnugrep
sqlite
];
};
};
packages =
let
imgTag = readFileOr tagFile "latest";
imgAttrs = rec {
name = "ghcr.io/bow/${app.name}";
tag = imgTag;
contents = [ app ];
config = {
Entrypoint = [ "/bin/${app.name}" ];
Env = [
"NEON_SERVER_ADDR=tcp://0.0.0.0:5151"
"NEON_SERVER_DB_PATH=/var/data/neon.db"
];
Labels = {
"org.opencontainers.image.revision" = readFileOr revFile "";
"org.opencontainers.image.source" = "https://github.com/bow/${app.name}";
"org.opencontainers.image.title" = "${app.name}";
"org.opencontainers.image.url" = "https://${name}";
};
};
extraCommands = ''
mkdir -p var/data
'';
};
in
{
dockerArchive = pkgs.dockerTools.buildLayeredImage imgAttrs;
dockerArchiveStreamer = pkgs.dockerTools.streamLayeredImage imgAttrs;
local = app;
};
}
);
}