From f2cda20b1e37a74963681349c245e4acdd3736a7 Mon Sep 17 00:00:00 2001 From: yashnevatia Date: Wed, 8 Jan 2025 13:54:00 +0000 Subject: [PATCH] adding dev stuff --- Makefile | 5 +++ flake.lock | 96 ++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 26 ++++++++++++ shell.nix | 116 +++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 243 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 shell.nix diff --git a/Makefile b/Makefile index 851ba45b7..6d0f229b8 100644 --- a/Makefile +++ b/Makefile @@ -1,5 +1,7 @@ TEST_COUNT ?= 10 COVERAGE_FILE ?= coverage.out +export PROJECT_SERUM_VERSION ?=v0.29.0 +export PROJECT_SERUM_IMAGE ?= backpackapp/build:$(PROJECT_SERUM_VERSION) # Detect the system architecture ARCH := $(shell uname -m) @@ -70,3 +72,6 @@ ensure_golangcilint_1_62_2: ensure_protoc_28_0: @$(PROTOC_BIN) --version | grep -q 'libprotoc 28.0' || (echo "Please use protoc 28.0, (make install-protoc)" && exit 1) + +anchor_shell: + docker run --rm -it -v $(shell pwd):/workdir --entrypoint bash ${PROJECT_SERUM_IMAGE} \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..85e72c3d5 --- /dev/null +++ b/flake.lock @@ -0,0 +1,96 @@ +{ + "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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1735471104, + "narHash": "sha256-0q9NGQySwDQc7RhAV2ukfnu7Gxa5/ybJ2ANT8DQrQrs=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "88195a94f390381c6afcdaa933c2f6ff93959cb4", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "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", + "nixpkgs": "nixpkgs", + "rust-overlay": "rust-overlay" + } + }, + "rust-overlay": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1735525800, + "narHash": "sha256-pcN8LAL021zdC99a9F7iEiFCI1wmrE4DpIYUgKpB/jY=", + "owner": "oxalica", + "repo": "rust-overlay", + "rev": "10faa81b4c0135a04716cbd1649260d82b2890cd", + "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" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 000000000..0761c5330 --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "Solana integration"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + rust-overlay.url = "github:oxalica/rust-overlay"; + }; + + outputs = inputs@{ self, nixpkgs, rust-overlay, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: + let + pkgs = import nixpkgs { inherit system; overlays = [ rust-overlay.overlays.default ]; }; + solanaPkgs = pkgs.callPackage ./solana.nix {}; + in rec { + devShells = { + default = pkgs.callPackage ./shell.nix {}; + solana-cli = solanaPkgs.solana-cli-shell; + }; + + packages = { + solana-test-validator = solanaPkgs.solana-test-validator; + solana-cli-env = solanaPkgs.solana-cli-env; + }; + }); +} diff --git a/shell.nix b/shell.nix new file mode 100644 index 000000000..86ba0f9d0 --- /dev/null +++ b/shell.nix @@ -0,0 +1,116 @@ +{ stdenv, pkgs, lib }: +let + version = "v2.0.18"; + getBinDerivation = + { + name, + filename, + sha256, + }: + pkgs.stdenv.mkDerivation rec { + inherit name; + url = "https://github.com/anza-xyz/agave/releases/download/${version}/${filename}"; + src = pkgs.fetchzip { + inherit url sha256; + }; + + installPhase = '' + mkdir -p $out/bin + ls -lah $src + cp -r $src/bin/* $out/bin + ''; + }; + + # It provides two derivations, one for x86_64-linux and another for aarch64-apple-darwin. + # Each derivation downloads the corresponding Solana release. + + # The SHA256 hashes below are automatically updated by action.(dependency-updates.yml) + # The update script(./scripts/update-solana-nix-hashes.sh) looks for the BEGIN and END markers to locate the lines to modify. + # Do not modify these markers or the lines between them manually. + solanaBinaries = { + x86_64-linux = getBinDerivation { + name = "solana-cli-x86_64-linux"; + filename = "solana-release-x86_64-unknown-linux-gnu.tar.bz2"; + ### BEGIN_LINUX_SHA256 ### + sha256 = "sha256-3FW6IMZeDtyU4GTsRIwT9BFLNzLPEuP+oiQdur7P13s="; + ### END_LINUX_SHA256 ### + }; + aarch64-apple-darwin = getBinDerivation { + name = "solana-cli-aarch64-apple-darwin"; + filename = "solana-release-aarch64-apple-darwin.tar.bz2"; + ### BEGIN_DARWIN_SHA256 ### + sha256 = "sha256-6VjycYU0NU0evXoqtGAZMYGHQEKijofnFQnBJNVsb6Q="; + ### END_DARWIN_SHA256 ### + }; + }; +in +pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + (rust-bin.stable.latest.default.override { extensions = ["rust-src"]; }) + # lld_11 + llvm_12 + stdenv.cc.cc.lib + pkg-config + openssl + + # Solana + # solana.solana-full + # spl-token-cli + # anchor + + # Golang + # Keep this golang version in sync with the version in .tool-versions please + go_1_23 + gopls + delve + golangci-lint + gotools + kubernetes-helm + + # NodeJS + TS + nodePackages.typescript + nodePackages.typescript-language-server + nodePackages.npm + nodePackages.pnpm + # Keep this nodejs version in sync with the version in .tool-versions please + nodejs-18_x + (yarn.override { nodejs = nodejs-18_x; }) + python3 + # ] ++ lib.optionals stdenv.isLinux [ + # # ledger specific packages + # libudev-zero + # libusb1 + # ]; + ] ++ pkgs.lib.optionals pkgs.stdenv.isLinux [ + libudev-zero + libusb1 + solanaBinaries.x86_64-linux + ] ++ pkgs.lib.optionals (pkgs.stdenv.isDarwin && pkgs.stdenv.hostPlatform.isAarch64) [ + solanaBinaries.aarch64-apple-darwin + ]; + RUST_BACKTRACE = "1"; + + LD_LIBRARY_PATH = lib.makeLibraryPath [pkgs.zlib stdenv.cc.cc.lib]; # lib64 + + # Avoids issues with delve + CGO_CPPFLAGS="-U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=0"; + + # shellHook = '' + # # install gotestloghelper + # go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@latest + # ''; + shellHook = '' + echo "====================================================" + echo "Welcome to the combined development shell." + echo "Current environment: $(uname -a)" + echo "You are using the package for ${pkgs.stdenv.hostPlatform.system}." + echo "----------------------------------------------------" + echo "Solana CLI information:" + solana --version || echo "Solana CLI not available." + solana config get || echo "Solana config not available." + echo "----------------------------------------------------" + + # Install gotestloghelper + go install github.com/smartcontractkit/chainlink-testing-framework/tools/gotestloghelper@latest + ''; +}