diff --git a/.gitignore b/.gitignore index 9624092..5a2f515 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ /target .direnv result +/.pre-commit-config.yaml \ No newline at end of file diff --git a/default.nix b/default.nix index 39bacff..89308a3 100644 --- a/default.nix +++ b/default.nix @@ -1,7 +1,10 @@ -(import ( - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; - sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } -) { - src = ./.; -}).defaultNix +(import + ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; + } + ) + { + src = ./.; + }).defaultNix diff --git a/flake.lock b/flake.lock index f98a0a8..39a7c6d 100644 --- a/flake.lock +++ b/flake.lock @@ -1,5 +1,20 @@ { "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1667395993, + "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "naersk": { "inputs": { "nixpkgs": [ @@ -37,18 +52,54 @@ "type": "github" } }, + "nixpkgs_2": { + "locked": { + "lastModified": 1667292599, + "narHash": "sha256-7ISOUI1aj6UKMPIL+wwthENL22L3+A9V+jS8Is3QsRo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ef2f213d9659a274985778bff4ca322f3ef3ac68", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1667992213, + "narHash": "sha256-8Ens8ozllvlaFMCZBxg6S7oUyynYx2v7yleC5M0jJsE=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "ebcbfe09d2bd6d15f68de3a0ebb1e4dcb5cd324b", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, "root": { "inputs": { + "flake-utils": "flake-utils", "naersk": "naersk", "nixpkgs": "nixpkgs", - "rust-overlay": "rust-overlay", - "utils": "utils" + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay" } }, "rust-overlay": { "inputs": { "flake-utils": [ - "utils" + "flake-utils" ], "nixpkgs": [ "nixpkgs" @@ -67,21 +118,6 @@ "repo": "rust-overlay", "type": "github" } - }, - "utils": { - "locked": { - "lastModified": 1667395993, - "narHash": "sha256-nuEHfE/LcWyuSWnS8t12N1wc105Qtau+/OdUAjtQ0rA=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "5aed5285a952e0b949eb3ba02c12fa4fcfef535f", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index 0635c23..e883ac6 100644 --- a/flake.nix +++ b/flake.nix @@ -2,7 +2,7 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; - utils.url = "github:numtide/flake-utils"; + flake-utils.url = "github:numtide/flake-utils"; naersk = { url = "github:nmattia/naersk/master"; inputs.nixpkgs.follows = "nixpkgs"; @@ -10,52 +10,83 @@ rust-overlay = { url = "github:oxalica/rust-overlay"; inputs.nixpkgs.follows = "nixpkgs"; - inputs.flake-utils.follows = "utils"; + inputs.flake-utils.follows = "flake-utils"; + }; + pre-commit-hooks = { + url = "github:cachix/pre-commit-hooks.nix"; + inputs.flake-utils.follows = "flake-utils"; }; }; - outputs = { self, nixpkgs, utils, naersk, rust-overlay }: - utils.lib.eachDefaultSystem (system: + outputs = { self, nixpkgs, flake-utils, naersk, rust-overlay, pre-commit-hooks }: + flake-utils.lib.eachDefaultSystem (system: let overlays = [ (import rust-overlay) ]; pkgs = import nixpkgs { inherit system overlays; }; naersk-lib = pkgs.callPackage naersk { }; rustToolchain = - (pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml); + pkgs.rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; - buildInputs = [ - rustToolchain - pkgs.openssl - ]; - nativeBuildInputs = [ - pkgs.pkgconf - ]; in - rec { - packages.ha-now-playing = (naersk-lib.override { - cargo = rustToolchain; - rustc = rustToolchain; - }).buildPackage - { - inherit buildInputs nativeBuildInputs; - pname = "ha-now-playing"; - root = ./.; + { + formatter = pkgs.nixpkgs-fmt; - }; - packages.default = packages.ha-now-playing; + packages = { + ha-now-playing = (naersk-lib.override { + cargo = rustToolchain; + rustc = rustToolchain; + }).buildPackage + { + pname = "ha-now-playing"; + root = ./.; - apps.ha-now-playing = utils.lib.mkApp { - drv = self.defaultPackage."${system}"; + buildInputs = with pkgs; [ + rustToolchain + openssl + ]; + nativeBuildInputs = with pkgs; [ + pkgconf + cargo-edit + cargo-expand + cargo-diet + cargo-feature + cargo-outdated + rust-analyzer + pre-commit + jq + gitflow + yaml-language-server + ]; + }; }; - apps.default = apps.ha-now-playing; + packages.default = self.packages.${system}.ha-now-playing; - overlays = final: prev: { - ha-now-playing = packages.ha-now-playing; + apps.ha-now-playing = flake-utils.lib.mkApp { + drv = self.packages.${system}.default; + }; + apps.default = self.apps.${system}.ha-now-playing; + + overlays = _final: _prev: { + inherit (self.packages.${system}) ha-now-playing; + }; + + checks = { + pre-commit-check = pre-commit-hooks.lib.${system}.run { + src = ./.; + hooks = { + nixpkgs-fmt.enable = true; + statix.enable = true; + deadnix.enable = true; + clippy.enable = true; + }; + }; }; devShells.default = with pkgs; mkShell { - inherit buildInputs; - nativeBuildInputs = [ cargo-edit cargo-expand cargo-diet cargo-feature cargo-outdated rust-analyzer pre-commit jq gitflow ] ++ nativeBuildInputs; + inherit (self.checks.${system}.pre-commit-check) shellHook; + + name = "ha-now-playing"; + inputsFrom = [ self.packages.${system}.ha-now-playing ]; }; }); diff --git a/shell.nix b/shell.nix index 77db547..47458ad 100644 --- a/shell.nix +++ b/shell.nix @@ -1,7 +1,10 @@ -(import ( - fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; - sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; } -) { - src = ./.; -}).shellNix +(import + ( + fetchTarball { + url = "https://github.com/edolstra/flake-compat/archive/99f1c2157fba4bfe6211a321fd0ee43199025dbf.tar.gz"; + sha256 = "0x2jn3vrawwv9xp15674wjz9pixwjyj3j771izayl962zziivbx2"; + } + ) + { + src = ./.; + }).shellNix