Skip to content

Commit 2ba8532

Browse files
author
Lymah123
committed
chore: switch to crate2nix
1 parent 64bad2b commit 2ba8532

9 files changed

Lines changed: 92 additions & 38 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: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
1+
{ ... }:
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
11+
pkgs.clippy
912
pkgs.bacon
1013
pkgs.cargo-insta
1114
pkgs.rust-analyzer

flake-parts/statix.nix

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,31 @@
1+
{
2+
root,
3+
...
4+
}:
15
{
26
perSystem =
37
{ pkgs, ... }:
8+
let
9+
statixBuild = pkgs.statix-workspace.workspaceMembers.statix.build;
10+
in
411
{
512
treefmt.settings.global.excludes = [ "bin/tests/data/*.nix" ];
6-
checks.build = pkgs.statix;
13+
checks = {
14+
inherit (pkgs) statix;
15+
statix-tests = statixBuild.override {
16+
runTests = true;
17+
testPreRun = ''
18+
export INSTA_SNAPSHOT_DIR=${root}/bin/tests/snapshots
19+
'';
20+
};
21+
clippy = statixBuild.override {
22+
crateOverrides = pkgs.defaultCrateOverrides // {
23+
statix = _: {
24+
useClippy = true;
25+
RUSTFLAGS = "-D warnings";
26+
};
27+
};
28+
};
29+
};
730
};
831
}

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: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
final: prev: {
2+
statix-cargo-nix = prev.callPackage ./packages/cargo-nix.nix { };
23
statix = prev.callPackage ./packages/statix.nix { };
4+
statix-workspace = prev.callPackage ./packages/statix-workspace.nix { };
35
statix-vim = prev.callPackage ./packages/statix-vim.nix { };
46
}

packages/cargo-nix.nix

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

packages/statix-workspace.nix

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
{
2+
callPackage,
3+
statix-cargo-nix,
4+
}:
5+
callPackage statix-cargo-nix { }

packages/statix.nix

Lines changed: 4 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,44 +1,13 @@
11
{
2-
rustPlatform,
32
lib,
4-
clippy,
3+
callPackage,
4+
statix-cargo-nix,
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-
];
23-
};
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;
6+
(callPackage statix-cargo-nix { }).workspaceMembers.statix.build.overrideAttrs (_: {
387
meta = {
398
mainProgram = "statix";
409
description = "Lints and suggestions for the Nix programming language";
4110
homepage = "https://github.com/molybdenumsoftware/statix";
4211
license = lib.licenses.mit;
4312
};
44-
}
13+
})

0 commit comments

Comments
 (0)