Skip to content

Commit 570cf68

Browse files
author
Lymah123
committed
chore: switch to crate2nix
chore: switch to crate2nix
1 parent 6c4a06c commit 570cf68

8 files changed

Lines changed: 145 additions & 43 deletions

File tree

flake-parts/crate2nix.nix

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{ inputs, ... }:
2+
{
3+
perSystem = _: {
4+
nixpkgs.overlays = [
5+
(_: prev: {
6+
crate2nixTools = prev.callPackage "${inputs.crate2nix}/tools.nix" { };
7+
})
8+
];
9+
};
10+
}

flake-parts/rust.nix

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1+
{ inputs, ... }:
12
{
23
gitignore = [ "/target" ];
34
perSystem =
45
{ pkgs, ... }:
56
{
67
make-shells.default = {
7-
inputsFrom = [ pkgs.statix ];
88
packages = [
9+
pkgs.cargo
10+
pkgs.rustc
911
pkgs.bacon
1012
pkgs.cargo-insta
1113
pkgs.rust-analyzer

flake-parts/statix.nix

Lines changed: 62 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,69 @@
1+
{
2+
root,
3+
...
4+
}:
15
{
26
perSystem =
37
{ pkgs, ... }:
8+
let
9+
statixBuild = pkgs.statix-workspace.workspaceMembers.statix.build;
10+
src = pkgs.lib.fileset.toSource {
11+
inherit root;
12+
fileset = pkgs.lib.fileset.fileFilter (
13+
file:
14+
pkgs.lib.any pkgs.lib.id [
15+
(file.name == "Cargo.toml")
16+
(file.hasExt "rs")
17+
(file.hasExt "snap")
18+
]
19+
) root;
20+
};
21+
in
422
{
523
treefmt.settings.global.excludes = [ "bin/tests/data/*.nix" ];
6-
checks.build = pkgs.statix;
24+
checks = {
25+
inherit (pkgs) statix;
26+
statix-tests = statixBuild.override {
27+
runTests = true;
28+
testPreRun = ''
29+
mkdir -p $TMPDIR/cargo-wrapper/bin
30+
cat > $TMPDIR/cargo-wrapper/bin/cargo << 'WRAPPER'
31+
#!/bin/sh
32+
if [ "$1" = "run" ] && [ "$2" = "--" ]; then
33+
shift 2
34+
exec ${pkgs.statix}/bin/statix "$@"
35+
fi
36+
exec ${pkgs.cargo}/bin/cargo "$@"
37+
WRAPPER
38+
chmod +x $TMPDIR/cargo-wrapper/bin/cargo
39+
export PATH=$TMPDIR/cargo-wrapper/bin:${pkgs.cargo}/bin:$PATH
40+
export INSTA_SNAPSHOT_DIR=${root}/bin/tests/snapshots
41+
'';
42+
};
43+
clippy = pkgs.rustPlatform.buildRustPackage {
44+
pname = "statix-clippy";
45+
version = "0.6.0-git";
46+
src = pkgs.lib.fileset.toSource {
47+
inherit root;
48+
fileset = pkgs.lib.fileset.unions [
49+
(pkgs.lib.fileset.fileFilter (
50+
file:
51+
pkgs.lib.any pkgs.lib.id [
52+
(file.name == "Cargo.toml")
53+
(file.hasExt "rs")
54+
(file.hasExt "snap")
55+
]
56+
) root)
57+
(root + "/Cargo.lock")
58+
];
59+
};
60+
cargoLock.lockFile = root + "/Cargo.lock";
61+
RUSTFLAGS = "-D warnings";
62+
nativeBuildInputs = [ pkgs.clippy ];
63+
buildPhase = "cargo clippy --all-targets --all-features";
64+
installPhase = "touch $out";
65+
doCheck = false;
66+
};
67+
};
768
};
869
}

flake.lock

Lines changed: 17 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
{
22
nixConfig = {
33
abort-on-warn = true;
4-
allow-import-from-derivation = false;
54
};
65

76
inputs = {
@@ -10,6 +9,10 @@
109
inputs.nixpkgs-lib.follows = "nixpkgs";
1110
};
1211

12+
crate2nix = {
13+
url = "github:nix-community/crate2nix";
14+
flake = false;
15+
};
1316
import-tree = {
1417
url = "github:denful/import-tree";
1518
flake = false;

overlay.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
final: prev: {
22
statix = prev.callPackage ./packages/statix.nix { };
3+
statix-workspace = prev.callPackage ./packages/statix-workspace.nix { };
34
statix-vim = prev.callPackage ./packages/statix-vim.nix { };
45
}

packages/statix-workspace.nix

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
{
2+
lib,
3+
callPackage,
4+
crate2nixTools,
5+
}:
6+
let
7+
cargoNix = crate2nixTools.generatedCargoNix {
8+
name = "statix";
9+
src = lib.fileset.toSource {
10+
root = ../.;
11+
fileset = lib.fileset.unions [
12+
(lib.fileset.fileFilter (
13+
file:
14+
lib.any lib.id [
15+
(file.name == "Cargo.toml")
16+
(file.hasExt "rs")
17+
(file.hasExt "snap")
18+
]
19+
) ../.)
20+
../Cargo.lock
21+
../insta.yaml
22+
];
23+
};
24+
};
25+
in
26+
callPackage cargoNix { }

packages/statix.nix

Lines changed: 22 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,26 @@
11
{
2-
rustPlatform,
32
lib,
4-
clippy,
3+
callPackage,
4+
crate2nixTools,
55
}:
6-
rustPlatform.buildRustPackage {
7-
pname = "statix";
8-
version = "0.6.0-git";
9-
src = lib.fileset.toSource {
10-
root = ../.;
11-
fileset = lib.fileset.unions [
12-
(lib.fileset.fileFilter (
13-
file:
14-
lib.any lib.id [
15-
(file.name == "Cargo.toml")
16-
(file.hasExt "rs")
17-
(file.hasExt "snap")
18-
]
19-
) ../.)
20-
../Cargo.lock
21-
../insta.yaml
22-
];
6+
let
7+
cargoNix = crate2nixTools.generatedCargoNix {
8+
name = "statix";
9+
src = lib.fileset.toSource {
10+
root = ../.;
11+
fileset = lib.fileset.unions [
12+
(lib.fileset.fileFilter (
13+
file:
14+
lib.any lib.id [
15+
(file.name == "Cargo.toml")
16+
(file.hasExt "rs")
17+
(file.hasExt "snap")
18+
]
19+
) ../.)
20+
../Cargo.lock
21+
../insta.yaml
22+
];
23+
};
2324
};
24-
RUSTFLAGS = "-D warnings";
25-
26-
nativeBuildInputs = [ clippy ];
27-
28-
checkPhase = ''
29-
runHook preCheck
30-
31-
cargo clippy --all-targets --all-features
32-
cargoCheckHook
33-
34-
runHook postCheck
35-
'';
36-
37-
cargoLock.lockFile = ../Cargo.lock;
38-
meta = {
39-
mainProgram = "statix";
40-
description = "Lints and suggestions for the Nix programming language";
41-
homepage = "https://github.com/molybdenumsoftware/statix";
42-
license = lib.licenses.mit;
43-
};
44-
}
25+
in
26+
(callPackage cargoNix { }).workspaceMembers.statix.build

0 commit comments

Comments
 (0)