Skip to content

Commit c7e613c

Browse files
committed
server: deploy servo/intermittent-tracker#24 as staging
1 parent 662af00 commit c7e613c

File tree

2 files changed

+97
-13
lines changed

2 files changed

+97
-13
lines changed

server/nixos/configuration.nix

Lines changed: 35 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@
216216
hash = "sha256-mROaUYqcOa+XePl4CzM/zM/mE21ejM2UhyQSYc8emc4=";
217217
};
218218

219-
intermittent-tracker = workingDir: {
219+
intermittent-tracker-service = workingDir: script: {
220220
# Wait for networking
221221
wants = ["network-online.target"];
222222
after = ["network-online.target"];
@@ -225,16 +225,39 @@
225225
wantedBy = ["multi-user.target"];
226226

227227
path = ["/run/current-system/sw"];
228-
script = ''
229-
. .venv/bin/activate
230-
FLASK_DEBUG=1 python3 -m intermittent_tracker.flask_server
231-
'';
228+
inherit script;
232229

233230
serviceConfig = {
234231
WorkingDirectory = workingDir;
235232
Restart = "on-failure";
236233
};
237234
};
235+
# v1 service requires manual deployment of the app:
236+
# $ git clone https://github.com/servo/intermittent-tracker.git <staging|prod>
237+
# $ cd <staging|prod>
238+
# $ uv venv
239+
# $ . .venv/bin/activate
240+
# $ uv pip install -r requirements.txt
241+
# $ cp config.json.example config.json
242+
intermittent-tracker-service-v1 = workingDir:
243+
intermittent-tracker-service workingDir ''
244+
. .venv/bin/activate
245+
FLASK_DEBUG=1 python3 -m intermittent_tracker.flask_server
246+
'';
247+
intermittent-tracker-service-v2 = workingDir: app:
248+
intermittent-tracker-service workingDir ''
249+
FLASK_DEBUG=1 ${app}/bin/intermittent_tracker
250+
'';
251+
252+
intermittent-tracker-staging = pkgs.callPackage ./python-app.nix {
253+
src = pkgs.fetchFromGitHub {
254+
owner = "servo";
255+
repo = "intermittent-tracker";
256+
rev = "42d55fdcce5e1d4e3aec70e4cfeb575d8569c8d3";
257+
hash = "sha256-L8Sk1aL3Na0JFymFj07eCcFIUZ0uYLt1ED2DDKnZ4VU=";
258+
};
259+
packageName = "intermittent-tracker";
260+
};
238261
in {
239262
# For benchmarking: disable CPU frequency boost, offline SMT siblings, etc.
240263
# Process affinity will be isolated externally via `isolcpus`.
@@ -255,14 +278,13 @@
255278
};
256279
};
257280

258-
# $ git clone https://github.com/servo/intermittent-tracker.git <staging|prod>
259-
# $ cd <staging|prod>
260-
# $ uv venv
261-
# $ . .venv/bin/activate
262-
# $ uv pip install -r requirements.txt
263-
# $ cp config.json.example config.json
264-
intermittent-tracker-staging = lib.mkIf hasIntermittentTracker (intermittent-tracker "/config/intermittent-tracker/staging");
265-
intermittent-tracker-prod = lib.mkIf hasIntermittentTracker (intermittent-tracker "/config/intermittent-tracker/prod");
281+
intermittent-tracker-staging = lib.mkIf hasIntermittentTracker
282+
(intermittent-tracker-service-v2
283+
"/config/intermittent-tracker/staging"
284+
intermittent-tracker-staging);
285+
intermittent-tracker-prod = lib.mkIf hasIntermittentTracker
286+
(intermittent-tracker-service-v1
287+
"/config/intermittent-tracker/prod");
266288

267289
monitor = {
268290
# Wait for networking

server/nixos/python-app.nix

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Based on the uv2nix docs:
2+
# <https://pyproject-nix.github.io/uv2nix/install.html#classic-nix>
3+
# <https://pyproject-nix.github.io/uv2nix/usage/getting-started.html>
4+
# <https://pyproject-nix.github.io/uv2nix/patterns/applications.html>
5+
{
6+
src,
7+
packageName,
8+
9+
# Provided by callPackage:
10+
lib,
11+
callPackage,
12+
fetchFromGitHub,
13+
python3,
14+
}: let
15+
pyproject-nix = import (fetchFromGitHub {
16+
owner = "pyproject-nix";
17+
repo = "pyproject.nix";
18+
rev = "02e9418fd4af638447dca4b17b1280da95527fc9";
19+
hash = "sha256-amLaLNwKSZPShQHzfgmc/9o76dU8xzN0743dWgvYlr8=";
20+
}) {
21+
inherit lib;
22+
};
23+
uv2nix = import (fetchFromGitHub {
24+
owner = "pyproject-nix";
25+
repo = "uv2nix";
26+
rev = "87de87c2486da49d22daef61fc98c490789a8e42";
27+
hash = "sha256-L9/jSc4YHNfeTa/iKolWtzF4A00o21YnrZmoTHAoo2U=";
28+
}) {
29+
inherit pyproject-nix lib;
30+
};
31+
pyproject-build-systems = import (fetchFromGitHub {
32+
owner = "pyproject-nix";
33+
repo = "build-system-pkgs";
34+
rev = "5b8e37fe0077db5c1df3a5ee90a651345f085d38";
35+
hash = "sha256-6nzSZl28IwH2Vx8YSmd3t6TREHpDbKlDPK+dq1LKIZQ=";
36+
}) {
37+
inherit pyproject-nix uv2nix lib;
38+
};
39+
pythonBase = callPackage pyproject-nix.build.packages {
40+
python = python3;
41+
};
42+
workspace = uv2nix.lib.workspace.loadWorkspace {
43+
workspaceRoot = src;
44+
};
45+
overlay = workspace.mkPyprojectOverlay {
46+
sourcePreference = "wheel";
47+
};
48+
pythonSet = pythonBase.overrideScope (
49+
lib.composeManyExtensions [
50+
# NOTE: just `.wheel`, not `.overlays.wheel`, since we aren’t using the flake
51+
# <https://github.com/pyproject-nix/build-system-pkgs/blob/5b8e37fe0077db5c1df3a5ee90a651345f085d38/flake.nix#L34>
52+
# <https://github.com/pyproject-nix/build-system-pkgs/blob/5b8e37fe0077db5c1df3a5ee90a651345f085d38/default.nix#L11>
53+
pyproject-build-systems.wheel
54+
overlay
55+
]
56+
);
57+
venv = pythonSet.mkVirtualEnv "venv" workspace.deps.default;
58+
inherit (callPackage pyproject-nix.build.util {}) mkApplication;
59+
in mkApplication {
60+
inherit venv;
61+
package = pythonSet."${packageName}";
62+
}

0 commit comments

Comments
 (0)