-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
141 lines (132 loc) · 5.03 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
{
description = "pgmigrate is a modern Postgres migrations CLI and library for golang";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
flake-compat.url = "github:edolstra/flake-compat";
flake-compat.flake = false;
nix-filter.url = "github:numtide/nix-filter";
};
outputs = { self, ... }@inputs:
inputs.flake-utils.lib.eachDefaultSystem (system:
let
overlays = [ ];
pkgs = import inputs.nixpkgs {
inherit system overlays;
};
lib = pkgs.lib;
version = (builtins.readFile ./VERSION);
commit = if (builtins.hasAttr "rev" self) then (builtins.substring 0 7 self.rev) else "unknown";
in
rec {
packages = rec {
pgmigrate = pkgs.buildGoModule {
pname = "pgmigrate";
version = version;
# Every time you update your dependencies (go.mod / go.sum) you'll
# need to update the vendorSha256.
#
# To find the right hash, set
#
# vendorHash = pkgs.lib.fakeHash;
#
# then run `nix build`, take the correct hash from the output, and set
#
# vendorHash = <the updated hash>;
#
# (Yes, that's really how you're expected to do this.)
#vendorHash = pkgs.lib.fakeHash;
vendorHash = "sha256-yffzg2giPpiAxCcVsLLrbXJSCno1axZSYctLsSTWq3Q=";
GOWORK = "off";
src =
let
# Set this to `true` in order to show all of the source files
# that will be included in the module build.
debug-tracing = false;
source-files = inputs.nix-filter.lib.filter {
root = ./cmd/pgmigrate;
};
in
(
if (debug-tracing) then
pkgs.lib.sources.trace source-files
else
source-files
);
# Add any extra packages required to build the binaries should go here.
buildInputs = [ ];
ldflags = [
"-X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Version=${version}"
"-X github.com/peterldowns/pgmigrate/cmd/pgmigrate/shared.Commit=${commit}"
];
modRoot = ".";
doCheck = false;
};
default = pgmigrate;
};
apps = rec {
pgmigrate = {
type = "app";
program = "${packages.pgmigrate}/bin/pgmigrate";
};
default = pgmigrate;
};
devShells = rec {
default = pkgs.mkShell {
buildInputs = [ ];
packages = with pkgs; [
# Go
delve
go-outline
go
golangci-lint
gopkgs
gopls
gotools
# Nix
nixpkgs-fmt
# Other
just
postgresql
docker
];
shellHook = ''
# The path to this repository
shell_nix="''${IN_LORRI_SHELL:-$(pwd)/shell.nix}"
workspace_root=$(dirname "$shell_nix")
export WORKSPACE_ROOT="$workspace_root"
# Puts the $GOPATH/$GOCACHE/$GOENV in $TOOLCHAIN_ROOT,
# and ensures that the GOPATH's bin dir is on the PATH so tools
# can be installed with `go install`.
#
# Any tools installed explicitly with `go install` will take precedence
# over versions installed by Nix due to the ordering here.
#
# Puts the toolchain folder adjacent to the repo so that tools
# running inside the repo don't ever scan its contents.
export TOOLCHAIN_NAME=".toolchain-$(basename $WORKSPACE_ROOT)"
export TOOLCHAIN_ROOT="$(dirname $WORKSPACE_ROOT)/$TOOLCHAIN_NAME"
export GOROOT=
export GOCACHE="$TOOLCHAIN_ROOT/go/cache"
export GOENV="$TOOLCHAIN_ROOT/go/env"
export GOPATH="$TOOLCHAIN_ROOT/go/path"
export GOMODCACHE="$GOPATH/pkg/mod"
export PATH=$(go env GOPATH)/bin:$PATH
export CGO_ENABLED=0
# Make it easy to test while developing by adding the built binary to
# the PATH.
export PATH="$workspace_root/bin:$workspace_root/result/bin:$PATH"
# For testing purposes
export MIGRATIONS='internal/migrations'
export DATABASE='postgres://postgres:password@localhost:5433/postgres'
'';
# Need to disable fortify hardening because GCC is not built with -oO,
# which means that if CGO_ENABLED=1 (which it is by default) then the golang
# debugger fails.
# see https://github.com/NixOS/nixpkgs/pull/12895/files
hardeningDisable = [ "fortify" ];
};
};
}
);
}