various fixs to oizys-go

This commit is contained in:
Daylin Morgan 2024-05-05 17:10:01 -05:00
parent 41cfd7b141
commit 7b6cdedcd1
Signed by: daylin
GPG Key ID: 950D13E9719334AD
9 changed files with 35 additions and 25 deletions

View File

@ -5,16 +5,15 @@ import (
"oizys/pkg/oizys" "oizys/pkg/oizys"
) )
var bootCmd = &cobra.Command{ var bootCmd = &cobra.Command{
Use: "boot", Use: "boot",
Short: "nixos rebuild boot", Short: "nixos rebuild boot",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake)
oizys.NixosRebuild("boot", flake) oizys.NixosRebuild("boot", flake)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(bootCmd) rootCmd.AddCommand(bootCmd)
} }

View File

@ -5,17 +5,15 @@ import (
"oizys/pkg/oizys" "oizys/pkg/oizys"
) )
var buildCmd = &cobra.Command{ var buildCmd = &cobra.Command{
Use: "build", Use: "build",
Short: "A brief description of your command", Short: "A brief description of your command",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake)
oizys.NixBuild(oizys.Output(flake, host), args...) oizys.NixBuild(oizys.Output(flake, host), args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(buildCmd) rootCmd.AddCommand(buildCmd)
} }

View File

@ -9,6 +9,7 @@ var cacheCmd = &cobra.Command{
Use: "cache", Use: "cache",
Short: "build and push to cachix", Short: "build and push to cachix",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake)
oizys.CacheBuild(oizys.Output(flake, host), cacheName, args...) oizys.CacheBuild(oizys.Output(flake, host), cacheName, args...)
}, },
} }
@ -16,10 +17,10 @@ var cacheCmd = &cobra.Command{
func init() { func init() {
cacheCmd.Flags().StringVarP( cacheCmd.Flags().StringVarP(
&cacheName, &cacheName,
"cache", "cache",
"c", "c",
"daylin", "daylin",
"name of cachix binary cache", "name of cachix binary cache",
) )
rootCmd.AddCommand(cacheCmd) rootCmd.AddCommand(cacheCmd)
} }

View File

@ -1,19 +1,20 @@
package cmd package cmd
import ( import (
"oizys/pkg/oizys"
"github.com/spf13/cobra" "github.com/spf13/cobra"
"oizys/pkg/oizys"
) )
var dryCmd = &cobra.Command{ var dryCmd = &cobra.Command{
Use: "dry", Use: "dry",
Short: "poor man's nix flake check", Short: "poor man's nix flake check",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake)
oizys.NixDryRun(oizys.Output(flake, host)) oizys.NixDryRun(oizys.Output(flake, host))
}, },
} }
func init() { func init() {
rootCmd.AddCommand(dryCmd) rootCmd.AddCommand(dryCmd)
} }

View File

@ -7,15 +7,15 @@ import (
"oizys/pkg/oizys" "oizys/pkg/oizys"
) )
var outputCmd = &cobra.Command{ var outputCmd = &cobra.Command{
Use: "output", Use: "output",
Short: "show nixosConfiguration attr", Short: "show nixosConfiguration attr",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake)
fmt.Println(oizys.Output(flake, host)) fmt.Println(oizys.Output(flake, host))
}, },
} }
func init() { func init() {
rootCmd.AddCommand(outputCmd) rootCmd.AddCommand(outputCmd)
} }

View File

@ -1,9 +1,7 @@
package cmd package cmd
import ( import (
"errors"
"fmt" "fmt"
"io/fs"
"log" "log"
"os" "os"
@ -21,10 +19,6 @@ func setFlake() {
flake = oizysDir flake = oizysDir
} }
} }
if _, err := os.Stat(flake); errors.Is(err, fs.ErrNotExist) {
log.Fatalln("path to flake:", flake, "does not exist")
}
} }
func setHost() { func setHost() {
@ -69,7 +63,6 @@ var rootCmd = &cobra.Command{
}, },
} }
func init() { func init() {
rootCmd.CompletionOptions.HiddenDefaultCmd = true rootCmd.CompletionOptions.HiddenDefaultCmd = true
rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)") rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)")

View File

@ -9,11 +9,11 @@ var switchCmd = &cobra.Command{
Use: "switch", Use: "switch",
Short: "nixos rebuild switch", Short: "nixos rebuild switch",
Run: func(cmd *cobra.Command, args []string) { Run: func(cmd *cobra.Command, args []string) {
oizys.CheckFlake(flake)
oizys.NixosRebuild("switch", flake, args...) oizys.NixosRebuild("switch", flake, args...)
}, },
} }
func init() { func init() {
rootCmd.AddCommand(switchCmd) rootCmd.AddCommand(switchCmd)
} }

View File

@ -1,6 +1,9 @@
{ {
installShellFiles,
buildGoModule, buildGoModule,
lib, lib,
...
}: }:
buildGoModule { buildGoModule {
pname = "oizys"; pname = "oizys";
@ -8,4 +11,11 @@ buildGoModule {
src = lib.cleanSource ./.; src = lib.cleanSource ./.;
vendorHash = "sha256-kh/7dV49KaQcD9ho8IpBcRc6+05bn4XpMzAI9JXu7+o="; vendorHash = "sha256-kh/7dV49KaQcD9ho8IpBcRc6+05bn4XpMzAI9JXu7+o=";
nativeBuildInputs = [installShellFiles];
postInstall = ''
installShellCompletion --cmd oizys \
--zsh <($out/bin/oizys completion zsh)
'';
} }

View File

@ -1,7 +1,9 @@
package oizys package oizys
import ( import (
"errors"
"fmt" "fmt"
"io/fs"
"log" "log"
"os" "os"
"os/exec" "os/exec"
@ -108,6 +110,12 @@ func CacheBuild(path string, cache string, rest ...string) {
runCommand(cmd) runCommand(cmd)
} }
func CheckFlake(flake string) {
if _, err := os.Stat(flake); errors.Is(err, fs.ErrNotExist) {
log.Fatalln("path to flake:", flake, "does not exist")
}
}
func Output(flake string, host string) string { func Output(flake string, host string) string {
return fmt.Sprintf( return fmt.Sprintf(
"%s#nixosConfigurations.%s.config.system.build.toplevel", "%s#nixosConfigurations.%s.config.system.build.toplevel",