diff --git a/flake.lock b/flake.lock index 3c0f64a8f..75d63b67e 100644 --- a/flake.lock +++ b/flake.lock @@ -20,22 +20,48 @@ }, "nixpkgs": { "locked": { - "lastModified": 1683594133, - "narHash": "sha256-iUhLhEAgOCnexSGDsYT2ouydis09uDoNzM7UC685XGE=", + "lastModified": 1707689078, + "narHash": "sha256-UUGmRa84ZJHpGZ1WZEBEUOzaPOWG8LZ0yPg1pdDF/yM=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "8d447c5626cfefb9b129d5b30103344377fe09bc", + "rev": "f9d39fb9aff0efee4a3d5f4a6d7c17701d38a1d8", "type": "github" }, "original": { - "id": "nixpkgs", - "type": "indirect" + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" } }, "root": { "inputs": { "flake-utils": "flake-utils", - "nixpkgs": "nixpkgs" + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": [ + "flake-utils" + ], + "nixpkgs": [ + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1707790272, + "narHash": "sha256-KQXPNl3BLdRbz7xx+mwIq/017fxLRk6JhXHxVWCKsTU=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "8dfbe2dffc28c1a18a29ffa34d5d0b269622b158", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" } }, "systems": { diff --git a/flake.nix b/flake.nix index f01107b94..992a1187a 100644 --- a/flake.nix +++ b/flake.nix @@ -2,23 +2,108 @@ description = "The Tokio console: a debugger for async Rust."; inputs = { - # nixpkgs.url = "github:nixos/nixpkgs/release-21.11"; - flake-utils = { - url = "github:numtide/flake-utils"; - inputs.nixpkgs.follows = "nixpkgs"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay = { + url = "github:oxalica/rust-overlay"; + inputs = { + nixpkgs.follows = "nixpkgs"; + flake-utils.follows = "flake-utils"; + }; }; }; - outputs = { self, nixpkgs, flake-utils }: - flake-utils.lib.eachDefaultSystem (system: - let - pkgs = import nixpkgs { inherit system; }; - tokio-console = import ./nix { inherit pkgs; }; - devShell = import ./nix/shell.nix { inherit pkgs; }; - in - { - inherit devShell; - packages = { inherit tokio-console; }; - defaultPackage = tokio-console; - }); + outputs = { self, nixpkgs, flake-utils, rust-overlay }: + flake-utils.lib.eachDefaultSystem + (system: + let + overlays = [ (import rust-overlay) ]; + pkgs = import nixpkgs { inherit system overlays; }; + + #################################################################### + #### tokio-console package #### + #################################################################### + tokio-console = with pkgs; let + inherit (nix-gitignore) gitignoreFilterPure withGitignoreFile; + # Workaround for the builtins.filterSource issue mentioned in + # https://nixos.org/manual/nix/unstable/expressions/builtins.html + # Since this might be built from a flake, the source path may be a store path, + # so we need to provide our own version of gitignoreSource that avoids + # builtins.filterSource in favor of builtins.path. + gitignoreSource = patterns: path: + builtins.path { + filter = + gitignoreFilterPure (_: _: true) (withGitignoreFile patterns path) path; + path = path; + name = "src"; + }; + + # Ignore some extra things that don't factor into the main build to help with + # caching. + extraIgnores = '' + /.envrc + /*.nix + /flake.* + /netlify.toml + /.github + /assets + /*.md + /.gitignore + /LICENSE + ''; + + src = gitignoreSource extraIgnores ./.; + + cargoTOML = lib.importTOML "${src}/tokio-console/Cargo.toml"; + rustToolchain = rust-bin.fromRustupToolchainFile ./rust-toolchain.toml; + rust = makeRustPlatform { + cargo = rustToolchain; + rustc = rustToolchain; + }; + in + rust.buildRustPackage + { + pname = cargoTOML.package.name; + version = cargoTOML.package.version; + + nativeBuildInputs = [ protobuf ]; + + inherit src; + + cargoLock = { lockFile = "${src}/Cargo.lock"; }; + + meta = { + inherit (cargoTOML.package) description homepage license; + maintainers = cargoTOML.package.authors; + }; + }; + + #################################################################### + #### dev shell #### + #################################################################### + devShell = with pkgs; + mkShell { + name = "tokio-console-env"; + buildInputs = tokio-console.buildInputs ++ lib.optional stdenv.isDarwin libiconv; + nativeBuildInputs = tokio-console.nativeBuildInputs; + RUST_SRC_PATH = "${rustPlatform.rustLibSrc}"; + CARGO_TERM_COLOR = "always"; + RUST_BACKTRACE = "full"; + }; + in + { + apps = { + tokio-console = { + type = "app"; + program = "${tokio-console}/bin/tokio-console"; + description = "The Tokio console: a debugger for async Rust."; + }; + default = self.apps.${system}.tokio-console; + }; + devShells.default = devShell; + packages = { + inherit tokio-console; + default = self.packages.${system}.tokio-console; + }; + }); } diff --git a/nix/tokio-console.nix b/nix/tokio-console.nix index bc43123f7..0eabaf9de 100644 --- a/nix/tokio-console.nix +++ b/nix/tokio-console.nix @@ -31,7 +31,8 @@ let src = gitignoreSource extraIgnores ../.; cargoTOML = lib.importTOML "${src}/tokio-console/Cargo.toml"; -in rustPlatform.buildRustPackage rec { +in +rustPlatform.buildRustPackage rec { pname = cargoTOML.package.name; version = cargoTOML.package.version; diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 000000000..4259fa81a --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,3 @@ +[toolchain] +channel = "stable" +profile = "default" \ No newline at end of file