Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add languages.python.version #641

Merged
merged 1 commit into from
Jun 2, 2023
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
3 changes: 3 additions & 0 deletions examples/python/.test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#!/bin/sh
set -ex
python --version | grep "3.7.16"
6 changes: 6 additions & 0 deletions examples/python/devenv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{ pkgs, ... }:

{
languages.python.enable = true;
languages.python.version = "3.7.16";
}
5 changes: 5 additions & 0 deletions examples/python/devenv.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
inputs:
nixpkgs:
url: github:NixOS/nixpkgs/nixpkgs-unstable
nixpkgs-python:
url: github:cachix/nixpkgs-python
24 changes: 23 additions & 1 deletion src/modules/languages/python.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,16 @@
{ pkgs, config, lib, ... }:
{ pkgs, config, lib, inputs, ... }:

let
cfg = config.languages.python;

nixpkgs-python = inputs.nixpkgs-python or (throw ''
To use languages.python.version, you need to add the following to your devenv.yaml:

inputs:
nixpkgs-python:
url: github:cachix/nixpkgs-python
'');

venvPath = "${config.env.DEVENV_STATE}/venv";

initVenvScript = pkgs.writeShellScript "init-venv.sh" ''
Expand Down Expand Up @@ -96,6 +104,16 @@ in
description = "The Python package to use.";
};

version = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
description = ''
The Python version to use.
This automatically sets the `languages.python.package` using [nixpkgs-python](https://github.com/cachix/nixpkgs-python).
'';
example = "3.11 or 3.11.2";
};

venv.enable = lib.mkEnableOption "Python virtual environment";

poetry = {
Expand Down Expand Up @@ -138,6 +156,10 @@ in

languages.python.poetry.activate.enable = lib.mkIf cfg.poetry.enable (lib.mkDefault true);

languages.python.package = lib.mkMerge [
(lib.mkIf (cfg.version != null) (nixpkgs-python.packages.${pkgs.stdenv.system}.${cfg.version} or (throw "Unsupported Python version, see https://github.com/cachix/nixpkgs-python#supported-python-versions")))
];

packages = [
cfg.package
] ++ (lib.optional cfg.poetry.enable cfg.poetry.package);
Expand Down