Skip to content

Commit 7c54586

Browse files
committed
1 parent 7919dfd commit 7c54586

4 files changed

Lines changed: 107 additions & 0 deletions

File tree

.envrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use flake

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
*.pyc
2+
.direnv
23
.idea
4+
.venv
35

46
regressionfiles.diff
57
regressionfiles.yaml.orig

flake.lock

Lines changed: 25 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
description = "A Nix-flake-based Python development environment";
3+
4+
inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1";
5+
6+
outputs = inputs:
7+
let
8+
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
9+
forEachSupportedSystem = f: inputs.nixpkgs.lib.genAttrs supportedSystems (system: f {
10+
pkgs = import inputs.nixpkgs { inherit system; };
11+
});
12+
13+
/*
14+
* Change this value ({major}.{min}) to
15+
* update the Python virtual-environment
16+
* version. When you do this, make sure
17+
* to delete the `.venv` directory to
18+
* have the hook rebuild it for the new
19+
* version, since it won't overwrite an
20+
* existing one. After this, reload the
21+
* development shell to rebuild it.
22+
* You'll see a warning asking you to
23+
* do this when version mismatches are
24+
* present. For safety, removal should
25+
* be a manual step, even if trivial.
26+
*/
27+
version = "3.13";
28+
in
29+
{
30+
devShells = forEachSupportedSystem ({ pkgs }:
31+
let
32+
concatMajorMinor = v:
33+
pkgs.lib.pipe v [
34+
pkgs.lib.versions.splitVersion
35+
(pkgs.lib.sublist 0 2)
36+
pkgs.lib.concatStrings
37+
];
38+
39+
python = pkgs."python${concatMajorMinor version}";
40+
in
41+
{
42+
default = pkgs.mkShell {
43+
venvDir = ".venv";
44+
45+
postShellHook = ''
46+
venvVersionWarn() {
47+
local venvVersion
48+
venvVersion="$("$venvDir/bin/python" -c 'import platform; print(platform.python_version())')"
49+
50+
[[ "$venvVersion" == "${python.version}" ]] && return
51+
52+
cat <<EOF
53+
Warning: Python version mismatch: [$venvVersion (venv)] != [${python.version}]
54+
Delete '$venvDir' and reload to rebuild for version ${python.version}
55+
EOF
56+
}
57+
58+
venvVersionWarn
59+
'';
60+
61+
packages = with python.pkgs; [
62+
venvShellHook
63+
pip
64+
65+
/* Add whatever else you'd like here. */
66+
# pkgs.basedpyright
67+
68+
# pkgs.black
69+
/* or */
70+
# python.pkgs.black
71+
72+
# pkgs.ruff
73+
/* or */
74+
# python.pkgs.ruff
75+
];
76+
};
77+
});
78+
};
79+
}

0 commit comments

Comments
 (0)