From 7b6cdedcd14acd86d0ac0d977ce36c73ce8cf973 Mon Sep 17 00:00:00 2001 From: Daylin Morgan Date: Sun, 5 May 2024 17:10:01 -0500 Subject: [PATCH] various fixs to oizys-go --- pkgs/oizys/oizys-go/cmd/boot.go | 5 ++--- pkgs/oizys/oizys-go/cmd/build.go | 6 ++---- pkgs/oizys/oizys-go/cmd/cache.go | 9 +++++---- pkgs/oizys/oizys-go/cmd/dry.go | 7 ++++--- pkgs/oizys/oizys-go/cmd/output.go | 4 ++-- pkgs/oizys/oizys-go/cmd/root.go | 7 ------- pkgs/oizys/oizys-go/cmd/switch.go | 4 ++-- pkgs/oizys/oizys-go/default.nix | 10 ++++++++++ pkgs/oizys/oizys-go/pkg/oizys/oizys.go | 8 ++++++++ 9 files changed, 35 insertions(+), 25 deletions(-) diff --git a/pkgs/oizys/oizys-go/cmd/boot.go b/pkgs/oizys/oizys-go/cmd/boot.go index d3b7ba1..96e0826 100644 --- a/pkgs/oizys/oizys-go/cmd/boot.go +++ b/pkgs/oizys/oizys-go/cmd/boot.go @@ -5,16 +5,15 @@ import ( "oizys/pkg/oizys" ) - - var bootCmd = &cobra.Command{ Use: "boot", Short: "nixos rebuild boot", Run: func(cmd *cobra.Command, args []string) { + oizys.CheckFlake(flake) oizys.NixosRebuild("boot", flake) }, } func init() { - rootCmd.AddCommand(bootCmd) + rootCmd.AddCommand(bootCmd) } diff --git a/pkgs/oizys/oizys-go/cmd/build.go b/pkgs/oizys/oizys-go/cmd/build.go index a7da2f0..7db8b75 100644 --- a/pkgs/oizys/oizys-go/cmd/build.go +++ b/pkgs/oizys/oizys-go/cmd/build.go @@ -5,17 +5,15 @@ import ( "oizys/pkg/oizys" ) - var buildCmd = &cobra.Command{ Use: "build", Short: "A brief description of your command", Run: func(cmd *cobra.Command, args []string) { + oizys.CheckFlake(flake) oizys.NixBuild(oizys.Output(flake, host), args...) }, } - - func init() { - rootCmd.AddCommand(buildCmd) + rootCmd.AddCommand(buildCmd) } diff --git a/pkgs/oizys/oizys-go/cmd/cache.go b/pkgs/oizys/oizys-go/cmd/cache.go index 93a0b87..97891e1 100644 --- a/pkgs/oizys/oizys-go/cmd/cache.go +++ b/pkgs/oizys/oizys-go/cmd/cache.go @@ -9,6 +9,7 @@ var cacheCmd = &cobra.Command{ Use: "cache", Short: "build and push to cachix", Run: func(cmd *cobra.Command, args []string) { + oizys.CheckFlake(flake) oizys.CacheBuild(oizys.Output(flake, host), cacheName, args...) }, } @@ -16,10 +17,10 @@ var cacheCmd = &cobra.Command{ func init() { cacheCmd.Flags().StringVarP( &cacheName, - "cache", - "c", - "daylin", - "name of cachix binary cache", + "cache", + "c", + "daylin", + "name of cachix binary cache", ) rootCmd.AddCommand(cacheCmd) } diff --git a/pkgs/oizys/oizys-go/cmd/dry.go b/pkgs/oizys/oizys-go/cmd/dry.go index 6783d35..1f6ac1d 100644 --- a/pkgs/oizys/oizys-go/cmd/dry.go +++ b/pkgs/oizys/oizys-go/cmd/dry.go @@ -1,19 +1,20 @@ package cmd import ( + "oizys/pkg/oizys" - "github.com/spf13/cobra" - "oizys/pkg/oizys" + "github.com/spf13/cobra" ) var dryCmd = &cobra.Command{ Use: "dry", Short: "poor man's nix flake check", Run: func(cmd *cobra.Command, args []string) { + oizys.CheckFlake(flake) oizys.NixDryRun(oizys.Output(flake, host)) }, } func init() { - rootCmd.AddCommand(dryCmd) + rootCmd.AddCommand(dryCmd) } diff --git a/pkgs/oizys/oizys-go/cmd/output.go b/pkgs/oizys/oizys-go/cmd/output.go index e00c521..c2a74f2 100644 --- a/pkgs/oizys/oizys-go/cmd/output.go +++ b/pkgs/oizys/oizys-go/cmd/output.go @@ -7,15 +7,15 @@ import ( "oizys/pkg/oizys" ) - var outputCmd = &cobra.Command{ Use: "output", Short: "show nixosConfiguration attr", Run: func(cmd *cobra.Command, args []string) { + oizys.CheckFlake(flake) fmt.Println(oizys.Output(flake, host)) }, } func init() { - rootCmd.AddCommand(outputCmd) + rootCmd.AddCommand(outputCmd) } diff --git a/pkgs/oizys/oizys-go/cmd/root.go b/pkgs/oizys/oizys-go/cmd/root.go index b483dff..0d5ee98 100644 --- a/pkgs/oizys/oizys-go/cmd/root.go +++ b/pkgs/oizys/oizys-go/cmd/root.go @@ -1,9 +1,7 @@ package cmd import ( - "errors" "fmt" - "io/fs" "log" "os" @@ -21,10 +19,6 @@ func setFlake() { flake = oizysDir } } - - if _, err := os.Stat(flake); errors.Is(err, fs.ErrNotExist) { - log.Fatalln("path to flake:", flake, "does not exist") - } } func setHost() { @@ -69,7 +63,6 @@ var rootCmd = &cobra.Command{ }, } - func init() { rootCmd.CompletionOptions.HiddenDefaultCmd = true rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)") diff --git a/pkgs/oizys/oizys-go/cmd/switch.go b/pkgs/oizys/oizys-go/cmd/switch.go index 9ccda3c..79e16a0 100644 --- a/pkgs/oizys/oizys-go/cmd/switch.go +++ b/pkgs/oizys/oizys-go/cmd/switch.go @@ -9,11 +9,11 @@ var switchCmd = &cobra.Command{ Use: "switch", Short: "nixos rebuild switch", Run: func(cmd *cobra.Command, args []string) { + oizys.CheckFlake(flake) oizys.NixosRebuild("switch", flake, args...) }, } - func init() { - rootCmd.AddCommand(switchCmd) + rootCmd.AddCommand(switchCmd) } diff --git a/pkgs/oizys/oizys-go/default.nix b/pkgs/oizys/oizys-go/default.nix index 70f3043..1cc1e98 100644 --- a/pkgs/oizys/oizys-go/default.nix +++ b/pkgs/oizys/oizys-go/default.nix @@ -1,6 +1,9 @@ { + + installShellFiles, buildGoModule, lib, + ... }: buildGoModule { pname = "oizys"; @@ -8,4 +11,11 @@ buildGoModule { src = lib.cleanSource ./.; vendorHash = "sha256-kh/7dV49KaQcD9ho8IpBcRc6+05bn4XpMzAI9JXu7+o="; + + nativeBuildInputs = [installShellFiles]; + + postInstall = '' + installShellCompletion --cmd oizys \ + --zsh <($out/bin/oizys completion zsh) + ''; } diff --git a/pkgs/oizys/oizys-go/pkg/oizys/oizys.go b/pkgs/oizys/oizys-go/pkg/oizys/oizys.go index 6b358cd..d905f80 100644 --- a/pkgs/oizys/oizys-go/pkg/oizys/oizys.go +++ b/pkgs/oizys/oizys-go/pkg/oizys/oizys.go @@ -1,7 +1,9 @@ package oizys import ( + "errors" "fmt" + "io/fs" "log" "os" "os/exec" @@ -108,6 +110,12 @@ func CacheBuild(path string, cache string, rest ...string) { 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 { return fmt.Sprintf( "%s#nixosConfigurations.%s.config.system.build.toplevel",