mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-22 14:20:44 -06:00
various fixs to oizys-go
This commit is contained in:
parent
41cfd7b141
commit
7b6cdedcd1
9 changed files with 35 additions and 25 deletions
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)")
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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)
|
||||
'';
|
||||
}
|
||||
|
|
|
@ -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",
|
||||
|
|
Loading…
Reference in a new issue