forked from pre-commit/pre-commit
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
115 lines (102 loc) · 3.63 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
{
description = "pre-commit in docker";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
devshell = {
url = "github:numtide/devshell";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = { self, nixpkgs, flake-utils, devshell }:
flake-utils.lib.eachDefaultSystem
(system:
let
overlays = [
devshell.overlays.default
];
pkgs = import nixpkgs {
inherit system overlays;
};
# docker-out-of-docker
docker-client = pkgs.docker_24.override {
clientOnly = true;
buildxSupport = false;
composeSupport = false;
};
# using buildkit will need this because frontends are pulled
# from the client (not from the daemon)
wrap-docker = pkgs.writeShellScriptBin "docker" ''
export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
${docker-client}/bin/docker $@
'';
# pre_commit pypy package is not available in nixpkgs
# lazy - this is first called _after_ we have the python-pkgs
pre_commit = ps: ps.callPackage ./pre-commit.nix { };
in
rec {
# a python environment with pre_commit installed
packages.python-env = pkgs.python39.withPackages
(python-pkgs: [
(pre_commit python-pkgs)
python-pkgs.cfgv
python-pkgs.identify
python-pkgs.pyyaml
python-pkgs.virtualenv
python-pkgs.pip
python-pkgs.setuptools
python-pkgs.wheel
python-pkgs.nodeenv
]);
packages.wrapper = pkgs.writeShellScriptBin "pre-commit-wrapper" ''
export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
cd /project
export PATH=$PATH:${pkgs.lib.makeBinPath [pkgs.git wrap-docker]}
${packages.python-env}/bin/python -mpre_commit hook-impl \
--config=/project/pre-commit-config.yaml \
--hook-type=pre-commit \
--hook-dir /config \
-- "$@"
'';
packages.commit-msg-wrapper = pkgs.writeShellScriptBin "commit-msg-wrapper" ''
export SSL_CERT_FILE="${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt"
cd /project
export PATH=$PATH:${pkgs.lib.makeBinPath [pkgs.git wrap-docker]}
${pkgs.git}/bin/git config user.name "Jim Clark"
${packages.python-env}/bin/python -mpre_commit hook-impl \
--config=/project/pre-commit-config.yaml \
--hook-type=commit-msg \
--hook-dir /config \
-- "$@"
'';
packages.default = pkgs.buildEnv {
name = "install";
paths = [
packages.wrapper
packages.commit-msg-wrapper
pkgs.bash
pkgs.coreutils
];
};
devShells.default = pkgs.mkShell {
name = "python";
nativeBuildInputs = with pkgs;
let
devpython = pkgs.python39.withPackages
(packages: with packages; [
virtualenv
nodeenv
pip
setuptools
wheel
requests
python-dotenv
pathspec
tiktoken
pytest
]);
in
[ devpython ];
};
});
}