-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
80 lines (78 loc) · 2.79 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
{
description = "A simple token based voting system";
inputs = {
nixpkgs.url = "github:mayflower/nixpkgs/mf-stable";
argocd-nix-flakes-plugin = {
url = "github:mayflower/argocd-nix-flakes-plugin";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, argocd-nix-flakes-plugin }: let
inherit (nixpkgs) lib;
forEachSystem = lib.genAttrs [ "x86_64-linux" ];
pkgs = forEachSystem (system: nixpkgs.legacyPackages.${system});
uwsgi = forEachSystem (system: pkgs.${system}.uwsgi.override { plugins = [ "python3" ]; });
djangoEnv = forEachSystem (system: uwsgi.${system}.python3.withPackages (ps: [
ps.django
ps.psycopg2
self.packages.${system}.django_config
]));
in {
devShells = forEachSystem (system: with pkgs.${system}; {
default = mkShell {
name = "demockrazy-env";
buildInputs = [
python3
python3Packages.django
python3Packages.psycopg2
tanka
jsonnet-bundler
sops
];
};
});
packages = forEachSystem (system: with pkgs.${system}; {
django_config = uwsgi.${system}.python3.pkgs.buildPythonPackage {
name = "demockrazy-config";
format = "other";
dontUnpack = true;
installPhase = ''
install -D \
${self}/k8s/settings.py \
$out/${uwsgi.${system}.python3.sitePackages}/demockrazy_config/__init__.py
'';
};
uwsgi = writeShellScriptBin "demockrazy-uwsgi" ''
# FIXME is this really a nice solution? Check if this can cause small downtimes.
pushd ${self} &>/dev/null
${lib.concatMapStrings (cmd: ''
DJANGO_SETTINGS_MODULE=demockrazy_config ${djangoEnv.${system}}/bin/python3 manage.py ${cmd}
'') [ "makemigrations" "migrate" ]}
popd &>/dev/null
${uwsgi.${system}}/bin/uwsgi \
--json ${writeText "demockrazy.json" (builtins.toJSON {
uwsgi = {
buffer-size = 8192;
chdir = self;
env = "DJANGO_SETTINGS_MODULE=demockrazy_config";
master = self;
plugins = [ "python3" ];
protocol = "uwsgi";
pythonpath = "${djangoEnv.${system}}/${uwsgi.${system}.python3.sitePackages}";
wsgi-file = "demockrazy/wsgi.py";
socket = "0.0.0.0:3000";
};
})}
'';
});
dockerImages = forEachSystem (system: with pkgs.${system}; {
default = callPackage ./nix/demockracy-image.nix {
uwsgi = self.packages.${system}.uwsgi;
};
nginx = callPackage ./nix/nginx-image.nix { };
});
apps = forEachSystem (system: with pkgs.${system}; {
inherit (argocd-nix-flakes-plugin.apps.${system}) tankaShow tankaEval;
});
};
}