-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathflake.nix
More file actions
286 lines (230 loc) · 9.14 KB
/
flake.nix
File metadata and controls
286 lines (230 loc) · 9.14 KB
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
{
description = "Tower CLI and runtime environment for Tower with build targets and devShell";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
rust-overlay = {
url = "github:oxalica/rust-overlay";
inputs.nixpkgs.follows = "nixpkgs";
};
naersk = {
url = "github:nix-community/naersk";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, rust-overlay, naersk }:
flake-utils.lib.eachSystem [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" "aarch64-linux" ] (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default ];
};
maintainer = "Tower Computing Inc. <support@tower.dev>";
homepage = "https://github.com/tower/tower-cli";
description = "Tower CLI and runtime environment";
longDescription = " |
Tower CLI and runtime environment
Tower is the best way to host Python data apps in production.
This package provides the Tower CLI tool for managing and deploying
applications to the Tower platform.
";
getVersionScript = ''
VERSION=${builtins.getEnv "VERSION"}
if [ -z "$VERSION" ]; then
VERSION="SNAPSHOT"
fi
'';
mkNfpmConfig = { arch, packager }: ''
name: tower
arch: ${arch}
platform: linux
version: $VERSION
${if packager == "rpm" then "release: 1" else "section: utils\npriority: optional"}
maintainer: ${maintainer}
description: ${longDescription}
vendor: Tower Computing Inc.
homepage: "${homepage}"
license: MIT
contents:
- src: package/usr/bin/tower
dst: /usr/bin/tower
file_info:
mode: 0755
'';
commonNativeBuildInputs = with pkgs; [ pkg-config ];
commonBuildInputs = with pkgs; [ openssl zlib ];
isMuslTarget = target: target == "x86_64-unknown-linux-musl" || target == "aarch64-unknown-linux-musl";
rustToolchain = pkgs.rust-bin.stable.latest.default;
python = pkgs.python312;
naersk-native = naersk.lib.${system}.override {
cargo = rustToolchain;
rustc = rustToolchain;
};
tower = naersk-native.buildPackage {
src = ./.;
cargoBuildOptions = x: x;
nativeBuildInputs = commonNativeBuildInputs;
buildInputs = commonBuildInputs;
meta = with pkgs.lib; {
inherit description;
license = licenses.mit;
platforms = [ "x86_64-linux" "aarch64-darwin" "x86_64-darwin" ];
mainProgram = "tower";
};
};
mkCrossTarget = target: let
crossSystemConfig = {
"x86_64-unknown-linux-musl" = "x86_64-unknown-linux-musl";
"aarch64-unknown-linux-musl" = "aarch64-unknown-linux-musl";
"aarch64-apple-darwin" = "aarch64-apple-darwin";
}.${target};
crossPkgs = import nixpkgs {
inherit system;
crossSystem = { config = crossSystemConfig; };
};
crossRustToolchain = pkgs.rust-bin.stable.latest.default.override {
targets = [target];
};
naersk-cross = naersk.lib.${system}.override {
cargo = crossRustToolchain;
rustc = crossRustToolchain;
};
in naersk-cross.buildPackage {
src = ./.;
cargoBuildOptions = x: x;
CARGO_BUILD_TARGET = target;
CARGO_BUILD_RUSTFLAGS = if (isMuslTarget target)
then "-C target-feature=+crt-static"
else "";
nativeBuildInputs = commonNativeBuildInputs ++ pkgs.lib.optionals (isMuslTarget target) [
crossPkgs.stdenv.cc
];
buildInputs = with crossPkgs; commonBuildInputs;
CARGO_TARGET_X86_64_UNKNOWN_LINUX_MUSL_LINKER =
if target == "x86_64-unknown-linux-musl"
then "${crossPkgs.stdenv.cc.targetPrefix}cc"
else null;
CARGO_TARGET_AARCH64_UNKNOWN_LINUX_MUSL_LINKER =
if target == "aarch64-unknown-linux-musl"
then "${crossPkgs.stdenv.cc.targetPrefix}cc"
else null;
PKG_CONFIG_ALLOW_CROSS = "1";
OPENSSL_NO_VENDOR = "1";
OPENSSL_DIR = "${crossPkgs.openssl.dev}";
OPENSSL_LIB_DIR = "${crossPkgs.openssl.out}/lib";
OPENSSL_INCLUDE_DIR = "${crossPkgs.openssl.dev}/include";
};
tower-linux-x86 = mkCrossTarget "x86_64-unknown-linux-musl";
tower-linux-arm64 = mkCrossTarget "aarch64-unknown-linux-musl";
tower-macos-arm = if system == "aarch64-darwin" then tower else mkCrossTarget "aarch64-apple-darwin";
in {
packages = {
default = tower;
tower = tower;
tower-linux-x86 = tower-linux-x86;
tower-linux-arm64 = tower-linux-arm64;
tower-macos-arm = tower-macos-arm;
tower-deb-x86 = pkgs.stdenv.mkDerivation {
name = "tower-deb-amd64";
nativeBuildInputs = with pkgs; [ nfpm python git ];
unpackPhase = "true";
buildPhase = ''
${getVersionScript}
mkdir -p package/usr/bin
cp ${tower-linux-x86}/bin/tower package/usr/bin/
chmod 755 package/usr/bin/tower
cat > nfpm.yaml << EOF
${mkNfpmConfig { arch = "amd64"; packager = "deb"; }}
EOF
'';
installPhase = ''
mkdir -p $out
nfpm package --config nfpm.yaml --packager deb --target $out/tower_''${VERSION}_amd64.deb
'';
};
tower-deb-arm64 = pkgs.stdenv.mkDerivation {
name = "tower-deb-arm64";
nativeBuildInputs = with pkgs; [ nfpm python git ];
unpackPhase = "true";
buildPhase = ''
${getVersionScript}
mkdir -p package/usr/bin
cp ${tower-linux-arm64}/bin/tower package/usr/bin/
chmod 755 package/usr/bin/tower
cat > nfpm.yaml << EOF
${mkNfpmConfig { arch = "arm64"; packager = "deb"; }}
EOF
'';
installPhase = ''
mkdir -p $out
cat nfpm.yaml
nfpm package --config nfpm.yaml --packager deb --target $out/tower_''${VERSION}_arm64.deb
'';
};
tower-rpm-x86 = pkgs.stdenv.mkDerivation {
name = "tower-rpm-x86_64";
nativeBuildInputs = with pkgs; [ nfpm python git ];
unpackPhase = "true";
buildPhase = ''
${getVersionScript}
mkdir -p package/usr/bin
cp ${tower-linux-x86}/bin/tower package/usr/bin/
chmod 755 package/usr/bin/tower
cat > nfpm.yaml << EOF
${mkNfpmConfig { arch = "x86_64"; packager = "rpm"; }}
EOF
'';
installPhase = ''
mkdir -p $out
nfpm package --config nfpm.yaml --packager rpm --target $out/tower-''${VERSION}-1.x86_64.rpm
'';
};
tower-rpm-arm64 = pkgs.stdenv.mkDerivation {
name = "tower-rpm-aarch64";
nativeBuildInputs = with pkgs; [ nfpm python git ];
unpackPhase = "true";
buildPhase = ''
${getVersionScript}
mkdir -p package/usr/bin
cp ${tower-linux-arm64}/bin/tower package/usr/bin/
chmod 755 package/usr/bin/tower
cat > nfpm.yaml << EOF
${mkNfpmConfig { arch = "aarch64"; packager = "rpm"; }}
EOF
'';
installPhase = ''
mkdir -p $out
nfpm package --config nfpm.yaml --packager rpm --target $out/tower-''${VERSION}-1.aarch64.rpm
'';
};
};
devShells.default = pkgs.mkShell {
nativeBuildInputs = with pkgs; [
rustToolchain
python
maturin
python312Packages.pip
uv
behave
pkg-config
openssl
];
buildInputs = commonBuildInputs;
shellHook = ''
export RUST_LOG=debug
export PYTHONPATH=$PWD/src:$PYTHONPATH
echo "Tower CLI development environment"
echo "Python: $(python --version)"
echo "Rust: $(rustc --version)"
echo "Behave: $(behave --version 2>/dev/null || echo 'not available')"
'';
};
apps = {
default = {
type = "app";
program = "${tower}/bin/tower";
};
};
}
);
}