Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 25 additions & 15 deletions etc/nix/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -61,30 +61,40 @@
pypiDataSha256 =
"0499zl39aia74f0i7fkn5dsy8244dkmcw4vzd5nf4kai605j2jli";
});
# This wrapper allows to setup both the production as well as the
# development Python environments in the same way (albeit having
# different requirements.txt).
getPythonEnv = system: requirements:
machnixFor.${system}.mkPython {
requirements = ''
${requirements}
'';
# Fix an issue with an upstream dep of GitPython.
# https://github.com/DavHau/mach-nix/issues/287
# See https://github.com/DavHau/mach-nix/issues/318
_.gitpython.propagatedBuildInputs.mod = pySelf: self: oldVal:
oldVal ++ [ pySelf.typing-extensions ];
};

in {

# A Nixpkgs overlay.
overlay = final: prev:
with final.pkgs; {

pythonEnv = machnixFor.${system}.mkPython {
requirements = ''
${requirements}
'';
};
pythonEnv = getPythonEnv system requirements;

vulnerablecode = stdenv.mkDerivation {
inherit version;
name = "vulnerablecode-${version}";
src = vulnerablecode-src;
dontConfigure = true; # do not use ./configure
dontBuild = true; # do not use Makefile

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

configure doesn't exist anymore, Makefile was added.

propagatedBuildInputs = [ pythonEnv postgresql gitMinimal ];

postPatch = ''
# Make sure the pycodestyle binary in $PATH is used.
substituteInPlace vulnerabilities/tests/test_basics.py \
--replace 'join(bin_dir, "pycodestyle")' '"pycodestyle"'

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

pycodestyle is not used anymore.

# Do not use absolute path.
substituteInPlace vulnerablecode/settings.py \
--replace 'STATIC_ROOT = "/var/vulnerablecode/static"' 'STATIC_ROOT = "./static"'
'';

installPhase = ''
Expand Down Expand Up @@ -117,12 +127,10 @@
# Tests run by 'nix flake check' and by Hydra.
checks = forAllSystems (system:
let
pythonEnvDev = machnixFor.${system}.mkPython {
requirements = ''
${requirements}
${requirementsDev}
'';
};
pythonEnvDev = getPythonEnv system ''
${requirements}
${requirementsDev}
'';

in {
inherit (self.packages.${system}) vulnerablecode;
Expand All @@ -138,6 +146,8 @@
buildPhase = ''
source ${libSh}
initPostgres $(pwd)
export SECRET_KEY=REALLY_SECRET

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ce64bce removed the DJANGO_DEV=1 setting, I would guess without testing it: Setting neither DJANGO_DEV=1 nor the SECRET_KEY results in an error.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, DJANGO_DEV is not present now. Please use make envfile. A basic make based run is at https://github.com/nexB/vulnerablecode/blob/main/.github/workflows/main.yml

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Hritik14 Thanks, if I understand you correctly, you suggest to run make dev envfile (https://github.com/nexB/vulnerablecode/blob/main/.github/workflows/main.yml#L24). The dev target makes no sense since the Nix setup doesn't run pip -r requirements on purpose. As for the envfile target, it creates the file but uses the non-deterministic urandom source, which is not feasible in Nix. I'm not convinced it is better to use make than to simply set the env var as I proposed here.

${vulnerablecode}/manage.py collectstatic --no-input
${vulnerablecode}/manage.py migrate
'';

Expand Down
2 changes: 2 additions & 0 deletions etc/nix/test-import-using-nix.sh
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ THIS_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
DEFAULT_INSTALL_DIR=$VULNERABLECODE_INSTALL_DIR # in the Nix store, see flake.nix
INSTALL_DIR=${INSTALL_DIR:-$DEFAULT_INSTALL_DIR}
ARGS=$(if [ $# -eq 0 ]; then echo "--all"; else echo "$@"; fi)
export SECRET_KEY=REALLY_SECRET
TEMPDIR=$(mktemp -d -p "$THIS_DIR")
export TEMPDIR

Expand All @@ -25,4 +26,5 @@ trap cleanup EXIT
initPostgres "$TEMPDIR"

"$INSTALL_DIR/manage.py" migrate
"$INSTALL_DIR/manage.py" collectstatic --no-input
"$INSTALL_DIR/manage.py" import $ARGS