-
Notifications
You must be signed in to change notification settings - Fork 18
Expand file tree
/
Copy pathdefault.nix
More file actions
174 lines (160 loc) · 4.98 KB
/
default.nix
File metadata and controls
174 lines (160 loc) · 4.98 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
{
system ? builtins.currentSystem,
sources ? import ./npins,
overlay ? import ./nix/overlay.nix,
pkgs ? import sources.nixpkgs {
config = { };
overlays = [ overlay ];
inherit system;
},
lib ? import "${sources.nixpkgs}/lib",
name ? "web-security-tracker",
}:
rec {
inherit pkgs name;
inherit (pkgs) python3;
localPythonPackages = import ./pkgs { inherit pkgs python3; };
# For exports.
overlays = [ overlay ];
# TODO: `callPackage` the derivation here instead of splicing through
# overlays, it's needlessly hard to follow
package = pkgs.web-security-tracker;
module = ./nix/web-security-tracker.nix;
dev-container = import ./infra/container.nix;
dev-setup = import ./nix/dev-setup.nix;
pre-commit-check = pkgs.pre-commit-hooks {
src = ./.;
# Do not run at pre-commit time, it prevent the workflow where
# we just absorb things up.
default_stages = [
"pre-push"
];
hooks =
let
pythonExcludes = [
"/migrations/" # auto-generated code
];
in
{
# Nix setup
nixfmt-rfc-style.enable = true;
statix = {
enable = true;
settings.ignore = [ "staging" ];
};
deadnix.enable = true;
# Python setup
ruff = {
enable = true;
excludes = pythonExcludes;
};
ruff-format = {
enable = true;
name = "Format python code with ruff";
types = [
"text"
"python"
];
entry = "${pkgs.lib.getExe pkgs.ruff} format";
excludes = pythonExcludes;
};
pyright =
let
pyEnv = pkgs.python3.withPackages (_: pkgs.web-security-tracker.propagatedBuildInputs);
wrappedPyright = pkgs.runCommand "pyright" { nativeBuildInputs = [ pkgs.makeWrapper ]; } ''
makeWrapper ${pkgs.pyright}/bin/pyright $out \
--set PYTHONPATH ${pyEnv}/${pyEnv.sitePackages} \
--prefix PATH : ${pyEnv}/bin \
--set PYTHONHOME ${pyEnv}
'';
in
{
enable = true;
entry = lib.mkForce (builtins.toString wrappedPyright);
excludes = pythonExcludes;
};
# Global setup
prettier = {
enable = true;
excludes = [
"\\.min.css$"
"\\.html$"
"npins/sources\\.json$"
] ++ pythonExcludes;
};
commitizen = {
enable = true;
# This should check the commit message, so better warn early.
stages = [ "commit-msg" ];
};
};
};
# shell environment for continuous integration runs
ci =
let
deploy = pkgs.writeShellApplication {
name = "deploy";
text = builtins.readFile ./infra/deploy.sh;
runtimeInputs = with pkgs; [
nixos-rebuild
coreutils
];
# TODO: satisfy shellcheck
checkPhase = "";
};
in
pkgs.mkShellNoCC {
packages = [
pkgs.npins
deploy
];
};
shell =
let
manage = pkgs.writeScriptBin "manage" ''
exec ${python3}/bin/python ${toString ./src/website/manage.py} $@
'';
deploymentSources = import ./infra/npins;
in
pkgs.mkShellNoCC {
env = {
REDIS_SOCKET_URL = "unix:///run/redis/redis.sock";
DATABASE_URL = "postgres://nix-security-tracker@/nix-security-tracker";
# psql doesn't take DATABASE_URL
PGDATABASE = "nix-security-tracker";
PGUSER = "nix-security-tracker";
CREDENTIALS_DIRECTORY = toString ./.credentials;
DJANGO_SETTINGS = builtins.toJSON {
DEBUG = true;
SYNC_GITHUB_STATE_AT_STARTUP = false;
GH_ISSUES_PING_MAINTAINERS = false;
GH_ORGANIZATION = "Nix-Security-WG";
GH_ISSUES_REPO = "sectracker-testing";
GH_SECURITY_TEAM = "setracker-testing-security";
GH_COMMITTERS_TEAM = "sectracker-testing-committers";
STATIC_ROOT = "${toString ./src/website/static}";
};
};
# `./src/website/tracker/settings.py` by default looks for LOCAL_NIXPKGS_CHECKOUT
# in the root of the repo. Make it the default here for local development.
LOCAL_NIXPKGS_CHECKOUT = toString ./. + "/nixpkgs";
packages = [
manage
package
pkgs.nix-eval-jobs
pkgs.npins
pkgs.hivemind
pkgs.awscli
(import deploymentSources.agenix { inherit pkgs; }).agenix
] ++ pre-commit-check.enabledPackages;
shellHook = ''
${pre-commit-check.shellHook}
ln -sf ${sources.htmx}/dist/htmx.js src/website/webview/static/htmx.min.js
mkdir -p $CREDENTIALS_DIRECTORY
# TODO(@fricklerhandwerk): move all configuration over to pydantic-settings
touch .settings.py
export USER_SETTINGS_FILE=${builtins.toString ./.settings.py}
'';
};
tests = pkgs.callPackage ./nix/tests.nix { application = name; };
}