mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-12-22 18:30:43 -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,12 +5,11 @@ 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)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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...)
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,15 +1,16 @@
|
||||||
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))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -7,11 +7,11 @@ 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))
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)")
|
||||||
|
|
|
@ -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)
|
||||||
}
|
}
|
||||||
|
|
|
@ -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)
|
||||||
|
'';
|
||||||
}
|
}
|
||||||
|
|
|
@ -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",
|
||||||
|
|
Loading…
Reference in a new issue