summaryrefslogtreecommitdiff
path: root/modules/python.nix
diff options
context:
space:
mode:
authorQuentin Aristote <quentin@aristote.fr>2021-12-03 11:48:19 +0100
committerQuentin Aristote <quentin@aristote.fr>2021-12-03 11:48:19 +0100
commit6bb027dbeb3dedb6c65cb27274465105bccdfb18 (patch)
tree7613a6397d866617c5c71cb3c906d86f03baba75 /modules/python.nix
initial commit
Diffstat (limited to 'modules/python.nix')
-rw-r--r--modules/python.nix52
1 files changed, 52 insertions, 0 deletions
diff --git a/modules/python.nix b/modules/python.nix
new file mode 100644
index 0000000..ce1154c
--- /dev/null
+++ b/modules/python.nix
@@ -0,0 +1,52 @@
+{ config, lib, pkgs, ... }:
+
+with lib;
+let
+ cfg = config.python;
+ pythonWithPackages = (cfg.python.withPackages cfg.packages).override {
+ ignoreCollisions = cfg.ignoreCollisions;
+ };
+in {
+ options.python = {
+ enable = mkEnableOption { name = "python"; };
+
+ python = mkOption {
+ type = types.package;
+ default = pkgs.python3;
+ defaultText = literalExample "pkgs.python3Minimal";
+ description = ''
+ The package providing python.
+ Use this option to set the version of Python.
+ '';
+ example = literalExample "pkgs.python310";
+ };
+
+ packages = mkOption {
+ type = with types; functionTo (listOf package);
+ default = _: [ ];
+ defaultText = literalExample "_: []";
+ description = ''
+ Python packages that will be made available to the environment.
+ '';
+ example = literalExample ''
+ pythonPackages: with pythonPackages; [
+ requests (callPackage ./my-package.nix {})
+ ];
+ '';
+ };
+
+ ignoreCollisions = mkEnableOption "ignoring collisions when building the Python environnement";
+ };
+
+ config = mkIf cfg.enable {
+ buildInputs = [ pythonWithPackages ];
+ # shellHook = ''
+ # # Tells pip to put packages into $PIP_PREFIX instead of the usual locations.
+ # # See https://pip.pypa.io/en/stable/user_guide/#environment-variables.
+ # export PIP_PREFIX=$(pwd)/_build/pip_packages
+ # export PYTHONPATH="$PIP_PREFIX/${cfg.python.sitePackages}:$PYTHONPATH"
+ # export PATH="$PIP_PREFIX/bin:$PATH"
+ # unset SOURCE_DATE_EPOCH
+ # '';
+ };
+}