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
|
{
buildGoModule,
curl,
dbmate,
fetchFromGitHub,
jq,
lib,
makeWrapper,
nix-update-script,
nixosTests,
python3,
writeShellScriptBin,
xz,
}:
buildGoModule (finalAttrs: {
pname = "ncps";
version = "0.9.4";
src = fetchFromGitHub {
owner = "kalbasit";
repo = "ncps";
tag = "v${finalAttrs.version}";
hash = "sha256-VPcX9gLXnTrap6HHU+08QdTBbT2oaNA2C9WY0e/FVoc=";
};
vendorHash = "sha256-PpHSkD7+csPfUXoYRuKhBm1iBtTSwJhOxuW/4ayv9hY=";
ldflags = [
"-X github.com/kalbasit/ncps/pkg/ncps.Version=v${finalAttrs.version}"
];
excludedPackages = [
"nix/dbmate-wrapper/src"
"nix/gen-db-wrappers/src"
];
buildInputs = [ xz ];
nativeBuildInputs = [
makeWrapper # used for wrapping the binary so it can always find the xz binary
dbmate # used for testing
];
postInstall = ''
mkdir -p $out/share/ncps
cp -r db $out/share/ncps/db
# ncps makes use of xz for decompression as it's 3-5x faster than
# using the native Go implementation of xz. By wrapping ncps, and
# setting the XZ_BINARY_PATH environment variable, we ensure that
# ncps can always find the xz binary. This environment variable is
# read by a flag in pkg/ncps and can be overriden by using calling
# ncps with the --xz-binary-path flag.
wrapProgram $out/bin/ncps --set XZ_BINARY_PATH ${lib.getExe' xz "xz"}
# Wrap the dbmate-wrapper and set the NCPS_DB_MIGRATIONS_DIR environment variable
makeWrapper ${finalAttrs.passthru.dbmate-wrapper}/bin/dbmate-wrapper \
$out/bin/dbmate-ncps \
--set NCPS_DB_MIGRATIONS_DIR $out/share/ncps/db/migrations
'';
doCheck = true;
checkFlags = [ "-race" ];
passthru = {
dbmate-wrapper = buildGoModule {
pname = "ncps-dbmate-wrapper";
inherit (finalAttrs) version;
src = "${finalAttrs.src}/nix/dbmate-wrapper/src";
vendorHash = null;
buildInputs = lib.singleton dbmate;
nativeBuildInputs = lib.singleton makeWrapper;
postInstall = ''
# the dbmate-wrapper needs access to the original dbmate executable, wrap it so it can find it correctly.
wrapProgram $out/bin/dbmate-wrapper --set DBMATE_BIN ${lib.getExe dbmate}
'';
subPackages = [ "." ];
};
tests = {
inherit (nixosTests)
ncps
ncps-custom-sqlite-directory
ncps-custom-storage-local
ncps-ha-pg-redis
ncps-ha-pg-redis-cdc
;
};
updateScript = nix-update-script { };
};
meta = {
description = "Nix binary cache proxy service";
homepage = "https://github.com/kalbasit/ncps";
license = lib.licenses.mit;
mainProgram = "ncps";
maintainers = with lib.maintainers; [
kalbasit
aciceri
];
};
})
|