Skip to content

Commit

Permalink
feat(go): add go-swagger devShell (#20)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
BlinfoldKing authored Mar 4, 2024
1 parent 3121922 commit 4742cb2
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 8 deletions.
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`, `[email protected]`, `pnpm@7` |
| [node14](./node14) | `nodejs@v14`, `[email protected]`, `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`, `[email protected]`, `pnpm@7` |
| [node14](./node14) | `nodejs@v14`, `[email protected]`, `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=<NAME>"`

Expand Down
17 changes: 17 additions & 0 deletions go/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

57 changes: 55 additions & 2 deletions go/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,55 @@
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
goVersion = 21;
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)
Expand All @@ -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;
};
});
}

0 comments on commit 4742cb2

Please sign in to comment.