diff --git a/build-configs.yaml b/build-configs.yaml index d3455b5..eeda0a6 100644 --- a/build-configs.yaml +++ b/build-configs.yaml @@ -6,5 +6,3 @@ parameters: cachix: binaryCache: altf4llc-os vendorHash: sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc= - goPackage: go_1_22 - buildGoModule: buildGo122Module diff --git a/flake.nix b/flake.nix index f71315b..e49813b 100644 --- a/flake.nix +++ b/flake.nix @@ -1,44 +1,33 @@ { inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; - outputs = inputs@{ flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ]; + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin"]; - perSystem = { config, pkgs, ... }: - let - inherit (pkgs) - go_1_22 - just; - - name = "build-configs"; - CGO_ENABLED = "0"; - in - { - devShells.default = pkgs.mkShell { - buildInputs = [ just ]; - inputsFrom = [ config.packages.default ]; - }; - - packages = { - default = pkgs.buildGo122Module { - inherit name; - src = ./.; - vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; - buildModules = [ "cmd/${name}" ]; - }; + perSystem = { + config, + pkgs, + ... + }: let + inherit (pkgs) just; + name = "build-configs"; + version = "0.1.0"; + CGO_ENABLED = "0"; + in { + devShells.default = pkgs.mkShell { + buildInputs = [just]; + inputsFrom = [config.packages.default]; + }; - docker = pkgs.dockerTools.buildImage { - inherit name; - tag = "latest"; - config = { - Entrypoint = [ "${config.packages.default}/bin/${name}" ]; - Env = [ - "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" - ]; - }; - }; + packages = { + default = pkgs.buildGoModule { + inherit CGO_ENABLED name version; + src = ./.; + subPackages = ["cmd/${name}"]; + vendorHash = "sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc="; }; }; - }; + }; + }; } diff --git a/internal/config/go_cobra_cli.go b/internal/config/go_cobra_cli.go index b2fb723..b3e55bb 100644 --- a/internal/config/go_cobra_cli.go +++ b/internal/config/go_cobra_cli.go @@ -8,24 +8,26 @@ const GoCobraCliName = "go-cobra-cli" type GoCobraCliConfig struct { Config + CgoEnabled bool `json:"cgoEnabled,omitempty" yaml:"cgoEnabled,omitempty"` GoVersion string `json:"goVersion,omitempty" yaml:"goVersion,omitempty"` Lint GolangCILintConfig `json:"lint,omitempty" yaml:"lint,omitempty"` Nix NixGoConfig `json:"nix,omitempty" yaml:"nix,omitempty"` PrivateModules string `json:"privateModules,omitempty" yaml:"privateModules,omitempty"` + Version string `json:"version,omitempty" yaml:"version,omitempty"` } func NewGoCobraCliConfig(c Config) GoCobraCliConfig { return GoCobraCliConfig{ - Config: c, - - GoVersion: "1.22", - - Lint: NewGolangCiLintConfig(), + CgoEnabled: false, + Config: c, + GoVersion: "1.22", + Lint: NewGolangCiLintConfig(), Nix: NixGoConfig{ - NixConfig: NewNixConfig(), - GoPackage: "go", BuildGoModule: "buildGoModule", + GoPackage: "go", + NixConfig: NewNixConfig(), }, + Version: "0.1.0", } } diff --git a/internal/templates/templates/go-cobra-cli/flake.nix b/internal/templates/templates/go-cobra-cli/flake.nix index 2cb6b5c..51d3788 100644 --- a/internal/templates/templates/go-cobra-cli/flake.nix +++ b/internal/templates/templates/go-cobra-cli/flake.nix @@ -1,44 +1,33 @@ { inputs.nixpkgs.url = "github:nixos/nixpkgs/{{ .Nix.NixpkgsBranch }}"; - outputs = inputs@{ flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ {{range .Nix.Systems}}"{{.}}" {{end}}]; + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = [{{range .Nix.Systems}}"{{.}}" {{end}}]; - perSystem = { config, pkgs, ... }: - let - inherit (pkgs) - {{ .Nix.GoPackage }} - just; - - name = "{{ .Name }}"; - CGO_ENABLED = "0"; - in - { - devShells.default = pkgs.mkShell { - buildInputs = [ just ]; - inputsFrom = [ config.packages.default ]; - }; - - packages = { - default = pkgs.{{ .Nix.BuildGoModule }} { - inherit name; - src = ./.; - vendorHash = "{{ .Nix.VendorHash }}"; - buildModules = [ "cmd/${name}" ]; - }; + perSystem = { + config, + pkgs, + ... + }: let + inherit (pkgs) just; + name = "{{ .Name }}"; + version = "{{ .Version }}"; + {{ if .CgoEnabled }}CGO_ENABLED = "1";{{ else }}CGO_ENABLED = "0";{{ end }} + in { + devShells.default = pkgs.mkShell { + buildInputs = [just]; + inputsFrom = [config.packages.default]; + }; - docker = pkgs.dockerTools.buildImage { - inherit name; - tag = "latest"; - config = { - Entrypoint = [ "${config.packages.default}/bin/${name}" ]; - Env = [ - "SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt" - ]; - }; - }; + packages = { + default = pkgs.{{ .Nix.BuildGoModule }} { + inherit CGO_ENABLED name version; + src = ./.; + subPackages = ["cmd/${name}"]; + vendorHash = "{{ .Nix.VendorHash }}"; }; }; - }; + }; + }; }