commit e1ec9ff94bd322418388dd17f9569196b9f267eb Author: Torjus HÃ¥kestad Date: Sat Oct 12 00:39:09 2024 +0200 Add go template diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..b2be92b --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +result diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..22964f6 --- /dev/null +++ b/flake.nix @@ -0,0 +1,14 @@ +{ + description = "Collection of flake templates"; + + outputs = + { self }: + { + templates = { + go = { + path = ./go; + description = "Go template"; + }; + }; + }; +} diff --git a/go/.envrc b/go/.envrc new file mode 100644 index 0000000..3550a30 --- /dev/null +++ b/go/.envrc @@ -0,0 +1 @@ +use flake diff --git a/go/.gitignore b/go/.gitignore new file mode 100644 index 0000000..2bbdbfe --- /dev/null +++ b/go/.gitignore @@ -0,0 +1,2 @@ +.direnv +result diff --git a/go/flake.lock b/go/flake.lock new file mode 100644 index 0000000..0ce117f --- /dev/null +++ b/go/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1728492678, + "narHash": "sha256-9UTxR8eukdg+XZeHgxW5hQA9fIKHsKCdOIUycTryeVw=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "5633bcff0c6162b9e4b5f1264264611e950c8ec7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/go/flake.nix b/go/flake.nix new file mode 100644 index 0000000..750a2c0 --- /dev/null +++ b/go/flake.nix @@ -0,0 +1,68 @@ +{ + description = "Example go flake"; + + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + + outputs = + { self, nixpkgs }: + let + allSystems = [ + "x86_64-linux" + "aarch64-linux" + "x86_64-darwin" + "aarch64-darwin" + ]; + forAllSystems = + f: + nixpkgs.lib.genAttrs allSystems ( + system: + f { + pkgs = import nixpkgs { inherit system; }; + } + ); + # Gets version from first line containg Version in main.go + version = nixpkgs.lib.strings.removePrefix "v" ( + builtins.elemAt (nixpkgs.lib.strings.split "\"" ( + nixpkgs.lib.lists.findFirst (x: nixpkgs.lib.strings.hasInfix "Version" x) null ( + nixpkgs.lib.strings.splitString "\n" (builtins.readFile ./main.go) + ) + )) 2 + ); + in + { + overlays.default = final: prev: { + ghettoptt = self.packages.${prev.system}.default; + }; + + packages = forAllSystems ( + { pkgs }: + { + default = + let + src = pkgs.lib.sourceFilesBySuffices ./. [ + "go.mod" + "go.sum" + ".go" + ]; + in + pkgs.buildGoModule { + inherit version; + pname = "example-go"; + src = src; + vendorHash = null; + }; + } + ); + devShells = forAllSystems ( + { pkgs }: + { + default = pkgs.mkShell { + buildInputs = with pkgs; [ + go + golangci-lint + ]; + }; + } + ); + }; +} diff --git a/go/go.mod b/go/go.mod new file mode 100644 index 0000000..ccd4f7c --- /dev/null +++ b/go/go.mod @@ -0,0 +1,3 @@ +module git.t-juice.club/torjus/go-example + +go 1.22.7 diff --git a/go/main.go b/go/main.go new file mode 100644 index 0000000..9e509c2 --- /dev/null +++ b/go/main.go @@ -0,0 +1,9 @@ +package main + +import "fmt" + +const Version = "v0.0.1" + +func main() { + fmt.Println("Hello, World!") +}