Skip to content

Commit

Permalink
Merge pull request #100 from akirak/go
Browse files Browse the repository at this point in the history
Add Go
  • Loading branch information
akirak authored Oct 5, 2024
2 parents b870177 + 54d2ead commit b4a1afa
Show file tree
Hide file tree
Showing 5 changed files with 131 additions and 0 deletions.
33 changes: 33 additions & 0 deletions .github/workflows/check-go.yml
Original file line number Diff line number Diff line change
@@ -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
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down
62 changes: 62 additions & 0 deletions go/flake.nix
Original file line number Diff line number Diff line change
@@ -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;
});
};
}
20 changes: 20 additions & 0 deletions go/treefmt.nix
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit b4a1afa

Please sign in to comment.