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,12 +5,11 @@ 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)
},
}

View file

@ -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)
}

View file

@ -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...)
},
}

View file

@ -1,15 +1,16 @@
package cmd
import (
"oizys/pkg/oizys"
"github.com/spf13/cobra"
"oizys/pkg/oizys"
)
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))
},
}

View file

@ -7,11 +7,11 @@ 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))
},
}

View file

@ -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)")

View file

@ -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)
}

View file

@ -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)
'';
}

View file

@ -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",