forked from NixOS/nix-security-tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault.nix
More file actions
163 lines (149 loc) · 4.34 KB
/
default.nix
File metadata and controls
163 lines (149 loc) · 4.34 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
{
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",
}:
rec {
inherit pkgs;
inherit (pkgs) python3;
localPythonPackages = import ./pkgs { inherit pkgs python3; };
# For exports.
overlays = [ overlay ];
package = pkgs.web-security-tracker;
module = import ./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" ''
${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";
};
# `./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
export CREDENTIALS_DIRECTORY=${builtins.toString ./.credentials}
touch .settings.py
export USER_SETTINGS_FILE=${builtins.toString ./.settings.py}
'';
};
tests = import ./nix/tests/vm-basic.nix {
inherit pkgs;
wstModule = module;
};
}