diff --git a/.envrc b/.envrc index e835c4d..b84f4a3 100755 --- a/.envrc +++ b/.envrc @@ -4,4 +4,4 @@ if nix flake metadata &>/dev/null; then use flake else use nix -fi +fi \ No newline at end of file diff --git a/default.nix b/default.nix index a2d59d6..286b3a8 100644 --- a/default.nix +++ b/default.nix @@ -1,16 +1,27 @@ { system ? builtins.currentSystem , inputs ? import ./flake.lock.nix { } +, overlays ? [ (import inputs.rust-overlay) ] , nixpkgs ? import inputs.nixpkgs { - inherit system; + inherit system overlays; # Makes the config pure as well. See /top-level/impure.nix: config = { }; - overlays = [ ]; } -, rustPackages ? nixpkgs.rustPackages +, rustVersion ? nixpkgs.rust-bin.stable."1.63.0".default }: let lib = nixpkgs.lib; + rustVersionExtended = rustVersion.override { + # include source for IDE's and other tools that resolve the source automatically via + # $(rustc --print sysroot)/lib/rustlib/src/rust + extensions = [ "rust-src" "rustfmt" ]; + }; + + rustPlatform = nixpkgs.makeRustPlatform { + cargo = rustVersionExtended; + rustc = rustVersionExtended; + }; + cargoToml = with builtins; (fromTOML (readFile ./Cargo.toml)); # Use the Nix module system to validate the treefmt config file format. @@ -26,7 +37,7 @@ let }; # What is used when invoking `nix run github:numtide/treefmt` - treefmt = rustPackages.rustPlatform.buildRustPackage { + treefmt = rustPlatform.buildRustPackage { inherit (cargoToml.package) name version; src = builtins.path { @@ -63,7 +74,6 @@ let nativeBuildInputs = prev.nativeBuildInputs ++ (with nixpkgs; [ # Build tools - rustPackages.clippy rust-analyzer # Code formatters @@ -76,7 +86,6 @@ let nodePackages.prettier python3.pkgs.black rufo - rustPackages.rustfmt shellcheck shfmt terraform diff --git a/flake.lock b/flake.lock index 99b4bd8..548bcbb 100644 --- a/flake.lock +++ b/flake.lock @@ -20,6 +20,21 @@ "type": "github" } }, + "flake-utils": { + "locked": { + "lastModified": 1659877975, + "narHash": "sha256-zllb8aq3YO3h8B/U0/J1WBgAL8EX5yWf5pMj3G0NAmc=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "c0e246b9b83f637f4681389ecabcb2681b4f3af0", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1663819708, @@ -39,7 +54,29 @@ "root": { "inputs": { "flake-parts": "flake-parts", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1670552927, + "narHash": "sha256-lCE51eAGrAFS4k9W5aDGFpVtOAwQQ/rFMN80PCDh0vo=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a0fdafd18c9cf599fde17fbaf07dbb20fa57eecb", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } } }, diff --git a/flake.nix b/flake.nix index 878f57b..396c112 100644 --- a/flake.nix +++ b/flake.nix @@ -6,15 +6,16 @@ inputs.flake-parts.url = "github:hercules-ci/flake-parts"; inputs.flake-parts.inputs.nixpkgs.follows = "nixpkgs"; - outputs = { self, nixpkgs, flake-parts }@inputs: + inputs.rust-overlay.url = "github:oxalica/rust-overlay"; + inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs"; + + outputs = { self, nixpkgs, flake-parts, rust-overlay }@inputs: flake-parts.lib.mkFlake { inherit self; } { systems = nixpkgs.lib.systems.flakeExposed; perSystem = { system, pkgs, ... }: let packages = import ./. { inherit system; - inputs = null; - nixpkgs = pkgs; }; in {