From 4742cb276de7f435e37073a0ba742f2ac781b577 Mon Sep 17 00:00:00 2001 From: Ganesha Danu Enastika Date: Mon, 4 Mar 2024 11:26:08 +0700 Subject: [PATCH] feat(go): add go-swagger devShell (#20) * update go flake for current efishery workflow - pin and add specific go-swagger fork - expose GOPATH * separate shell for go swagger use * remove duplicate package * use go packages binary on exporting env --- README.md | 12 +++++------ go/flake.lock | 17 +++++++++++++++ go/flake.nix | 57 +++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 78 insertions(+), 8 deletions(-) diff --git a/README.md b/README.md index de939c7..18d33dc 100644 --- a/README.md +++ b/README.md @@ -48,12 +48,12 @@ In this section is require nix installed in your system, here steps to install: > available templates or development environments. -| NAME | Lang/Framework/Tools | -| ------------- | ------------- | -| [node](./node) | `nodejs@v18`, `yarn@1.22`, `pnpm@7` | -| [node14](./node14) | `nodejs@v14`, `yarn@1.22`, `pnpm@5` | -| [go](./go) | `go@v1.19`, `gotools`, `golangci-lint` | -| [react-native](./react-native) | [See Details](./react-native/flake.nix#L192-L212) | +| NAME | Lang/Framework/Tools | +| ------------- | ------------- | +| [node](./node) | `nodejs@v18`, `yarn@1.22`, `pnpm@7` | +| [node14](./node14) | `nodejs@v14`, `yarn@1.22`, `pnpm@5` | +| [go](./go) | `go@v1.21`, `gotools`, `golangci-lint`, `go-swagger-0.3` | +| [react-native](./react-native) | [See Details](./react-native/flake.nix#L192-L212) | * using as development environment: `nix develop "github:efishery/dvt?dir="` diff --git a/go/flake.lock b/go/flake.lock index 467de30..036d56f 100644 --- a/go/flake.lock +++ b/go/flake.lock @@ -1,5 +1,21 @@ { "nodes": { + "go-swagger": { + "flake": false, + "locked": { + "lastModified": 1690583297, + "narHash": "sha256-wrFGi94Qw1EP/a5sQvsTTq127GhzNAQaVJNzwMU/baw=", + "owner": "MAAF72", + "repo": "go-swagger", + "rev": "d2a9e58c6d7693a3b70785cfc81c9d92f4baf095", + "type": "github" + }, + "original": { + "owner": "MAAF72", + "repo": "go-swagger", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1702272962, @@ -18,6 +34,7 @@ }, "root": { "inputs": { + "go-swagger": "go-swagger", "nixpkgs": "nixpkgs", "utils": "utils" } diff --git a/go/flake.nix b/go/flake.nix index 8bb4104..ebe6dc3 100644 --- a/go/flake.nix +++ b/go/flake.nix @@ -4,9 +4,14 @@ inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; utils.url = "github:numtide/flake-utils"; + + go-swagger = { + url = "github:MAAF72/go-swagger"; + flake = false; + }; }; - outputs = { self, nixpkgs, utils }: + outputs = { self, nixpkgs, utils, go-swagger }: utils.lib.eachDefaultSystem (system: let @@ -14,8 +19,40 @@ overlays = [ (final: prev: { go = prev."go_1_${toString goVersion}"; }) ]; pkgs = import nixpkgs { inherit overlays system; }; + # common dependency + + # custom fork of swagger used by efishery + # due to its ability to add custom tag on generated code + # the nix package did not expose any param to override + # thus we make a separate package for this flake + # ref: https://github.com/NixOS/nixpkgs/blob/nixos-23.11/pkgs/development/tools/go-swagger/default.nix + maaf72-go-swagger = with pkgs; buildGoModule rec { + pname = "go-swagger-custom"; + version = "0.30.6-maaf72.1"; + + src = go-swagger; + + doCheck = false; + subPackages = [ "cmd/swagger" ]; + ldflags = [ + "-s" + "-w" + "-X github.com/MAAF72/go-swagger/cmd/swagger/commands.Version=${version}" + "-X github.com/MAAF72/go-swagger/cmd/swagger/commands.Commit=${src.rev}" + ]; + + + vendorHash = "sha256-TqoTzxPGF0BBUfLtYWkljRcmr08m4zo5iroWMklxL7U="; + + + meta = with nixpkgs.lib;{ + homepage = "https://github.com/MAAF72/go-swagger"; + license = licenses.asl20; # apache license 2.0 + maintainers = with maintainers; [ MAAF72 ]; + }; + }; in - { + rec { devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ # go 1.21 (specified by overlay) @@ -32,8 +69,24 @@ ]; shellHook = '' + # allow for external dependency to be + # install on nix os imperatively + # using `go install` when certain + # dependencies not available/outdated + # on nixpkgs + export GOPATH="$(${pkgs.go}/bin/go env GOPATH)" + export PATH="$PATH:$GOPATH/bin" + ${pkgs.go}/bin/go version ''; }; + + devShells.go-swagger = pkgs.mkShell { + buildInputs = [ + maaf72-go-swagger + ] ++ devShells.default.buildInputs; + + shellHook = devShells.default.shellHook; + }; }); }