From 71d82b482f6a79799a5989c3923a47d8dc11e5b3 Mon Sep 17 00:00:00 2001 From: srdtrk <59252793+srdtrk@users.noreply.github.com> Date: Wed, 27 Nov 2024 19:57:23 +0800 Subject: [PATCH] deps: switch from nix-shell to nix flakes (#124) --- README.md | 2 +- flake.lock | 214 +++++++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 66 +++++++++++++++++ shell.nix | 34 --------- 4 files changed, 281 insertions(+), 35 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 shell.nix diff --git a/README.md b/README.md index 9e819e93..ce4e3351 100644 --- a/README.md +++ b/README.md @@ -60,7 +60,7 @@ just install-operator > Nix users can enter a development shell with all the necessary dependencies by running: > > ```sh -> nix-shell shell.nix +> nix develop > ``` ## Unit Testing diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..ce8e8070 --- /dev/null +++ b/flake.lock @@ -0,0 +1,214 @@ +{ + "nodes": { + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_2": { + "locked": { + "lastModified": 1644229661, + "narHash": "sha256-1YdnJAsNy69bpcjuoKdOYQX0YxZBiCYZo4Twxerqv7k=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "3cecb5b042f7f209c56ffd8371b2711a290ec797", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "flake-utils_3": { + "inputs": { + "systems": "systems_2" + }, + "locked": { + "lastModified": 1731533236, + "narHash": "sha256-l0KFg5HjrsfsO/JpG+r7fRrqm12kzFHyUHqHCVpMMbI=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "11707dc2f618dd54ca8739b309ec4fc024de578b", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "foundry": { + "inputs": { + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1732698617, + "narHash": "sha256-1t7qoI66D0f7+2psofZM+CPMolTfEYgZHEyI5qETeAY=", + "owner": "shazow", + "repo": "foundry.nix", + "rev": "1c29834d607abd7e302483c01b56cd58d0b0c797", + "type": "github" + }, + "original": { + "owner": "shazow", + "ref": "main", + "repo": "foundry.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1666753130, + "narHash": "sha256-Wff1dGPFSneXJLI2c0kkdWTgxnQ416KE6X4KnFkgPYQ=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "f540aeda6f677354f1e7144ab04352f61aaa0118", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "type": "indirect" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1732521221, + "narHash": "sha256-2ThgXBUXAE1oFsVATK1ZX9IjPcS4nKFOAjhPNKuiMn0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "4633a7c72337ea8fd23a4f2ba3972865e3ec685d", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { + "locked": { + "lastModified": 1728538411, + "narHash": "sha256-f0SBJz1eZ2yOuKUr5CA9BHULGXVSn6miBuUWdTyhUhU=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b69de56fac8c2b6f8fd27f2eca01dcda8e0a4221", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "foundry": "foundry", + "nixpkgs": "nixpkgs_2", + "rust-overlay": "rust-overlay", + "solc": "solc" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_3" + }, + "locked": { + "lastModified": 1732674798, + "narHash": "sha256-oM1gjCv9R4zxDFO3as9wqQ4FI3+pDA9MKZ72L7tTIII=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "1d569430326b0a7807ccffdb2a188b814091976c", + "type": "github" + }, + "original": { + "owner": "oxalica", + "repo": "rust-overlay", + "type": "github" + } + }, + "solc": { + "inputs": { + "flake-utils": "flake-utils_3", + "nixpkgs": [ + "nixpkgs" + ], + "solc-macos-amd64-list-json": "solc-macos-amd64-list-json" + }, + "locked": { + "lastModified": 1731758759, + "narHash": "sha256-NX4+V6Q8bwopah0oza/Dpf6UsYNGbokW2kE9qT3wdHY=", + "owner": "hellwolf", + "repo": "solc.nix", + "rev": "0714c24cd521b9eb3ee435818c5d743ac6179176", + "type": "github" + }, + "original": { + "owner": "hellwolf", + "repo": "solc.nix", + "type": "github" + } + }, + "solc-macos-amd64-list-json": { + "flake": false, + "locked": { + "narHash": "sha256-KBEEpcDeKtVvCeguRP0D499yg9O5Jef9Nxn3yfrmw9g=", + "type": "file", + "url": "https://github.com/ethereum/solc-bin/raw/67f45d8/macosx-amd64/list.json" + }, + "original": { + "type": "file", + "url": "https://github.com/ethereum/solc-bin/raw/67f45d8/macosx-amd64/list.json" + } + }, + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..1a1ea550 --- /dev/null +++ b/flake.nix @@ -0,0 +1,66 @@ +{ + description = "Development environment for the sp1 tendermint light client"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + + solc = { + url = "github:hellwolf/solc.nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + foundry.url = "github:shazow/foundry.nix/main"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = inputs: inputs.flake-utils.lib.eachSystem + [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ] + ( + system: + let + pkgs = import inputs.nixpkgs { + inherit system; + overlays = [ + (import inputs.rust-overlay) + inputs.foundry.overlay + inputs.solc.overlay + ]; + }; + in + { + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + openssl + openssl.dev + pkg-config + foundry-bin + go-ethereum + solc_0_8_28 + (inputs.solc.mkDefault pkgs solc_0_8_28) + bun + just + golangci-lint + go + jq + parallel + rust-bin.stable.latest.default + protobuf + buf + protoc-gen-go + protoc-gen-go-grpc + ]; + + NIX_LD_LIBRARY_PATH = with pkgs.buildPackages; lib.makeLibraryPath [ + stdenv.cc.cc + ]; + + shellHook = '' + if [ -z "$(which cargo-prove)" ]; then + echo "SP1 toolchain is not installed. This is recommended to generate risc-v elfs. To install, please follow the instructions at" + echo "https://docs.succinct.xyz/getting-started/install.html" + fi + ''; + }; + } + ); +} diff --git a/shell.nix b/shell.nix deleted file mode 100644 index 9b4bdf60..000000000 --- a/shell.nix +++ /dev/null @@ -1,34 +0,0 @@ -{ pkgs ? import {}, lib ? pkgs.lib, stdenv ? pkgs.stdenv }: -let - unstable = import - (builtins.fetchTarball https://github.com/nixos/nixpkgs/tarball/ccc0c2126893dd20963580b6478d1a10a4512185) - # reuse the current configuration - { config = pkgs.config; }; -in - pkgs.mkShell { - # nativeBuildInputs is usually what you want -- tools you need to run - nativeBuildInputs = with pkgs.buildPackages; [ - openssl openssl.dev pkg-config - solc-select unstable.bun go-ethereum - unstable.golangci-lint unstable.go - rustup just jq - ]; - NIX_LD_LIBRARY_PATH = with pkgs.buildPackages; lib.makeLibraryPath [ - stdenv.cc.cc - ]; - NIX_LD = lib.fileContents "${stdenv.cc}/nix-support/dynamic-linker"; - # Run a command after entering the shell - shellHook = '' - echo "Entering shell with solc 0.8.28" - solc-select use 0.8.28 - echo "Entering shell with nightly rust" - rustup override set nightly-2024-10-11 - # Check if tool is installed - if [ -z "$(which cargo-prove)" ]; then - echo "SP1 toolchain is not installed. Please follow the instructions at" - echo "https://docs.succinct.xyz/getting-started/install.html" - else - echo "SP1 toolchain is already installed." - fi - ''; -}