commit db93b6be6c1ff2bec2fb95949fc6d7ba1767a051 Author: Yonah Date: Sun Jul 13 23:55:04 2025 +0900 format: format nixos installable diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..47c5249 --- /dev/null +++ b/.gitignore @@ -0,0 +1,25 @@ +# Binaries for programs and plugins +*.exe +*.exe~ +*.dll +*.so +*.dylib +*.pkg + +# Test binary, built with `go test -c` +*.test + +# Output of the go coverage tool, specifically when used with LiteIDE +*.out + +# Dependency directories (remove the comment below to include it) +# vendor/ + +# Go workspace file +go.work +go.work.sum + +# env file +.env +.idea +.vscode \ No newline at end of file diff --git a/format.go b/format.go new file mode 100644 index 0000000..860b09d --- /dev/null +++ b/format.go @@ -0,0 +1,9 @@ +package nixbuild + +const ( + nixosSuffix0 = "#nixosConfigurations." + nixosSuffix1 = ".config.system.build.toplevel" +) + +// NixOSInstallable returns the nixos installable for a given flake and host. +func NixOSInstallable(flake, host string) string { return flake + nixosSuffix0 + host + nixosSuffix1 } diff --git a/format_test.go b/format_test.go new file mode 100644 index 0000000..f8bf8ca --- /dev/null +++ b/format_test.go @@ -0,0 +1,24 @@ +package nixbuild_test + +import ( + "testing" + + "git.gensokyo.uk/yonah/nixbuild" +) + +func TestInstallable(t *testing.T) { + testCases := []struct { + name, flake, host, want string + }{ + {"satori", "/var/lib/persist/nixos", "satori", "/var/lib/persist/nixos#nixosConfigurations.satori.config.system.build.toplevel"}, + } + for _, tc := range testCases { + t.Run(tc.name, func(t *testing.T) { + got := nixbuild.NixOSInstallable(tc.flake, tc.host) + if got != tc.want { + t.Errorf("Installable(%q, %q): %q, want %q", + tc.flake, tc.host, got, tc.want) + } + }) + } +} diff --git a/go.mod b/go.mod new file mode 100644 index 0000000..8871f9a --- /dev/null +++ b/go.mod @@ -0,0 +1,3 @@ +module git.gensokyo.uk/yonah/nixbuild + +go 1.24.4