This repository has been archived by the owner on Jan 8, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
flake.nix
158 lines (138 loc) · 5.16 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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
{
description = "Pretix ticketing software";
inputs = {
# Some utility functions to make the flake less boilerplaty
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "nixpkgs/nixos-20.09";
pretixSrc = {
url = "github:pretix/pretix";
flake = false;
};
};
outputs = { self, nixpkgs, pretixSrc, flake-utils }:
flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlay ];
};
in
{
defaultPackage = pkgs.pretix;
packages = { inherit (pkgs) pretix update-pretix; };
}) // {
overlay = final: prev: {
update-pretix = prev.writeScriptBin "update-pretix" ''
#!/usr/bin/env bash
set -euo pipefail
set -x
export PATH=${
prev.lib.concatMapStringsSep ":" (x: "${x}/bin")
(prev.stdenv.initialPath ++ [ final.poetry prev.stdenv.cc ])
}:$PATH
POETRY=${final.poetry}/bin/poetry
workdir=$(mktemp -d)
trap "rm -rf \"$workdir\"" EXIT
pushd "$workdir"
cp ${./pyproject.toml.template} pyproject.toml
chmod +w pyproject.toml
cat ${pretixSrc}/src/requirements/production.txt | \
sed -e 's/#.*//' -e 's/\([=<>]\)/@&/' | \
xargs "$POETRY" add
poetry add gunicorn
popd
cp "$workdir"/{pyproject.toml,poetry.lock} ./
'';
pretix = (prev.poetry2nix.mkPoetryApplication {
projectDir = pretixSrc;
pyproject = ./pyproject.toml;
poetrylock = ./poetry.lock;
src = pretixSrc + "/src";
overrides = prev.poetry2nix.overrides.withDefaults (pself: psuper: {
# The tlds package is an ugly beast which fetches its content
# at build-time. So instead replace it by a fixed hardcoded
# version.
tlds = psuper.tlds.overrideAttrs (a: {
src = prev.fetchFromGitHub {
owner = "regnat";
repo = "tlds";
rev = "3c1c0ce416e153a975d7bc753694cfb83242071e";
sha256 =
"sha256-u6ZbjgIVozaqgyVonBZBDMrIxIKOM58GDRcqvyaYY+8=";
};
});
# For some reason, tqdm is missing a dependency on toml
tqdm = psuper.tqdm.overrideAttrs (a: {
buildInputs = (a.buildInputs or [ ])
++ [ prev.python3Packages.toml ];
});
django-scopes = psuper.django-scopes.overrideAttrs (a: {
# Django-scopes does something fishy to determine its version,
# which breaks with Nix
prePatch = (a.prePatch or "") + ''
sed -i "s/version = '?'/version = '${a.version}'/" setup.py
'';
});
});
}).dependencyEnv;
};
nixosModules.pretix = {
imports = [ ./nixos-module.nix ];
nixpkgs.overlays = [ self.overlay ];
};
nixosConfigurations.vm = nixpkgs.lib.nixosSystem {
system = "x86_64-linux";
modules = [
self.nixosModules.pretix
({ config, lib, pkgs, ... }:
let
# XXX: Should be passed out-of-band so as to not end-up in the
# Nix store
pretix_secret_cfg = pkgs.writeText "pretix-secrets"
(lib.generators.toKeyValue { } {
PRETIX_DATABASE_PASSWORD = "foobar";
});
in
{
system.configurationRevision = self.rev or "dirty";
services.pretix = {
enable = true;
config = {
database = {
backend = "postgresql";
name = "pretix";
host = "localhost";
user = "pretix";
};
};
secretConfig = pretix_secret_cfg;
host = "0.0.0.0";
port = 8000;
};
# Ad-hoc initialisation of the database password.
# Ideally the postgres host is on another machine and handled
# separately
systemd.services.pretix-setup = {
script = ''
# Setup the db
set -eu
${pkgs.utillinux}/bin/runuser -u ${config.services.postgresql.superUser} -- \
${config.services.postgresql.package}/bin/psql -c \
"ALTER ROLE ${config.services.pretix.config.database.user} WITH PASSWORD '$PRETIX_DATABASE_PASSWORD'"
'';
after = [ "postgresql.service" ];
requires = [ "postgresql.service" ];
before = [ "pretix.service" ];
requiredBy = [ "pretix.service" ];
serviceConfig.EnvironmentFile = pretix_secret_cfg;
};
networking.firewall.allowedTCPPorts =
[ config.services.pretix.port ];
networking.hostName = "pretix";
services.mingetty.autologinUser = "root";
})
];
};
};
}