Inherited a Django app with a non-standard requirements.txt
that translates to the following:
Django == 2.1.5
psycopg2-binary
django-crispy-forms
django-debug-toolbar
django-tables2
openpyxl
django-mathfilters
django-audit-log
django-reversion
django-simple-history
I think I found the answer in the Python section of the Nixpkgs manual (in chapter 15.19.1.2.1. Python library packages in Nixpkgs to be precise), but before spending an inordinate amount of time, I would like to know whether this approach is indeed the most efficient/pragmatic/etc.
I got the first 3 lines so far but it is representative of the entire file because
- it requires pinning of Python packages (which I haven’t been able to figure out yet)
- has packages that are already part of the Python packages in Nixpkgs
- and packages that need to be added manually (e.g.,
django-crispy-forms
)
I have been very lucky with django-crispy-forms
because it is not part of the supported Python packages, but there is a derivation for it elsewhere in Nixpkgs so I could use it as a template.
The contents of the current shell.nix
file are below, and my question is: should I continue along this vein?
# TODO pin this as soon as possible
{ pkgs ? import <nixpkgs> {} }:
let
pythonEnv =
let
django-crispy-forms = pkgs.python38.pkgs.buildPythonPackage rec {
pname = "django-crispy-forms";
version = "1.10.0";
src = pkgs.fetchFromGitHub {
owner = "django-crispy-forms";
repo = "django-crispy-forms";
rev = version;
sha256 = "0y6kskfxgckb9npcgwx4zrs5n9px159zh9zhinhxi3i7wlriqpf5";
};
# For reasons unknown, the source dir must contain a dash
# for the tests to run successfully
postUnpack = ''
mv $sourceRoot source-
export sourceRoot=source-
'';
checkInputs =
[ pkgs.python38Packages.django
pkgs.python38Packages.pytest-django
pkgs.python38Packages.pytestCheckHook
];
preCheck = ''
export DJANGO_SETTINGS_MODULE=crispy_forms.tests.test_settings
'';
meta = with pkgs.lib; {
description = "The best way to have DRY Django forms";
homepage = "https://github.com/maraujop/django-crispy-forms";
license = licenses.mit;
maintainers = with maintainers; [ earvstedt ];
};
};
in
pkgs.python38.withPackages (
packages:
[ packages.django
packages.psycopg2
django-crispy-forms
]
);
in
pkgs.mkShell {
buildInputs = [
pythonEnv
];
}
(I’m learning Python, Django, and more advanced Nix techniques at the same time so my replies may be a bit delayed to make sure I understood your suggestions… Thanks!)
I gave pypi2nix
a try but it wouldn’t work unfortunately.