From 172aed43dc6731c56427a2a5dd135428cd0d2659 Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Sat, 5 Oct 2024 14:02:53 +0900 Subject: [PATCH 1/3] feat: Add go --- flake.nix | 4 ++++ go/flake.nix | 62 ++++++++++++++++++++++++++++++++++++++++++++++++++ go/treefmt.nix | 20 ++++++++++++++++ 3 files changed, 86 insertions(+) create mode 100644 go/flake.nix create mode 100644 go/treefmt.nix diff --git a/flake.nix b/flake.nix index 4d2cb97..027fece 100644 --- a/flake.nix +++ b/flake.nix @@ -29,6 +29,10 @@ path = ./node-typescript; description = "Toolchain for TypeScript frontend projects"; }; + go = { + path = ./go; + description = "A minimal environment for Go with support for Go module"; + }; ocaml = { path = ./ocaml; description = "A flake template for development with OPAM and Dune"; diff --git a/go/flake.nix b/go/flake.nix new file mode 100644 index 0000000..eea868d --- /dev/null +++ b/go/flake.nix @@ -0,0 +1,62 @@ +{ + inputs = { + # nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; + systems.url = "github:nix-systems/default"; + treefmt-nix = { + url = "github:numtide/treefmt-nix"; + inputs.nixpkgs.follows = "nixpkgs"; + }; + }; + + # Configure a binary cache for your executable(s). + nixConfig = { + extra-substituters = + [ + ]; + extra-trusted-public-keys = + [ + ]; + }; + + outputs = + { + self, + systems, + nixpkgs, + treefmt-nix, + ... + }: + let + inherit (nixpkgs) lib; + eachSystem = f: lib.genAttrs (import systems) (system: f nixpkgs.legacyPackages.${system}); + + treefmtEval = eachSystem (pkgs: treefmt-nix.lib.evalModule pkgs ./treefmt.nix); + in + { + # Build executables. See https://nixos.org/manual/nixpkgs/stable/#sec-language-go + packages = eachSystem (pkgs: { + # default = pkgs.buildGoModule { + # pname = "squasher"; + # version = builtins.substring 0 8 (self.lastModifiedDate or "19700101"); + # src = self.outPath; + # vendorHash = lib.fakeHash; + # meta = { }; + # }; + }); + + devShells = eachSystem (pkgs: { + default = pkgs.mkShell { + packages = [ + pkgs.go + pkgs.gopls + ]; + }; + }); + + formatter = eachSystem (pkgs: treefmtEval.${pkgs.system}.config.build.wrapper); + + checks = eachSystem (pkgs: { + formatting = treefmtEval.${pkgs.system}.config.build.check self; + }); + }; +} diff --git a/go/treefmt.nix b/go/treefmt.nix new file mode 100644 index 0000000..6d84570 --- /dev/null +++ b/go/treefmt.nix @@ -0,0 +1,20 @@ +{ + projectRootFile = "treefmt.nix"; + + # See https://github.com/numtide/treefmt-nix#supported-programs + + programs.gofmt.enable = true; + + # JSON + programs.biome.enable = true; + + # GitHub Actions + programs.yamlfmt.enable = true; + programs.actionlint.enable = true; + + # Markdown + programs.mdformat.enable = true; + + # Nix + programs.nixfmt.enable = true; +} From d9b7acfc0a7884c66707afe506064ce351d80c4a Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Sat, 5 Oct 2024 14:04:32 +0900 Subject: [PATCH 2/3] ci(go): Init --- .github/workflows/check-go.yml | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 .github/workflows/check-go.yml diff --git a/.github/workflows/check-go.yml b/.github/workflows/check-go.yml new file mode 100644 index 0000000..0a0e60f --- /dev/null +++ b/.github/workflows/check-go.yml @@ -0,0 +1,33 @@ +name: Check go +on: + push: + paths: + # Set this to the directory of the template + - go/** + - .github/workflows/check-go.yml + workflow_dispatch: + workflow_call: +concurrency: + group: check-go-${{ github.ref }} + cancel-in-progress: true +jobs: + check: + runs-on: ubuntu-latest + steps: + - uses: cachix/install-nix-action@v30 + with: + extra_nix_config: | + access-tokens = github.com=${{ secrets.GITHUB_TOKEN }} + flake-registry = https://raw.githubusercontent.com/akirak/flake-pins/master/registry.json + - uses: cachix/cachix-action@v15 + with: + name: akirak + authToken: '${{ secrets.CACHIX_AUTH_TOKEN }}' + pushFilter: '-source$' + - uses: actions/checkout@v4 + with: + path: ./tmp + - name: Use the template + run: | + nix flake new -t ./tmp#go work + - run: go version From 54d2ead83027e8457f3353305340b2ac3b0c9ac7 Mon Sep 17 00:00:00 2001 From: Akira Komamura Date: Sat, 5 Oct 2024 14:09:35 +0900 Subject: [PATCH 3/3] docs(readme): Update on adding Go --- README.md | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/README.md b/README.md index 5cd4857..fa952c3 100644 --- a/README.md +++ b/README.md @@ -172,6 +172,18 @@ This flake provides minimal dependencies for [Gleam](https://gleam.run/). nix flake init -t github:akirak/flake-templates#gleam ``` +### [go](go/) + +This flake provides a development environment for [Go](https://go.dev/). + +``` bash +nix flake init -t github:akirak/flake-templates#go +``` + +Note that creating a Go project may require some manual work. This template +helps you start working on an existing Go project on NixOS or adding a Nix-based +CI, but not much more. + ### [meta](meta/) This is a set of common metadata files for GitHub projects, such as