From 1d1b084549e33ed21eed1bfd7edcd06acbdfe364 Mon Sep 17 00:00:00 2001 From: Lymah123 Date: Sun, 26 Jul 2026 06:07:56 +0100 Subject: [PATCH] chore: switch to crate2nix --- flake-parts/crate2nix.nix | 10 +++++++ flake-parts/rust.nix | 6 +++-- flake.lock | 17 ++++++++++++ flake.nix | 5 +++- overlay.nix | 2 ++ packages/cargo-nix.nix | 22 ++++++++++++++++ packages/statix-workspace.nix | 5 ++++ packages/statix.nix | 49 +++++++++++------------------------ 8 files changed, 79 insertions(+), 37 deletions(-) create mode 100644 flake-parts/crate2nix.nix create mode 100644 packages/cargo-nix.nix create mode 100644 packages/statix-workspace.nix diff --git a/flake-parts/crate2nix.nix b/flake-parts/crate2nix.nix new file mode 100644 index 00000000..ef7e208c --- /dev/null +++ b/flake-parts/crate2nix.nix @@ -0,0 +1,10 @@ +{ inputs, ... }: +{ + perSystem = _: { + nixpkgs.overlays = [ + (_: prev: { + crate2nixTools = prev.callPackage "${inputs.crate2nix}/tools.nix" { }; + }) + ]; + }; +} diff --git a/flake-parts/rust.nix b/flake-parts/rust.nix index 838cc9f4..7e2553c5 100644 --- a/flake-parts/rust.nix +++ b/flake-parts/rust.nix @@ -1,11 +1,13 @@ -{ +_: { gitignore = [ "/target" ]; perSystem = { pkgs, ... }: { make-shells.default = { - inputsFrom = [ pkgs.statix ]; packages = [ + pkgs.cargo + pkgs.rustc + pkgs.clippy pkgs.bacon pkgs.cargo-insta pkgs.rust-analyzer diff --git a/flake.lock b/flake.lock index 713a0c4c..b4555528 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "crate2nix": { + "flake": false, + "locked": { + "lastModified": 1782759041, + "narHash": "sha256-2577vxyoBa8+ZRiXr3CuPtOuEtPRYsFPSZuEc/KI/80=", + "owner": "nix-community", + "repo": "crate2nix", + "rev": "5e1ecfd2d15b34ec90c2e51fdffbe8116595a767", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "crate2nix", + "type": "github" + } + }, "files": { "flake": false, "locked": { @@ -99,6 +115,7 @@ }, "root": { "inputs": { + "crate2nix": "crate2nix", "files": "files", "flake-parts": "flake-parts", "git-hooks": "git-hooks", diff --git a/flake.nix b/flake.nix index 2759ddd5..1ee50a0d 100644 --- a/flake.nix +++ b/flake.nix @@ -1,7 +1,6 @@ { nixConfig = { abort-on-warn = true; - allow-import-from-derivation = false; }; inputs = { @@ -10,6 +9,10 @@ inputs.nixpkgs-lib.follows = "nixpkgs"; }; + crate2nix = { + url = "github:nix-community/crate2nix"; + flake = false; + }; import-tree = { url = "github:denful/import-tree"; flake = false; diff --git a/overlay.nix b/overlay.nix index 784e7a69..edf71270 100644 --- a/overlay.nix +++ b/overlay.nix @@ -1,4 +1,6 @@ final: prev: { + statix-cargo-nix = prev.callPackage ./packages/cargo-nix.nix { }; statix = prev.callPackage ./packages/statix.nix { }; + statix-workspace = prev.callPackage ./packages/statix-workspace.nix { }; statix-vim = prev.callPackage ./packages/statix-vim.nix { }; } diff --git a/packages/cargo-nix.nix b/packages/cargo-nix.nix new file mode 100644 index 00000000..59633486 --- /dev/null +++ b/packages/cargo-nix.nix @@ -0,0 +1,22 @@ +{ + lib, + crate2nixTools, +}: +crate2nixTools.generatedCargoNix { + name = "statix"; + src = lib.fileset.toSource { + root = ../.; + fileset = lib.fileset.unions [ + (lib.fileset.fileFilter ( + file: + lib.any lib.id [ + (file.name == "Cargo.toml") + (file.hasExt "rs") + (file.hasExt "snap") + ] + ) ../.) + ../Cargo.lock + ../insta.yaml + ]; + }; +} diff --git a/packages/statix-workspace.nix b/packages/statix-workspace.nix new file mode 100644 index 00000000..d92b1ef2 --- /dev/null +++ b/packages/statix-workspace.nix @@ -0,0 +1,5 @@ +{ + callPackage, + statix-cargo-nix, +}: +callPackage statix-cargo-nix { } diff --git a/packages/statix.nix b/packages/statix.nix index e638eff6..e44ded89 100644 --- a/packages/statix.nix +++ b/packages/statix.nix @@ -1,44 +1,25 @@ { - rustPlatform, lib, - clippy, + callPackage, + defaultCrateOverrides, + statix-cargo-nix, }: -rustPlatform.buildRustPackage { - pname = "statix"; - version = "0.6.0-git"; - src = lib.fileset.toSource { - root = ../.; - fileset = lib.fileset.unions [ - (lib.fileset.fileFilter ( - file: - lib.any lib.id [ - (file.name == "Cargo.toml") - (file.hasExt "rs") - (file.hasExt "snap") - ] - ) ../.) - ../Cargo.lock - ../insta.yaml - ]; +let + built = (callPackage statix-cargo-nix { }).workspaceMembers.statix.build.override { + runTests = true; + crateOverrides = defaultCrateOverrides // { + statix = _: { + useClippy = true; + RUSTFLAGS = "-D warnings"; + }; + }; }; - RUSTFLAGS = "-D warnings"; - - nativeBuildInputs = [ clippy ]; - - checkPhase = '' - runHook preCheck - - cargo clippy --all-targets --all-features - cargoCheckHook - - runHook postCheck - ''; - - cargoLock.lockFile = ../Cargo.lock; +in +built.overrideAttrs (_: { meta = { mainProgram = "statix"; description = "Lints and suggestions for the Nix programming language"; homepage = "https://github.com/molybdenumsoftware/statix"; license = lib.licenses.mit; }; -} +})