Skip to content

Commit a132b99

Browse files
committed
Make pre-commit use Python 3.11
I’m working on a commit in the mailserver-dns branch that depends on pre-commit using Python 3.11. See the comments that this commit adds for details.
1 parent bfe5695 commit a132b99

File tree

1 file changed

+42
-2
lines changed

1 file changed

+42
-2
lines changed

imports/git-graphical.nix

Lines changed: 42 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,53 @@
88
# that also didn’t work.
99
environment.systemPackages = [ pkgs.nodejs ];
1010
home-manager.users.jayman = { pkgs, ... }: {
11-
home.packages = [
11+
# Adapted from
12+
# <https://nix-community.github.io/home-manager/index.html#_how_do_i_install_packages_from_nixpkgs_unstable>.
13+
home.packages = let
14+
url = "https://github.com/NixOS/nixpkgs/archive/refs/heads/nixos-unstable.tar.gz";
15+
tarball = builtins.fetchTarball url;
16+
unstablePkgs = import tarball {};
17+
# Thanks to strager
18+
# (<https://stackoverflow.com/users/39992/strager>)
19+
# for this idea:
20+
# <https://stackoverflow.com/a/71245733/7593853>
21+
pyOverrides = finalAttrs: previousAttrs: {
22+
# The version of python3Packages.cffi in
23+
# the stable version of nixpkgs doesn’t
24+
# work with Python 3.11. See
25+
# <https://foss.heptapod.net/pypy/cffi/-/issues/551>.
26+
#
27+
# The only reason we want cffi to work
28+
# with Python 3.11 it’s an indirect
29+
# dependency of pre-commit. See below
30+
# for why we want to run pre-commit with
31+
# Python 3.11.
32+
cffi = unstablePkgs.python311Packages.cffi;
33+
};
34+
overlay = finalAttrs: previousAttrs: {
35+
python311 = previousAttrs.python311.override {
36+
packageOverrides = pyOverrides;
37+
};
38+
};
39+
pkgs = import <nixpkgs> {
40+
overlays = [ overlay ];
41+
};
42+
in [
1243
pkgs.cargo # Used for this repo’s pre-commit config
1344
pkgs.gcc # Used for this repo’s pre-commit config
1445
pkgs.go # Used for this repo’s pre-commit config
46+
47+
# In a future commit, I’m going to add a Python
48+
# script that requires Python 3.11. We need to
49+
# make sure that pre-commit uses Python 3.11 so
50+
# that the mypy hook uses Python 3.11. If we
51+
# were to run the mypy hook with Python 3.10,
52+
# then the mypy hook would fail to check that
53+
# Python 3.11-only script.
1554
(pkgs.pre-commit.override {
16-
python3Packages = pkgs.python310Packages;
55+
python3Packages = pkgs.python311Packages;
1756
})
57+
1858
(import applications/git-bhc.nix)
1959
(import applications/git-tb.nix)
2060
];

0 commit comments

Comments
 (0)