diff --git a/.envrc b/.envrc new file mode 100644 index 00000000000..3550a30f2de --- /dev/null +++ b/.envrc @@ -0,0 +1 @@ +use flake diff --git a/.gitignore b/.gitignore index 4c5bb203190..a9318e63026 100644 --- a/.gitignore +++ b/.gitignore @@ -17,3 +17,4 @@ # VSCode .vscode +/.direnv diff --git a/flake.lock b/flake.lock new file mode 100644 index 00000000000..f419aaf0e9c --- /dev/null +++ b/flake.lock @@ -0,0 +1,184 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1696343447, + "narHash": "sha256-B2xAZKLkkeRFG5XcHHSXXcP7To9Xzr59KXeZiRf4vdQ=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "c9afaba3dfa4085dbd2ccb38dfade5141e33d9d4", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1681202837, + "narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "cfacdce06f30d2b68473a46042957675eebb3401", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1697723726, + "narHash": "sha256-SaTWPkI8a5xSHX/rrKzUe+/uVNy6zCGMXgoeMb7T9rg=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "7c9cc5a6e5d38010801741ac830a3f8fd667a7a0", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1696019113, + "narHash": "sha256-X3+DKYWJm93DRSdC5M6K5hLqzSya9BjibtBsuARoPco=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f5892ddac112a1e9b3612c39af1b72987ee5783a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1681358109, + "narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1695644571, + "narHash": "sha256-asS9dCCdlt1lPq0DLwkVBbVoEKuEuz+Zi3DG7pR/RxA=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "6500b4580c2a1f3d0f980d32d285739d8e156d92", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay", + "systems": "systems_2", + "treefmt-nix": "treefmt-nix" + } + }, + "rust-overlay": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1697940838, + "narHash": "sha256-eyk92QqAoRNC0V99KOcKcBZjLPixxNBS0PRc4KlSQVs=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "a3e829c06eadf848f13d109c7648570ce37ebccd", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "systems_2": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1697388351, + "narHash": "sha256-63N2eBpKaziIy4R44vjpUu8Nz5fCJY7okKrkixvDQmY=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "aae39f64f5ecbe89792d05eacea5cb241891292a", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 00000000000..8bce729ec80 --- /dev/null +++ b/flake.nix @@ -0,0 +1,69 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + systems.url = "github:nix-systems/default"; + rust-overlay.url = "github:oxalica/rust-overlay"; + + # Dev tools + treefmt-nix.url = "github:numtide/treefmt-nix"; + }; + + outputs = inputs: inputs.flake-parts.lib.mkFlake { inherit inputs; } { + systems = import inputs.systems; + imports = [ + inputs.treefmt-nix.flakeModule + ]; + perSystem = { config, self', pkgs, lib, system, rust-overlay, ... }: + let + cargoToml = builtins.fromTOML (builtins.readFile ./Cargo.toml); + nonRustDeps = with pkgs; [ + libclang.lib + libiconv + openssl + protobuf + pkg-config + nodejs + ]; + rustToolchain = (pkgs.rust-bin.fromRustupToolchainFile + ./rust-toolchain.toml); + rustPlatform = pkgs.makeRustPlatform { + rustc = rustToolchain; + cargo = rustToolchain; + }; + in { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ (import inputs.rust-overlay) ]; + }; + + # Rust dev environment + devShells.default = pkgs.mkShell { + inputsFrom = [ + config.treefmt.build.devShell + ]; + shellHook = '' + # For rust-analyzer 'hover' tooltips to work. + export RUST_SRC_PATH=${rustToolchain.availableComponents.rust-src} + export LIBCLANG_PATH=${pkgs.libclang.lib}/lib + export PATH=$PWD/target/release:~/.cargo/bin:$PATH + ''; + buildInputs = nonRustDeps; + nativeBuildInputs = with pkgs; [ + rustToolchain + rust-analyzer + ]; + }; + + # Add your auto-formatters here. + # cf. https://numtide.github.io/treefmt/ + treefmt.config = { + projectRootFile = "flake.nix"; + programs = { + nixpkgs-fmt.enable = true; + rustfmt.enable = true; + }; + }; + }; + }; +} diff --git a/linera-service/src/project.rs b/linera-service/src/project.rs index 7b0b17aae3b..39419782c4e 100644 --- a/linera-service/src/project.rs +++ b/linera-service/src/project.rs @@ -167,11 +167,15 @@ impl Project { } fn create_rust_toolchain(project_root: &Path) -> Result<()> { - let toolchain_path = project_root.join("rust-toolchain"); Self::write_string_to_file( - &toolchain_path, + &project_root.join("rust-toolchain"), include_str!("../template/rust-toolchain.template"), - ) + )?; + Self::write_string_to_file( + &project_root.join("rust-toolchain.toml"), + include_str!("../template/rust-toolchain.toml.template"), + )?; + Ok(()) } fn create_state_file(source_directory: &Path) -> Result<()> { diff --git a/linera-service/template/rust-toolchain.toml.template b/linera-service/template/rust-toolchain.toml.template new file mode 120000 index 00000000000..e01fe10aba9 --- /dev/null +++ b/linera-service/template/rust-toolchain.toml.template @@ -0,0 +1 @@ +../../rust-toolchain.toml \ No newline at end of file diff --git a/rust-toolchain.toml b/rust-toolchain.toml new file mode 100644 index 00000000000..2dc71a0d379 --- /dev/null +++ b/rust-toolchain.toml @@ -0,0 +1,4 @@ +[toolchain] +channel = "1.72.0" +components = [ "rustfmt", "rustc-dev", "rust-src" ] +targets = [ "wasm32-unknown-unknown" ] diff --git a/shell.nix b/shell.nix new file mode 100644 index 00000000000..8745f5026ca --- /dev/null +++ b/shell.nix @@ -0,0 +1 @@ +(builtins.getFlake ("git+file://" + toString ./.)).devShells.${builtins.currentSystem}.default