diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..2601b96 --- /dev/null +++ b/flake.lock @@ -0,0 +1,116 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1656928814, + "narHash": "sha256-RIFfgBuKz6Hp89yRr7+NR5tzIAbn52h8vT6vXkYjZoM=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "7e2a3b3dfd9af950a856d66b0a7d01e3c18aa249", + "type": "github" + }, + "original": { + "owner": "numtide", + "ref": "master", + "repo": "flake-utils", + "type": "github" + } + }, + "naersk": { + "inputs": { + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1655042882, + "narHash": "sha256-9BX8Fuez5YJlN7cdPO63InoyBy7dm3VlJkkmTt6fS1A=", + "owner": "nix-community", + "repo": "naersk", + "rev": "cddffb5aa211f50c4b8750adbec0bbbdfb26bb9f", + "type": "github" + }, + "original": { + "owner": "nix-community", + "ref": "master", + "repo": "naersk", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1657888067, + "narHash": "sha256-GnwJoFBTPfW3+mz7QEeJEEQ9OMHZOiIJ/qDhZxrlKh8=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "65fae659e31098ca4ac825a6fef26d890aaf3f4e", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1656169028, + "narHash": "sha256-y9DRauokIeVHM7d29lwT8A+0YoGUBXV3H0VErxQeA8s=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "db3bd555d3a3ceab208bed48f983ccaa6a71a25e", + "type": "github" + }, + "original": { + "owner": "cachix", + "ref": "master", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "naersk": "naersk", + "nixpkgs": "nixpkgs", + "pre-commit-hooks": "pre-commit-hooks", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1657853760, + "narHash": "sha256-X6ERAyUXGsrhbhgkxNaQl40wcus5uyQZOCxUh5neK+g=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a97a761cc11327bb109dc30af1c637b986be7959", + "type": "github" + }, + "original": { + "owner": "oxalica", + "ref": "master", + "repo": "rust-overlay", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..5767191 --- /dev/null +++ b/flake.nix @@ -0,0 +1,153 @@ +{ + description = "A handy file picker program"; + + inputs = { + flake-utils = { + type = "github"; + owner = "numtide"; + repo = "flake-utils"; + ref = "master"; + }; + + naersk = { + type = "github"; + owner = "nix-community"; + repo = "naersk"; + ref = "master"; + inputs = { + nixpkgs.follows = "nixpkgs"; + }; + }; + + nixpkgs = { + type = "github"; + owner = "NixOS"; + repo = "nixpkgs"; + ref = "nixpkgs-unstable"; + }; + + pre-commit-hooks = { + type = "github"; + owner = "cachix"; + repo = "pre-commit-hooks.nix"; + ref = "master"; + inputs = { + flake-utils.follows = "flake-utils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + + rust-overlay = { + type = "github"; + owner = "oxalica"; + repo = "rust-overlay"; + ref = "master"; + inputs = { + flake-utils.follows = "flake-utils"; + nixpkgs.follows = "nixpkgs"; + }; + }; + }; + + outputs = + { self + , flake-utils + , naersk + , nixpkgs + , pre-commit-hooks + , rust-overlay + }: + let + inherit (flake-utils.lib) eachSystem system; + + mySystems = [ + system.aarch64-linux + system.x86_64-darwin + system.x86_64-linux + ]; + + eachMySystem = eachSystem mySystems; + in + eachMySystem (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit overlays system; }; + my-rust = pkgs.rust-bin.stable.latest.default.override { + extensions = [ "rust-src" ]; + }; + naersk-lib = naersk.lib."${system}".override { + cargo = my-rust; + rustc = my-rust; + }; + inherit (pkgs) lib; + in + rec { + checks = { + pre-commit = + let + # See https://github.com/cachix/pre-commit-hooks.nix/issues/126 + rust-env = pkgs.buildEnv { + name = "rust-env"; + buildInputs = [ pkgs.makeWrapper ]; + paths = [ my-rust ]; + pathsToLink = [ "/" "/bin" ]; + postBuild = '' + for i in $out/bin/*; do + wrapProgram "$i" --prefix PATH : "$out/bin" + done + ''; + }; + in + pre-commit-hooks.lib.${system}.run { + src = self; + + hooks = { + clippy = { + enable = true; + entry = lib.mkForce "${rust-env}/bin/cargo-clippy clippy"; + }; + + nixpkgs-fmt = { + enable = true; + }; + + rustfmt = { + enable = true; + entry = lib.mkForce "${rust-env}/bin/cargo-fmt fmt -- --check --color always"; + }; + }; + }; + }; + + devShells = { + default = pkgs.mkShell { + inputsFrom = [ + packages.seer + ]; + + nativeBuildInputs = with pkgs; [ + rust-analyzer + # Not included in the pre-commit hook unfortunately... + clippy + rustfmt + ]; + + inherit (checks.pre-commit) shellHook; + + RUST_SRC_PATH = "${my-rust}/lib/rustlib/src/rust/library"; + }; + }; + + packages = { + default = self.packages."${system}".seer; + + seer = naersk-lib.buildPackage { + src = self; + + passthru = { + inherit my-rust; + }; + }; + }; + }); +}