aboutsummaryrefslogtreecommitdiff
path: root/flake.nix
diff options
context:
space:
mode:
Diffstat (limited to 'flake.nix')
-rw-r--r--flake.nix42
1 files changed, 42 insertions, 0 deletions
diff --git a/flake.nix b/flake.nix
new file mode 100644
index 0000000..3c153d3
--- /dev/null
+++ b/flake.nix
@@ -0,0 +1,42 @@
+{
+ description = "A very basic flake for developing in python";
+ # Provides abstraction to boiler-code when specifying multi-platform outputs.
+ inputs = {
+ flake-utils.url = "github:numtide/flake-utils";
+ nixpkgs.url = "github:nixos/nixpkgs";
+ };
+ outputs = { self, nixpkgs, flake-utils }:
+ flake-utils.lib.eachDefaultSystem (system: let
+ pkgs = nixpkgs.legacyPackages.${system};
+ venvDir = "./.venv";
+ pythonPackages = pkgs.python38Packages;
+ in {
+ devShell = pkgs.mkShell {
+ nativeBuildInputs = with pkgs; [
+ hello
+ pythonPackages.python
+ ];
+ shellHook = ''
+ SOURCE_DATE_EPOCH=$(date +%s)
+
+ if [ -d "${venvDir}" ]; then
+ echo "Skipping venv creation, '${venvDir}' already exists"
+ else
+ echo "Creating new venv environment in path: '${venvDir}'"
+ # Note that the module venv was only introduced in python 3, so for 2.7
+ # this needs to be replaced with a call to virtualenv
+ ${pythonPackages.python.interpreter} -m venv "${venvDir}"
+ fi
+
+ # Under some circumstances it might be necessary to add your virtual
+ # environment to PYTHONPATH, which you can do here too;
+ # PYTHONPATH=$PWD/${venvDir}/${pythonPackages.python.sitePackages}/:$PYTHONPATH
+
+ source "${venvDir}/bin/activate"
+
+ # As in the previous example, this is optional.
+ pip install -r requirements.txt
+ '';
+ };
+ });
+}