-
Notifications
You must be signed in to change notification settings - Fork 22
Expand file tree
/
Copy pathflake.nix
More file actions
144 lines (135 loc) · 4.09 KB
/
Copy pathflake.nix
File metadata and controls
144 lines (135 loc) · 4.09 KB
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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
nixpkgs-old-pythons.url = "github:NixOS/nixpkgs/c0b0e0fddf73fd517c3471e546c0df87a42d53f4";
git-hooks = {
url = "github:ysndr/nix-git-hooks/d48aa6c86f9ded84e342e60ebebf8f973a891aa9";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs =
{
self,
nixpkgs,
nixpkgs-old-pythons,
git-hooks,
}:
let
systems = [
"aarch64-darwin"
"aarch64-linux"
"x86_64-linux"
];
overlays = [
(
final: prev:
let
old-pkgs = nixpkgs-old-pythons.legacyPackages.${system final};
in
{
python310 = old-pkgs.python310;
}
)
git-hooks.overlay
];
perSystem = callback: nixpkgs.lib.genAttrs systems (system: callback (mkPkgs system));
mkPkgs = system: import nixpkgs { inherit system overlays; };
system = pkgs: pkgs.stdenv.hostPlatform.system;
in
{
packages = perSystem (pkgs: rec {
git-format-staged = pkgs.callPackage ./packages/git-format-staged.nix { };
default = git-format-staged;
# When npm dependencies change we need to update the dependencies hash
# in test/test.nix
update-npm-deps-hash = pkgs.writeShellApplication {
name = "update-npm-deps-hash";
runtimeInputs = with pkgs; [
prefetch-npm-deps
nix
gnused
];
text = ''
hash=$(prefetch-npm-deps package-lock.json 2>/dev/null)
echo "updated npm dependency hash: $hash" >&2
sed -i "s|sha256-[A-Za-z0-9+/=]\+|$hash|" test/test.nix
'';
};
lint-commit-message = pkgs.writeShellApplication {
name = "lint-commit-message";
runtimeInputs = [ pkgs.commitlint ];
text = ''
commitlint --edit
'';
};
format-staged-changes = pkgs.writeShellApplication {
name = "format-staged-changes";
runtimeInputs = [
self.packages.${system pkgs}.default
pkgs.black
pkgs.nixfmt
pkgs.nodejs
];
text = ''
git-format-staged --formatter 'nixfmt --filename {}' '*.nix'
git-format-staged --formatter 'black --quiet --stdin-filename {} -' '*.py' 'git-format-staged'
git-format-staged --formatter 'prettier --stdin-filepath {}' '*.json' '*.yml'
git-format-staged --formatter 'npx prettier-standard' '*.js' '*.ts'
'';
};
});
devShells = perSystem (
pkgs:
let
hook-installer = pkgs.git-hook-installer {
commit-msg = [ self.packages.${system pkgs}.lint-commit-message ];
pre-commit = [ self.packages.${system pkgs}.format-staged-changes ];
};
in
{
default = pkgs.mkShell {
packages = [
self.packages.${system pkgs}.update-npm-deps-hash
hook-installer
pkgs.git-hook-uninstaller
pkgs.black
pkgs.nixfmt
pkgs.nodejs
pkgs.prettier
];
inputsFrom = [
self.packages.${system pkgs}.default
];
shellHook = ''
install-git-hooks
'';
};
}
);
# Run tests against maintained Python versions.
#
# Run tests with,
#
# $ nix flake check --print-build-logs
#
checks = perSystem (
pkgs:
let
python_versions = with pkgs; [
python315
python314
python313
python312 # Python 3.12
python311
python310 # Python 3.10
];
in
builtins.listToAttrs (
builtins.map (python3: rec {
name = builtins.replaceStrings [ "." ] [ "_" ] "test-python_${python3.version}";
value = pkgs.callPackage ./test/test.nix { inherit name python3; };
}) python_versions
)
);
};
}