From 6da0fcbb1bd61998860511614b5b6cc32d1aeeea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20Schwarz=C3=A4ugl?= Date: Tue, 31 Dec 2024 17:34:37 +0100 Subject: [PATCH] feat: add go template --- SwarselSystems.org | 5 +++- programs/emacs/init.el | 2 ++ templates/default.nix | 1 + templates/go/.envrc | 1 + templates/go/flake.nix | 52 ++++++++++++++++++++++++++++++++++++++ templates/go/go.mod | 3 +++ templates/go/name/name.go | 9 +++++++ templates/python/flake.nix | 2 +- templates/rust/flake.nix | 3 ++- 9 files changed, 75 insertions(+), 3 deletions(-) create mode 100644 templates/go/.envrc create mode 100644 templates/go/flake.nix create mode 100644 templates/go/go.mod create mode 100644 templates/go/name/name.go diff --git a/SwarselSystems.org b/SwarselSystems.org index eb41150..10d7caa 100644 --- a/SwarselSystems.org +++ b/SwarselSystems.org @@ -116,7 +116,7 @@ These blocks are later inserted here: [[#h:aee5ec75-7ca6-40d8-b6ac-a3e7e33a474b] -** flake.nix template +** flake.nix skeleton :PROPERTIES: :CUSTOM_ID: h:aee5ec75-7ca6-40d8-b6ac-a3e7e33a474b :END: @@ -486,6 +486,7 @@ This file defines the templates that are being exposed by the flake. These can b templateNames = [ "python" "rust" + "go" ]; in lib.swarselsystems.mkTemplates templateNames @@ -13852,6 +13853,8 @@ After having tried out =lsp-mode= and =lsp-bridge= for a while each, I must say c-ts-mode c++-mode c++-ts-mode + go-mode + go-ts-mode rust-ts-mode rustic-mode tex-mode diff --git a/programs/emacs/init.el b/programs/emacs/init.el index 951ea76..cb75a91 100644 --- a/programs/emacs/init.el +++ b/programs/emacs/init.el @@ -1376,6 +1376,8 @@ create a new one." c-ts-mode c++-mode c++-ts-mode + go-mode + go-ts-mode rust-ts-mode rustic-mode tex-mode diff --git a/templates/default.nix b/templates/default.nix index b56a596..1eaff7b 100644 --- a/templates/default.nix +++ b/templates/default.nix @@ -3,6 +3,7 @@ let templateNames = [ "python" "rust" + "go" ]; in lib.swarselsystems.mkTemplates templateNames diff --git a/templates/go/.envrc b/templates/go/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/templates/go/.envrc @@ -0,0 +1 @@ +use flake diff --git a/templates/go/flake.nix b/templates/go/flake.nix new file mode 100644 index 0000000..c1b2888 --- /dev/null +++ b/templates/go/flake.nix @@ -0,0 +1,52 @@ +# heavily inspired by https://github.com/nulladmin1/nix-flake-templates/blob/main/go-nix/flake.nix +{ + description = "Go Flake"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + systems.url = "github:nix-systems/default"; + }; + + outputs = + { self + , nixpkgs + , systems + , ... + }: + let + forEachSystem = nixpkgs.lib.genAttrs (import systems); + pkgsFor = forEachSystem (system: import nixpkgs { inherit system; }); + + pname = "name"; + in + { + formatter = forEachSystem (system: pkgsFor.${system}.nixpkgs-fmt); + + devShells = forEachSystem (system: { + default = pkgsFor.${system}.mkShell { + packages = with pkgsFor.${system}; [ + go + gopls + go-tools + gotools + ]; + }; + }); + + packages = forEachSystem (system: { + default = pkgsFor.${system}.buildGoModule { + inherit pname; + version = "0.1.0"; + src = ./.; + vendorHash = null; + }; + }); + + apps = forEachSystem (system: { + default = { + type = "app"; + program = "${self.packages.${system}.default}/bin/${pname}"; + }; + }); + }; +} diff --git a/templates/go/go.mod b/templates/go/go.mod new file mode 100644 index 0000000..5840ae0 --- /dev/null +++ b/templates/go/go.mod @@ -0,0 +1,3 @@ +module name + +go 1.22.7 diff --git a/templates/go/name/name.go b/templates/go/name/name.go new file mode 100644 index 0000000..2ca0d5e --- /dev/null +++ b/templates/go/name/name.go @@ -0,0 +1,9 @@ +package main + +import ( + "fmt" +) + +func main() { + fmt.Println("Hello, World!") +} diff --git a/templates/python/flake.nix b/templates/python/flake.nix index a117c7a..3384af5 100644 --- a/templates/python/flake.nix +++ b/templates/python/flake.nix @@ -1,7 +1,7 @@ # based on https://github.com/pyproject-nix/uv2nix/tree/master/templates/hello-world { - description = "Hello world flake using uv2nix"; + description = "Python flake using uv2nix"; inputs = { nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; diff --git a/templates/rust/flake.nix b/templates/rust/flake.nix index 97dcb9a..415d1c2 100644 --- a/templates/rust/flake.nix +++ b/templates/rust/flake.nix @@ -1,5 +1,6 @@ +# heavily inspired by https://github.com/nulladmin1/nix-flake-templates/blob/main/rust-fenix-naersk/flake.nix { - description = "Nix Flake Template for Rust using Fenix and Naersk"; + description = "Rust Flake using Fenix and Naersk"; inputs = { nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";