aboutsummaryrefslogtreecommitdiff
path: root/templates/go/flake.nix
diff options
context:
space:
mode:
authorFranck Cuny <franck@fcuny.net>2023-02-21 12:55:28 -0800
committerFranck Cuny <franck@fcuny.net>2023-02-21 12:59:13 -0800
commitd6971f6d7a03142ea6e391d7c37532b3aa4792e7 (patch)
treef60d9d3fcdd37075bc81b9a1116afa7ce74d286d /templates/go/flake.nix
parentfeat(home/fish): move fish's code to external files (diff)
downloadinfra-d6971f6d7a03142ea6e391d7c37532b3aa4792e7.tar.gz
feat(templates/go): add flake template for go projects
Diffstat (limited to 'templates/go/flake.nix')
-rw-r--r--templates/go/flake.nix83
1 files changed, 83 insertions, 0 deletions
diff --git a/templates/go/flake.nix b/templates/go/flake.nix
new file mode 100644
index 0000000..9038975
--- /dev/null
+++ b/templates/go/flake.nix
@@ -0,0 +1,83 @@
+{
+ description = "Go project template";
+
+ inputs = {
+ futils.url = "github:numtide/flake-utils";
+ nixpkgs.url = "github:NixOS/nixpkgs";
+ pre-commit-hooks = {
+ url = "github:cachix/pre-commit-hooks.nix";
+ inputs = {
+ flake-utils.follows = "futils";
+ nixpkgs.follows = "nixpkgs";
+ };
+ };
+ };
+
+ outputs =
+ { self
+ , futils
+ , nixpkgs
+ , pre-commit-hooks
+ }:
+ futils.lib.eachDefaultSystem
+ (system:
+ let
+ pkgs = import nixpkgs {
+ inherit system;
+ };
+ pname = "project-name";
+ version = "0.0.1";
+ tools = with pkgs; [
+ # https://github.com/golang/vscode-go/blob/master/docs/tools.md
+ delve
+ golangci-lint
+ gopls
+ ];
+ in
+ rec {
+ # `nix build`
+ packages."${pname}" = pkgs.buildGoModule {
+ inherit pname version;
+ src = ./.;
+ vendorSha256 = null;
+ };
+ defaultPackage = packages."${pname}";
+
+ # `nix run`
+ apps = {
+ "${pname}" = futils.lib.mkApp {
+ drv = packages."${pname}";
+ exePath = "/bin/changeme";
+ };
+ default = apps."${pname}";
+ };
+
+ # `nix develop`
+ checks = {
+ pre-commit = pre-commit-hooks.lib.${system}.run {
+ src = ./.;
+ hooks = {
+ nixpkgs-fmt.enable = true;
+ yamllint.enable = true;
+ govet.enable = true;
+ gotest.enable = true;
+ gofmt.enable = true;
+ staticcheck.enable = true;
+ };
+ settings = {
+ yamllint.relaxed = true;
+ };
+ };
+ };
+
+ devShell = pkgs.mkShell {
+ buildInputs = with pkgs; [ go ] ++ tools;
+ inherit (self.checks.${system}.pre-commit) shellHook;
+ };
+ })
+ // {
+ overlay = final: prev: {
+ XXX = self.defaultPackage.${prev.system};
+ };
+ };
+}