diff --git a/.envrc b/.envrc new file mode 100644 index 0000000..c4b17d7 --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use_flake diff --git a/.gitignore b/.gitignore index 36c509b..3b807f6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target old/ result +.direnv/ diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml deleted file mode 100644 index b538481..0000000 --- a/.pre-commit-config.yaml +++ /dev/null @@ -1,16 +0,0 @@ -repos: - - repo: https://github.com/pre-commit/pre-commit-hooks - rev: v4.5.0 - hooks: - - id: trailing-whitespace - - id: end-of-file-fixer - - id: check-yaml - - id: check-toml - - id: check-merge-conflict - - - repo: https://github.com/doublify/pre-commit-rust - rev: v1.0 - hooks: - - id: fmt - - id: cargo-check - - id: clippy diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 120000 index 0000000..7851a79 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1 @@ +/nix/store/s2x590z57dj3v8kyhncxdys8xi6szp44-pre-commit-config.json \ No newline at end of file diff --git a/flake.lock b/flake.lock index 44e0a6a..68da8ed 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1747046372, + "narHash": "sha256-CIVLLkVgvHYbgI2UpXvIIBJ12HWgX+fjA8Xf8PUmqCY=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "9100a0f413b0c601e0533d1d94ffd501ce2e7885", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, "flake-utils": { "inputs": { "systems": "systems" @@ -18,6 +34,27 @@ "type": "github" } }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1709087332, + "narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "637db329424fd7e46cf4185293b9cc8c88c95394", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1760878510, @@ -50,10 +87,33 @@ "type": "github" } }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1760663237, + "narHash": "sha256-BflA6U4AM1bzuRMR8QqzPXqh8sWVCNDzOdsxXEguJIc=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ca5b894d3e3e151ffc1db040b6ce4dcc75d31c37", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { "flake-utils": "flake-utils", "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", "rust-overlay": "rust-overlay" } }, diff --git a/flake.nix b/flake.nix index 77743ab..70b7d6d 100644 --- a/flake.nix +++ b/flake.nix @@ -5,39 +5,75 @@ nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; flake-utils.url = "github:numtide/flake-utils"; rust-overlay.url = "github:oxalica/rust-overlay"; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; }; - outputs = { self, nixpkgs, flake-utils, rust-overlay }: - flake-utils.lib.eachDefaultSystem (system: + outputs = + { + self, + nixpkgs, + flake-utils, + rust-overlay, + pre-commit-hooks, + }: + flake-utils.lib.eachDefaultSystem ( + system: let - overlays = [ (import rust-overlay )]; + overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; rustToolchain = pkgs.rust-bin.nightly.latest.default.override { - extensions = [ "rust-src" "rust-analyzer" ]; + extensions = [ + "rust-src" + "rust-analyzer" + ]; + }; + formatter = + let + pkgs = nixpkgs.legacyPackages.${system}; + in + pkgs.nixfmt-rfc-style; + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + statix.enable = false; + nixfmt-rfc-style.enable = true; + }; + }; }; in { devShells.default = pkgs.mkShell { + inherit (self.checks.${system}.pre-commit-check) shellHook; + NIX_CONFIG = "experimental-features = nix-command flakes"; buildInputs = with pkgs; [ rustToolchain pkg-config ]; }; - packages.default = (pkgs.makeRustPlatform { - cargo = rustToolchain; - rustc = rustToolchain; - }).buildRustPackage { - pname = "timedctl"; - version = "0.1.0"; - src = ./.; - cargoLock.lockFile = ./Cargo.lock; + packages.default = + (pkgs.makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }).buildRustPackage + { + pname = "timedctl"; + version = "0.1.0"; + src = ./.; + cargoLock.lockFile = ./Cargo.lock; - nativeBuildInputs = [ pkgs.pkg-config ]; - # buildInputs = [ pkgs.openssl ]; - }; + nativeBuildInputs = [ pkgs.pkg-config ]; + # buildInputs = [ pkgs.openssl ]; + }; + + formatter = formatter; + checks = checks; } ); }