Skip to content

Commit

Permalink
refactor: update build configurations and flake.nix for Go module
Browse files Browse the repository at this point in the history
- Removed `goPackage` and `buildGoModule` parameters from `build-configs.yaml`.
- Updated `flake.nix` to use `buildGoModule` instead of `buildGo122Module`.
- Added `version` and `CgoEnabled` fields to `GoCobraCliConfig` in `go_cobra_cli.go`.
- Updated `internal/templates/templates/go-cobra-cli/flake.nix` to include `version` and `CgoEnabled` fields.
  • Loading branch information
erikreinert committed Jul 13, 2024
1 parent 18e0491 commit a85aa33
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 81 deletions.
2 changes: 0 additions & 2 deletions build-configs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,3 @@ parameters:
cachix:
binaryCache: altf4llc-os
vendorHash: sha256-6B9O6ho4COpJy4HlkzQ0lk+ieezRO3xg9LyLHzoxYzc=
goPackage: go_1_22
buildGoModule: buildGo122Module
61 changes: 25 additions & 36 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -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=";
};
};
};
};
};
}
16 changes: 9 additions & 7 deletions internal/config/go_cobra_cli.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
}
}

Expand Down
61 changes: 25 additions & 36 deletions internal/templates/templates/go-cobra-cli/flake.nix
Original file line number Diff line number Diff line change
@@ -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 }}";
};
};
};
};
};
}

0 comments on commit a85aa33

Please sign in to comment.