Skip to content

Commit a0a733a

Browse files
authored
Fix several problems with the nix setup. (#546)
* Fix several problems with the nix setup. Signed-off-by: Rolf Schröder <[email protected]>
1 parent 64d52ec commit a0a733a

File tree

2 files changed

+27
-15
lines changed

2 files changed

+27
-15
lines changed

etc/nix/flake.nix

Lines changed: 25 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -61,30 +61,40 @@
6161
pypiDataSha256 =
6262
"0499zl39aia74f0i7fkn5dsy8244dkmcw4vzd5nf4kai605j2jli";
6363
});
64+
# This wrapper allows to setup both the production as well as the
65+
# development Python environments in the same way (albeit having
66+
# different requirements.txt).
67+
getPythonEnv = system: requirements:
68+
machnixFor.${system}.mkPython {
69+
requirements = ''
70+
${requirements}
71+
'';
72+
# Fix an issue with an upstream dep of GitPython.
73+
# https://github.com/DavHau/mach-nix/issues/287
74+
# See https://github.com/DavHau/mach-nix/issues/318
75+
_.gitpython.propagatedBuildInputs.mod = pySelf: self: oldVal:
76+
oldVal ++ [ pySelf.typing-extensions ];
77+
};
6478

6579
in {
6680

6781
# A Nixpkgs overlay.
6882
overlay = final: prev:
6983
with final.pkgs; {
7084

71-
pythonEnv = machnixFor.${system}.mkPython {
72-
requirements = ''
73-
${requirements}
74-
'';
75-
};
85+
pythonEnv = getPythonEnv system requirements;
7686

7787
vulnerablecode = stdenv.mkDerivation {
7888
inherit version;
7989
name = "vulnerablecode-${version}";
8090
src = vulnerablecode-src;
81-
dontConfigure = true; # do not use ./configure
91+
dontBuild = true; # do not use Makefile
8292
propagatedBuildInputs = [ pythonEnv postgresql gitMinimal ];
8393

8494
postPatch = ''
85-
# Make sure the pycodestyle binary in $PATH is used.
86-
substituteInPlace vulnerabilities/tests/test_basics.py \
87-
--replace 'join(bin_dir, "pycodestyle")' '"pycodestyle"'
95+
# Do not use absolute path.
96+
substituteInPlace vulnerablecode/settings.py \
97+
--replace 'STATIC_ROOT = "/var/vulnerablecode/static"' 'STATIC_ROOT = "./static"'
8898
'';
8999

90100
installPhase = ''
@@ -117,12 +127,10 @@
117127
# Tests run by 'nix flake check' and by Hydra.
118128
checks = forAllSystems (system:
119129
let
120-
pythonEnvDev = machnixFor.${system}.mkPython {
121-
requirements = ''
122-
${requirements}
123-
${requirementsDev}
124-
'';
125-
};
130+
pythonEnvDev = getPythonEnv system ''
131+
${requirements}
132+
${requirementsDev}
133+
'';
126134

127135
in {
128136
inherit (self.packages.${system}) vulnerablecode;
@@ -138,6 +146,8 @@
138146
buildPhase = ''
139147
source ${libSh}
140148
initPostgres $(pwd)
149+
export SECRET_KEY=REALLY_SECRET
150+
${vulnerablecode}/manage.py collectstatic --no-input
141151
${vulnerablecode}/manage.py migrate
142152
'';
143153

etc/nix/test-import-using-nix.sh

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
1010
DEFAULT_INSTALL_DIR=$VULNERABLECODE_INSTALL_DIR # in the Nix store, see flake.nix
1111
INSTALL_DIR=${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}
1212
ARGS=$(if [ $# -eq 0 ]; then echo "--all"; else echo "$@"; fi)
13+
export SECRET_KEY=REALLY_SECRET
1314
TEMPDIR=$(mktemp -d -p "$THIS_DIR")
1415
export TEMPDIR
1516

@@ -25,4 +26,5 @@ trap cleanup EXIT
2526
initPostgres "$TEMPDIR"
2627

2728
"$INSTALL_DIR/manage.py" migrate
29+
"$INSTALL_DIR/manage.py" collectstatic --no-input
2830
"$INSTALL_DIR/manage.py" import $ARGS

0 commit comments

Comments
 (0)