From 23c2665fce3028ba0f905cdccb7e4513804aeaf0 Mon Sep 17 00:00:00 2001 From: Anatolii Smolianinov Date: Thu, 6 Mar 2025 17:07:31 +0100 Subject: [PATCH] add a sample flake.nix - takes protoc-gen-gogofaster from anyproto, marshall-append - drpc is already turned into flake by drpc author, just take the flake with the same version from go.mod --- .gitignore | 4 + Makefile | 5 +- flake.lock | 126 ++++++++++++++++++++++++++++++ flake.nix | 35 +++++++++ nix/any-protoc-gen-gogofaster.nix | 15 ++++ 5 files changed, 182 insertions(+), 3 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 nix/any-protoc-gen-gogofaster.nix diff --git a/.gitignore b/.gitignore index b71fe51b0..58fd9283f 100644 --- a/.gitignore +++ b/.gitignore @@ -32,3 +32,7 @@ db # Dependency directories (remove the comment below to include it) # vendor/ + +# Add "use flake" in .envrc to get shell automatically with direnv+nix +/.envrc +/.direnv/ diff --git a/Makefile b/Makefile index 5df578db8..47690c3d3 100644 --- a/Makefile +++ b/Makefile @@ -1,6 +1,5 @@ .PHONY: proto test deps mocks export GOPRIVATE=github.com/anyproto -export PATH:=deps:$(PATH) all: @set -e; @@ -35,7 +34,7 @@ proto-execute: mocks: echo 'Generating mocks...' go build -o deps go.uber.org/mock/mockgen - PATH=$(CURDIR)/deps:$(PATH) go generate ./... + go generate ./... deps: go mod download @@ -47,4 +46,4 @@ test: replace-gogo-strings: @echo "Replacing 'github.com/gogo/protobuf' with 'github.com/anyproto/protobuf' in all files recursively..." - LC_CTYPE=C LANG=C find . -type f -name "*.go" | xargs sed -i '' "s|github.com/gogo/protobuf|github.com/anyproto/protobuf|g" + LC_CTYPE=C LANG=C find . -type f -name "*.go" | xargs sed -i "s|github.com/gogo/protobuf|github.com/anyproto/protobuf|g" diff --git a/flake.lock b/flake.lock new file mode 100644 index 000000000..6dd6e2273 --- /dev/null +++ b/flake.lock @@ -0,0 +1,126 @@ +{ + "nodes": { + "drpc": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + }, + "locked": { + "lastModified": 1710270657, + "narHash": "sha256-hjb+8iB0HTdAYtsOvr6gY2yhwdg2NLUqQRVJi4qMmJI=", + "owner": "storj", + "repo": "drpc", + "rev": "a5d487af8ae33deb7913b0f7c06b2c7ec7cd4dcc", + "type": "github" + }, + "original": { + "owner": "storj", + "ref": "v0.0.34", + "repo": "drpc", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1710146030, + "narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=", + "rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a", + "revCount": 92, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/numtide/flake-utils/0.1.92%2Brev-b1d9ab70662946ef0850d488da1c9019f3a9752a/018e2ca5-e5a2-7f80-9261-445a8cecd4d7/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/numtide/flake-utils/%2A.tar.gz" + } + }, + "flake-utils_2": { + "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" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710162809, + "narHash": "sha256-i2R2bcnQp+85de67yjgZVvJhd6rRnJbSYNpGmB6Leb8=", + "rev": "ddcd7598b2184008c97e6c9c6a21c5f37590b8d2", + "revCount": 556648, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.2311.556648%2Brev-ddcd7598b2184008c97e6c9c6a21c5f37590b8d2/018e3162-e13b-7219-a0b5-da03bcc09ecc/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/%2A.tar.gz" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1741173522, + "narHash": "sha256-k7VSqvv0r1r53nUI/IfPHCppkUAddeXn843YlAC5DR0=", + "rev": "d69ab0d71b22fa1ce3dbeff666e6deb4917db049", + "revCount": 762848, + "type": "tarball", + "url": "https://api.flakehub.com/f/pinned/NixOS/nixpkgs/0.1.762848%2Brev-d69ab0d71b22fa1ce3dbeff666e6deb4917db049/0195698a-02df-791f-8cd3-d10c16d442f0/source.tar.gz" + }, + "original": { + "type": "tarball", + "url": "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz" + } + }, + "root": { + "inputs": { + "drpc": "drpc", + "flake-utils": "flake-utils_2", + "nixpkgs": "nixpkgs_2" + } + }, + "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..5f525689a --- /dev/null +++ b/flake.nix @@ -0,0 +1,35 @@ +{ + description = ""; + inputs.nixpkgs.url = "https://flakehub.com/f/NixOS/nixpkgs/0.1.0.tar.gz"; + inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.drpc.url = "github:storj/drpc/v0.0.34"; + + outputs = { self, nixpkgs, drpc, flake-utils, ... }: + flake-utils.lib.eachDefaultSystem (system: let + pkgs = import nixpkgs { + inherit system; + config = { allowUnfree = true; }; + }; + + any-protoc-gen-gogofaster = pkgs.callPackage ./nix/any-protoc-gen-gogofaster.nix {}; + protoc-gen-go-drpc = drpc.defaultPackage.${system}; + in { + devShell = pkgs.mkShell { + name = "any-sync"; + nativeBuildInputs = [ + # our forked proto generator + any-protoc-gen-gogofaster + + # drpc generator + protoc-gen-go-drpc + + pkgs.go_1_23 + # pkgs.gox + pkgs.protobuf3_21 + pkgs.pkg-config + pkgs.pre-commit + # todo: govvv, not packaged + ]; + }; + }); +} diff --git a/nix/any-protoc-gen-gogofaster.nix b/nix/any-protoc-gen-gogofaster.nix new file mode 100644 index 000000000..ce907639e --- /dev/null +++ b/nix/any-protoc-gen-gogofaster.nix @@ -0,0 +1,15 @@ +{ pkgs ? import {} }: +pkgs.buildGoModule rec { + pname = "protoc-gen-gogofaster"; + name = pname; + src = pkgs.fetchFromGitHub { + owner = "anyproto"; + repo = "protobuf"; + rev = "marshal-append"; + hash = "sha256-TetJNcPn0/2Dym/JOLczGax4BEnsLKvJtTZIv1mTMdc="; + }; + + vendorHash = "sha256-nOL2Ulo9VlOHAqJgZuHl7fGjz/WFAaWPdemplbQWcak="; + + doCheck = false; +}