Skip to content

Commit

Permalink
feat: add flake.nix file to consume gt via nix (#161)
Browse files Browse the repository at this point in the history
  • Loading branch information
brumhard committed Oct 29, 2022
1 parent 32514c2 commit f41c052
Show file tree
Hide file tree
Showing 5 changed files with 225 additions and 0 deletions.
1 change: 1 addition & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ run: fmt ## Run a controller from your host
generate: ## Generates files
@go run cmd/dotembed/main.go -target _template -o embed_gen.go -pkg gotemplate -var FS
@go run cmd/options2md/main.go -o docs/options.md
@go run github.com/nix-community/gomod2nix@latest --outdir nix

GOLANGCI_LINT = bin/golangci-lint-$(GOLANGCI_VERSION)
$(GOLANGCI_LINT):
Expand Down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ go install github.com/schwarzit/go-template/cmd/gt@latest
Download the desired version for your operating system and processor architecture from the [go-template releases page](https://github.com/SchwarzIT/go-template/releases).
Make the file executable and place it in a directory available in your `$PATH`.

#### nix

`go-template` also provides a [flake.nix](flake.nix) to install it via [nix package manager](https://github.com/NixOS/nix).

You can also try out `go-template` without installing:

```shell
nix run github:schwarzit/go-template
```

### Preconditions

`go/template`'s `gt` CLI requires at least the following executables on `$PATH` to run succesfully:
Expand Down
93 changes: 93 additions & 0 deletions flake.lock

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

43 changes: 43 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{
inputs = {
nixpkgs.url = "github:nixos/nixpkgs";
flake-utils.url = "github:numtide/flake-utils";
gomod2nix.url = "github:nix-community/gomod2nix";
};

outputs = { self, nixpkgs, flake-utils, gomod2nix }:
flake-utils.lib.eachDefaultSystem (system:
let
name = "go-template";
pkgs = import nixpkgs {
inherit system;
overlays = [ gomod2nix.overlays.default ];
};
in
rec {
packages = {
default = packages.${name};
${name} = pkgs.buildGoApplication {
pname = name;
version = pkgs.lib.removeSuffix "\n" (builtins.readFile ./config/version.txt);
src = ./.;
modules = ./nix/gomod2nix.toml;
subPackages = [ "cmd/gt" ];
ldflags = [ "-s" "-w" ];
meta = with pkgs.lib; {
description = "go/template is a tool for jumpstarting production-ready Golang projects quickly.";
homepage = "https://github.com/schwarzit/go-template";
maintainers = with maintainers; [ brumhard ];
license = licenses.asl20; # Apache License 2.0
};
};
};

apps = {
default = flake-utils.lib.mkApp {
drv = packages.default;
exePath = "/bin/gt";
};
};
});
}
78 changes: 78 additions & 0 deletions nix/gomod2nix.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
schema = 3

[mod]
[mod."github.com/Masterminds/goutils"]
version = "v1.1.1"
hash = "sha256-MEvA5e099GUllILa5EXxa6toQexU1sz6eDZt2tiqpCY="
[mod."github.com/Masterminds/semver/v3"]
version = "v3.1.1"
hash = "sha256-6AbVa1URv04zlxUZA/Wc484EzrzgAuPcuub3WFBRWDc="
[mod."github.com/Masterminds/sprig/v3"]
version = "v3.2.2"
hash = "sha256-XXDG2ImEqg+TbrXBNYAXaqeV0H/nsNRfijqctCv8y3E="
[mod."github.com/davecgh/go-spew"]
version = "v1.1.1"
hash = "sha256-nhzSUrE1fCkN0+RL04N4h8jWmRFPPPWbCuDc7Ss0akI="
[mod."github.com/fatih/color"]
version = "v1.13.0"
hash = "sha256-Xo0zFKLm/9NuChdHDhHoUFo8Oa7Mkb3ezZCu23SfOAk="
[mod."github.com/google/go-github/v39"]
version = "v39.2.0"
hash = "sha256-rzMQo5Cnmky9zehUDaGrG2nL25hAd55jJe/efay04CM="
[mod."github.com/google/go-querystring"]
version = "v1.1.0"
hash = "sha256-itsKgKghuX26czU79cK6C2n+lc27jm5Dw1XbIRgwZJY="
[mod."github.com/google/uuid"]
version = "v1.3.0"
hash = "sha256-QoR55eBtA94T2tBszyxfDtO7/pjZZSGb5vm7U0Xhs0Y="
[mod."github.com/huandu/xstrings"]
version = "v1.3.2"
hash = "sha256-ueAZrYRXMdRpeTKct3Yxa5YXkCZEoUHpNQs7wLLJil8="
[mod."github.com/imdario/mergo"]
version = "v0.3.12"
hash = "sha256-IPGunEznxlUilS22LUU4p/QTA7f5+Goowf1Utg9ARpc="
[mod."github.com/inconshreveable/mousetrap"]
version = "v1.0.0"
hash = "sha256-ogTuLrV40FwS4ueo4hh6hi1wPywOI+LyIqfNjsibwNY="
[mod."github.com/mattn/go-colorable"]
version = "v0.1.12"
hash = "sha256-Y1vCt0ShrCz4wSmwsppCfeLPLKrWusc2zM2lUFwDMyI="
[mod."github.com/mattn/go-isatty"]
version = "v0.0.14"
hash = "sha256-e8zn5eCVh/B1HOP1PGXeXH0bGkIV0vKYP9KLwZni5as="
[mod."github.com/mitchellh/copystructure"]
version = "v1.2.0"
hash = "sha256-VR9cPZvyW62IHXgmMw8ee+hBDThzd2vftgPksQYR/Mc="
[mod."github.com/mitchellh/reflectwalk"]
version = "v1.0.2"
hash = "sha256-VX9DPqChm7jPnyrA3RAYgxAFrAhj7TRKIWD/qR9Zr9s="
[mod."github.com/pkg/errors"]
version = "v0.9.1"
hash = "sha256-mNfQtcrQmu3sNg/7IwiieKWOgFQOVVe2yXgKBpe/wZw="
[mod."github.com/pmezard/go-difflib"]
version = "v1.0.0"
hash = "sha256-/FtmHnaGjdvEIKAJtrUfEhV7EVo5A/eYrtdnUkuxLDA="
[mod."github.com/shopspring/decimal"]
version = "v1.2.0"
hash = "sha256-f4Sk7p3S4ClpJN9sfm5MOJhWftcXrGgpX2ArRLt8TBg="
[mod."github.com/spf13/cast"]
version = "v1.4.1"
hash = "sha256-jaY+/RKUviKnE2h8Ly5cdZYinSE0uc32FW6+xfZ1Ghs="
[mod."github.com/spf13/cobra"]
version = "v1.5.0"
hash = "sha256-rcyHWrxshA5DVpxrSba5X4NjppqOGrJ64QkUKKnfW2E="
[mod."github.com/spf13/pflag"]
version = "v1.0.5"
hash = "sha256-w9LLYzxxP74WHT4ouBspH/iQZXjuAh2WQCHsuvyEjAw="
[mod."github.com/stretchr/testify"]
version = "v1.8.0"
hash = "sha256-LDxBAebK+A06y4vbH7cd1sVBOameIY81Xm8/9OPZh7o="
[mod."golang.org/x/crypto"]
version = "v0.0.0-20210915214749-c084706c2272"
hash = "sha256-xJkNphIlSfFUXryOK1Tom9GQIZrOzoG7Qq6ScKxV70Q="
[mod."golang.org/x/sys"]
version = "v0.0.0-20211205182925-97ca703d548d"
hash = "sha256-hGalTJfPEB6kjkKTTnPLPpsZ/L+meujDHlm54bIP9qE="
[mod."gopkg.in/yaml.v3"]
version = "v3.0.1"
hash = "sha256-FqL9TKYJ0XkNwJFnq9j0VvJ5ZUU1RvH/52h/f5bkYAU="

0 comments on commit f41c052

Please sign in to comment.