-
-
Notifications
You must be signed in to change notification settings - Fork 204
/
Copy pathflake.nix
150 lines (138 loc) · 4.38 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
{
description = "Source code project lifecycle management tool";
nixConfig = {
# HACK https://github.com/NixOS/nix/issues/6771
# TODO Leave only own cache settings when fixed
extra-trusted-public-keys = [
"copier.cachix.org-1:sVkdQyyNXrgc53qXPCH9zuS91zpt5eBYcg7JQSmTBG4="
"devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw="
];
extra-substituters = [
"https://copier.cachix.org"
"https://devenv.cachix.org"
];
# HACK https://github.com/renovatebot/renovate/issues/29721
# TODO Remove these comments when fixed
# github:NixOS/nixpkgs/nixpkgs-24.05
};
inputs = {
devenv.url = "github:cachix/devenv";
flake-compat.url = "https://flakehub.com/f/edolstra/flake-compat/1.*.tar.gz";
flake-parts.url = "github:hercules-ci/flake-parts";
nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/*.tar.gz";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = inputs @ {
flake-parts,
devenv,
nixpkgs,
nixpkgs-unstable,
...
}:
flake-parts.lib.mkFlake {inherit inputs;} {
imports = [
inputs.devenv.flakeModule
];
systems = nixpkgs.lib.systems.flakeExposed;
perSystem = {
config,
self',
inputs',
pkgs,
lib,
system,
...
}: let
python = pkgs.python311;
uv = inputs'.nixpkgs-unstable.legacyPackages.uv;
in {
devenv.shells.default = {
languages.python = {
enable = true;
package = python;
uv = {
enable = true;
package = uv;
sync.enable = true;
};
};
env = {
# Force uv to use nixpkgs' Python interpreter
UV_PYTHON = python;
# Prevent uv from managing Python downloads
UV_PYTHON_DOWNLOADS = "never";
};
tasks = {
# Patch binaries to make them runnable on NixOS
# E.g.: https://github.com/astral-sh/ruff/issues/1699
"venv:patchelf" = {
exec = ''
for exe in ruff taplo; do
${lib.getExe pkgs.patchelf} --set-interpreter ${pkgs.stdenv.cc.bintools.dynamicLinker} $(uv run which $exe)
done;
'';
after = ["devenv:python:uv"];
before = ["devenv:enterShell"];
};
};
packages = [
pkgs.git
pkgs.alejandra
pkgs.nodePackages.prettier
];
difftastic.enable = true;
pre-commit.gitPackage = pkgs.git;
pre-commit.hooks = {
alejandra.enable = true;
commitizen = {
enable = true;
package = null;
entry = "uv run cz check --allow-abort --commit-msg-file";
};
editorconfig-checker.enable = true;
editorconfig-checker.excludes = [
"\.md$"
"\.noeof\."
"\.bundle$"
];
prettier.enable = true;
prettier.excludes = [
# Some API reference identifiers are dotted paths involving
# internal modules prefixed with `_` which are converted by
# Prettier to `\_`, making them invalid.
"^docs/reference/.+\.md$"
# Those files have wrong syntax and would fail
"^tests/demo_invalid/copier.yml$"
"^tests/demo_transclude_invalid(_multi)?/demo/copier.yml$"
# HACK https://github.com/prettier/prettier/issues/9430
"^tests/demo"
];
ruff = {
enable = true;
package = null;
entry = "uv run ruff check --fix";
};
ruff-format = {
enable = true;
package = null;
entry = "uv run ruff format";
};
taplo = {
enable = true;
package = null;
entry = "uv run taplo fmt";
};
};
enterTest = ''
env \
GIT_AUTHOR_EMAIL=copier@example.com \
GIT_AUTHOR_NAME=copier \
GIT_COMMITTER_EMAIL=copier@example.com \
GIT_COMMITTER_NAME=copier \
PYTHONOPTIMIZE= \
uv run poe test
'';
};
};
};
}