-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathflake.nix
215 lines (194 loc) · 6.25 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
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
{
description = "Rust library for tools and encodings related to SAT solving library";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11";
systems.url = "github:nix-systems/default";
rust-overlay.url = "github:oxalica/rust-overlay";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
nix-tools.url = "github:gleachkr/nix-tools";
nix-tools.inputs.nixpkgs.follows = "nixpkgs";
git-hooks.url = "github:chrjabs/git-hooks.nix";
git-hooks.inputs.nixpkgs.follows = "nixpkgs";
nix-github-actions.url = "github:nix-community/nix-github-actions";
nix-github-actions.inputs.nixpkgs.follows = "nixpkgs";
};
outputs = {
self,
nixpkgs,
systems,
rust-overlay,
nix-tools,
git-hooks,
nix-github-actions,
}: let
lib = nixpkgs.lib;
forAllSystems = lib.genAttrs (import systems);
pkgsFor = lib.genAttrs (import systems) (system: (import nixpkgs {
inherit system;
overlays = [(import rust-overlay) nix-tools.overlays.default rust-toolchain-overlay];
}));
rust-toolchain-overlay = _: super: {
rust-toolchain = super.symlinkJoin {
name = "rust-toolchain";
paths = [(super.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml)];
buildInputs = [super.makeWrapper];
postBuild = ''
wrapProgram $out/bin/cargo --set LIBCLANG_PATH ${super.libclang.lib}/lib
'';
};
};
in {
devShells = forAllSystems (system: {
default = let
pkgs = pkgsFor.${system};
libs = with pkgs; [openssl xz bzip2];
git-subtree-cmd =
pkgs.writeShellScriptBin "git-subtree"
/*
bash
*/
''
SUBTREE="$1"
CMD="$2"
REF="$3"
declare -A prefixes
prefixes=(
["minisat"]="minisat/cppsrc"
["glucose"]="glucose/cppsrc"
["cadical"]="cadical/cppsrc"
["kissat"]="kissat/csrc"
)
case $CMD in
pull)
echo "Pulling subtree $SUBTREE from ref $REF"
git subtree pull --prefix "''${prefixes[$SUBTREE]}" "$SUBTREE" "$REF" --squash -m "chore($SUBTREE): update subtree"
;;
push)
echo "Pushing subtree $SUBTREE to ref $REF"
git subtree push --prefix "''${prefixes[$SUBTREE]}" "$SUBTREE" "$REF"
;;
*)
2>&1 echo "Unknown command $CMD"
2>&1 echo "Usage: git-subtree <subtree> <command> <ref>"
esac
'';
pr-merge-ff-cmd =
pkgs.writeShellScriptBin "pr-merge-ff"
/*
bash
*/
''
set -e
if ! ${lib.getExe pkgs.gh} pr checks ; then
2>&1 echo "PR checks have not (yet) passed"
exit 1
fi
BASE=main
DELETE=false
case "$1" in
"-d")
DELETE=true
;;
*)
echo "setting base branch to $1"
BASE="$1"
esac
BRANCH=$(git rev-parse --abbrev-ref HEAD)
git switch "$BASE"
git merge --ff-only "$BRANCH"
if $DELETE ; then
git branch -d "$BRANCH"
fi
git push
'';
in
pkgs.mkShell.override {stdenv = pkgs.clangStdenv;} rec {
inherit (self.checks.${system}.pre-commit-check) shellHook;
nativeBuildInputs = with pkgs;
[
llvmPackages_12.bintools
pkg-config
clang
cmake
rust-toolchain
cargo-rdme
cargo-nextest
release-plz
jq
maturin
kani
git-subtree-cmd
pr-merge-ff-cmd
]
++ self.checks.${system}.pre-commit-check.enabledPackages;
buildInputs = libs;
LIBCLANG_PATH = "${pkgs.libclang.lib}/lib";
LD_LIBRARY_PATH = lib.makeLibraryPath libs;
PKG_CONFIG_PATH = "${pkgs.openssl.dev}/lib/pkgconfig/";
};
});
packages = forAllSystems (system: {
tools = pkgsFor.${system}.callPackage ./tools {};
});
checks = forAllSystems (system: {
pre-commit-check = let
pkgs = pkgsFor.${system};
in
git-hooks.lib.${system}.run {
src = ./.;
tools.cargo = pkgs.rust-toolchain;
settings.rust.check.cargoDeps = pkgs.rustPlatform.importCargoLock {lockFile = ./Cargo.lock;};
hooks = let
cargo-spellcheck = lib.getExe pkgs.cargo-spellcheck;
in {
# Rust
cargo-check = {
enable = true;
args = ["--workspace"];
extraPackages = with pkgs; [
pkg-config
clang
cmake
openssl
libclang
];
};
rustfmt.enable = true;
cargo-spellcheck = {
enable = true;
name = "Spellchecking documentation";
entry = "${cargo-spellcheck} --code 1";
language = "system";
files = "(.+\\.rs|docs/.+\\.md)$";
};
# TOML
check-toml.enable = true;
taplo.enable = true;
# Github actions
actionlint.enable = true;
check-yaml.enable = true;
# Nix
alejandra.enable = true;
deadnix.enable = true;
# Python
black.enable = true;
# General neatness
check-added-large-files.enable = true;
end-of-file-fixer = {
enable = true;
excludes = [".+\\.(patch|log)$" "cadical/cppsrc/.+" "kissat/csrc/.+"];
};
trim-trailing-whitespace = {
enable = true;
excludes = [".+\\.(patch|log)$" "cadical/cppsrc/.+" "kissat/csrc/.+"];
};
check-symlinks.enable = true;
no-commit-to-branch.enable = true;
};
};
});
githubActions = nix-github-actions.lib.mkGithubMatrix {
checks = self.checks // self.packages;
};
};
}