mirror of
https://github.com/daylinmorgan/oizys.git
synced 2024-11-09 20:33:15 -06:00
Compare commits
2 commits
128ddc47a9
...
52d79fd28c
Author | SHA1 | Date | |
---|---|---|---|
52d79fd28c | |||
20810ca4ba |
5 changed files with 52 additions and 39 deletions
|
@ -5,6 +5,7 @@ import (
|
|||
|
||||
o "oizys/internal/oizys"
|
||||
|
||||
"github.com/charmbracelet/log"
|
||||
cc "github.com/ivanpirog/coloredcobra"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
@ -41,12 +42,27 @@ var rootCmd = &cobra.Command{
|
|||
Use: "oizys",
|
||||
Short: "nix begat oizys",
|
||||
PersistentPreRun: func(cmd *cobra.Command, args []string) {
|
||||
if verbose {
|
||||
log.Info("running with verbose mode")
|
||||
log.SetLevel(log.DebugLevel)
|
||||
}
|
||||
oizys.Set(flake, host, cacheName, verbose, systemPath)
|
||||
oizys.CheckFlake()
|
||||
},
|
||||
}
|
||||
|
||||
func setupLogger() {
|
||||
log.SetReportTimestamp(false)
|
||||
styles := log.DefaultStyles()
|
||||
for k, v := range styles.Levels {
|
||||
styles.Levels[k] = v.MaxWidth(10)
|
||||
}
|
||||
log.SetStyles(styles)
|
||||
}
|
||||
|
||||
func init() {
|
||||
setupLogger()
|
||||
|
||||
rootCmd.CompletionOptions.HiddenDefaultCmd = true
|
||||
rootCmd.PersistentFlags().StringVar(&flake, "flake", "", "path to flake ($OIZYS_DIR or $HOME/oizys)")
|
||||
rootCmd.PersistentFlags().StringVar(&host, "host", "", "host to build (current host)")
|
||||
|
|
|
@ -16,7 +16,7 @@ buildGoModule {
|
|||
version = "d${mkDate self.lastModifiedDate}";
|
||||
|
||||
src = cleanSource ./.;
|
||||
vendorHash = "sha256-Geqcp0/7I1IF2IfaYyIChz7SOCF+elIEdcz2VsAU0hQ=";
|
||||
vendorHash = "sha256-/JVXhXrU2np/ty7AGFy+LPZCo1NaLYl9NAyD9+FJYBI=";
|
||||
|
||||
nativeBuildInputs = [
|
||||
installShellFiles
|
||||
|
|
|
@ -5,6 +5,7 @@ go 1.22.2
|
|||
require (
|
||||
github.com/briandowns/spinner v1.23.0
|
||||
github.com/charmbracelet/lipgloss v0.11.0
|
||||
github.com/charmbracelet/log v0.4.0
|
||||
github.com/ivanpirog/coloredcobra v1.0.1
|
||||
github.com/spf13/cobra v1.8.0
|
||||
golang.org/x/term v0.21.0
|
||||
|
@ -14,6 +15,7 @@ require (
|
|||
github.com/aymanbagabas/go-osc52/v2 v2.0.1 // indirect
|
||||
github.com/charmbracelet/x/ansi v0.1.2 // indirect
|
||||
github.com/fatih/color v1.17.0 // indirect
|
||||
github.com/go-logfmt/logfmt v0.6.0 // indirect
|
||||
github.com/inconshreveable/mousetrap v1.1.0 // indirect
|
||||
github.com/lucasb-eyer/go-colorful v1.2.0 // indirect
|
||||
github.com/mattn/go-colorable v0.1.13 // indirect
|
||||
|
@ -22,5 +24,6 @@ require (
|
|||
github.com/muesli/termenv v0.15.2 // indirect
|
||||
github.com/rivo/uniseg v0.4.7 // indirect
|
||||
github.com/spf13/pflag v1.0.5 // indirect
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d // indirect
|
||||
golang.org/x/sys v0.21.0 // indirect
|
||||
)
|
||||
|
|
|
@ -4,15 +4,19 @@ github.com/briandowns/spinner v1.23.0 h1:alDF2guRWqa/FOZZYWjlMIx2L6H0wyewPxo/CH4
|
|||
github.com/briandowns/spinner v1.23.0/go.mod h1:rPG4gmXeN3wQV/TsAY4w8lPdIM6RX3yqeBQJSrbXjuE=
|
||||
github.com/charmbracelet/lipgloss v0.11.0 h1:UoAcbQ6Qml8hDwSWs0Y1cB5TEQuZkDPH/ZqwWWYTG4g=
|
||||
github.com/charmbracelet/lipgloss v0.11.0/go.mod h1:1UdRTH9gYgpcdNN5oBtjbu/IzNKtzVtb7sqN1t9LNn8=
|
||||
github.com/charmbracelet/log v0.4.0 h1:G9bQAcx8rWA2T3pWvx7YtPTPwgqpk7D68BX21IRW8ZM=
|
||||
github.com/charmbracelet/log v0.4.0/go.mod h1:63bXt/djrizTec0l11H20t8FDSvA4CRZJ1KH22MdptM=
|
||||
github.com/charmbracelet/x/ansi v0.1.2 h1:6+LR39uG8DE6zAmbu023YlqjJHkYXDF1z36ZwzO4xZY=
|
||||
github.com/charmbracelet/x/ansi v0.1.2/go.mod h1:dk73KoMTT5AX5BsX0KrqhsTqAnhZZoCBjs7dGWp4Ktw=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.1/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/cpuguy83/go-md2man/v2 v2.0.3/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o=
|
||||
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
|
||||
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
|
||||
github.com/fatih/color v1.13.0/go.mod h1:kLAiJbzzSOZDVNGyDpeOxJ47H46qBXwg5ILebYFFOfk=
|
||||
github.com/fatih/color v1.16.0 h1:zmkK9Ngbjj+K0yRhTVONQh1p/HknKYSlNT+vZCzyokM=
|
||||
github.com/fatih/color v1.16.0/go.mod h1:fL2Sau1YI5c0pdGEVCbKQbLXB6edEj1ZgiY4NijnWvE=
|
||||
github.com/fatih/color v1.17.0 h1:GlRw1BRJxkpqUCBKzKOw098ed57fEsKeNjpTe3cSjK4=
|
||||
github.com/fatih/color v1.17.0/go.mod h1:YZ7TlrGPkiz6ku9fK3TLD/pl3CpsiFyu8N92HLgmosI=
|
||||
github.com/go-logfmt/logfmt v0.6.0 h1:wGYYu3uicYdqXVgoYbvnkrPVXkuLM1p1ifugDMEdRi4=
|
||||
github.com/go-logfmt/logfmt v0.6.0/go.mod h1:WYhtIu8zTZfxdn5+rREduYbwxfcBr/Vr6KEVveWlfTs=
|
||||
github.com/inconshreveable/mousetrap v1.0.0/go.mod h1:PxqpIevigyE2G7u3NXJIT2ANytuPF1OarO4DADm73n8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8=
|
||||
github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw=
|
||||
|
@ -32,6 +36,8 @@ github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZ
|
|||
github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w=
|
||||
github.com/muesli/termenv v0.15.2 h1:GohcuySI0QmI3wN8Ok9PtKGkgkFIk7y6Vpb5PvrY+Wo=
|
||||
github.com/muesli/termenv v0.15.2/go.mod h1:Epx+iuz8sNs7mNKhxzH4fWXGNpZwUaJKRS1noLXviQ8=
|
||||
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
|
||||
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||
github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc=
|
||||
github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ=
|
||||
github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88=
|
||||
|
@ -41,19 +47,20 @@ github.com/spf13/cobra v1.8.0 h1:7aJaZx1B85qltLMc546zn58BxxfZdR/W22ej9CFoEf0=
|
|||
github.com/spf13/cobra v1.8.0/go.mod h1:WXLWApfZ71AjXPya3WOlMsY9yMs7YeiHhFVlvLyhcho=
|
||||
github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA=
|
||||
github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg=
|
||||
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
|
||||
github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d h1:jtJma62tbqLibJ5sFQz8bKtEM8rJBtfilJ2qTU199MI=
|
||||
golang.org/x/exp v0.0.0-20231006140011-7918f672742d/go.mod h1:ldy0pHrwJyGW56pPQzzkH36rKxoZW1tw7ZJpeKx+hdo=
|
||||
golang.org/x/sys v0.0.0-20200116001909-b77594299b42/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20200223170610-d5e6a3e2c0ae/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
|
||||
golang.org/x/sys v0.0.0-20210630005230-0f9fa26af87c/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
|
||||
golang.org/x/sys v0.20.0 h1:Od9JTbYCk261bKm4M/mw7AklTlFYIa0bIp9BgSm1S8Y=
|
||||
golang.org/x/sys v0.20.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/sys v0.21.0 h1:rF+pYz3DAGSQAxAu1CbC7catZg4ebC4UIeIhKxBZvws=
|
||||
golang.org/x/sys v0.21.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
|
||||
golang.org/x/term v0.19.0 h1:+ThwsDv+tYfnJFhF4L8jITxu1tdTWRTZpdsWgEgjL6Q=
|
||||
golang.org/x/term v0.19.0/go.mod h1:2CuTdWZ7KHSQwUzKva0cbMg6q2DMI3Mmxp+gKJbskEk=
|
||||
golang.org/x/term v0.21.0 h1:WVXCp+/EBEHOj53Rvu+7KiT/iElMrO8ACK16SMZ3jaA=
|
||||
golang.org/x/term v0.21.0/go.mod h1:ooXLefLobQVslOqselCNF4SxFAaoS6KujMbsGzSDmX0=
|
||||
gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
|
||||
gopkg.in/yaml.v2 v2.4.0/go.mod h1:RDklbk79AGWmwhnvt/jBztapEOGDOx6ZbXqjP6csGnQ=
|
||||
gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA=
|
||||
gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"log"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
|
@ -15,6 +14,7 @@ import (
|
|||
"golang.org/x/term"
|
||||
|
||||
"github.com/briandowns/spinner"
|
||||
"github.com/charmbracelet/log"
|
||||
)
|
||||
|
||||
// verbose vs debug?
|
||||
|
@ -62,7 +62,7 @@ func parseSystemPath(derivation map[string]Derivation) (string, error) {
|
|||
// nix derivation show `oizys output` | jq -r '.[].inputDrvs | with_entries(select(.key|match("system-path";"i"))) | keys | .[]'
|
||||
func (o *Oizys) getSystemPath() string {
|
||||
cmd := exec.Command("nix", "derivation", "show", o.nixosConfigAttr())
|
||||
log.Println("evaluating to get system-path")
|
||||
log.Info("evaluating to get system-path")
|
||||
cmd.Stderr = os.Stderr
|
||||
out, err := cmd.Output()
|
||||
if err != nil {
|
||||
|
@ -139,7 +139,7 @@ func parsePackages(lines []string, desc string) *packages {
|
|||
for i, pkg := range lines {
|
||||
s := strings.SplitN(pkg, "-", 2)
|
||||
if len(s) != 2 {
|
||||
log.Fatalln("failed to trim hash path from this line: ", pkg)
|
||||
log.Fatalf("failed to trim hash path from this line: %s\n ", pkg)
|
||||
}
|
||||
name := ellipsis(strings.Replace(s[1], ".drv", "", 1), maxAcceptable)
|
||||
if nameLen := len(name); nameLen > maxLen {
|
||||
|
@ -193,10 +193,9 @@ func (p *packages) summary() {
|
|||
func (o *Oizys) git(rest ...string) *exec.Cmd {
|
||||
args := []string{"-C", o.flake}
|
||||
args = append(args, rest...)
|
||||
if o.verbose {
|
||||
fmt.Println("CMD:", "git", strings.Join(args, " "))
|
||||
}
|
||||
return exec.Command("git", args...)
|
||||
cmd := exec.Command("git", args...)
|
||||
logCmd(cmd)
|
||||
return cmd
|
||||
}
|
||||
|
||||
func showFailedOutput(buf []byte) {
|
||||
|
@ -243,8 +242,8 @@ func parseDryRun(buf string) (*packages, *packages) {
|
|||
}
|
||||
|
||||
if len(parts[0])+len(parts[1]) == 0 {
|
||||
log.Println("no changes...")
|
||||
log.Fatalln("or failed to parse nix build --dry-run output")
|
||||
log.Info("no changes...")
|
||||
log.Fatal("or failed to parse nix build --dry-run output")
|
||||
}
|
||||
|
||||
return parsePackages(parts[0], "packages to build"),
|
||||
|
@ -257,6 +256,10 @@ func showDryRunResult(nixOutput string, verbose bool) {
|
|||
toFetch.show(verbose)
|
||||
}
|
||||
|
||||
func logCmd(cmd *exec.Cmd) {
|
||||
log.Debugf("CMD: %s %s", cmd.Path, strings.Join(cmd.Args, " "))
|
||||
}
|
||||
|
||||
func (o *Oizys) NixDryRun(verbose bool, rest ...string) {
|
||||
args := []string{
|
||||
"build", o.nixosConfigAttr(), "--dry-run",
|
||||
|
@ -273,19 +276,19 @@ func (o *Oizys) NixDryRun(verbose bool, rest ...string) {
|
|||
showDryRunResult(string(result), verbose)
|
||||
}
|
||||
|
||||
// / Setup command completely differently here
|
||||
func (o *Oizys) NixosRebuild(subcmd string, rest ...string) {
|
||||
args := []string{
|
||||
cmd := exec.Command("sudo",
|
||||
"nixos-rebuild",
|
||||
subcmd,
|
||||
"--flake",
|
||||
o.flake,
|
||||
}
|
||||
args = append(args, rest...)
|
||||
)
|
||||
cmd.Args = append(cmd.Args, rest...)
|
||||
if o.verbose {
|
||||
args = append(args, "--print-build-logs")
|
||||
fmt.Println("CMD:", "sudo", strings.Join(args, " "))
|
||||
cmd.Args = append(cmd.Args, "--print-build-logs")
|
||||
}
|
||||
cmd := exec.Command("sudo", args...)
|
||||
logCmd(cmd)
|
||||
runCommand(cmd)
|
||||
}
|
||||
|
||||
|
@ -297,22 +300,6 @@ func runCommand(cmd *exec.Cmd) {
|
|||
}
|
||||
}
|
||||
|
||||
// func runBuildWithNom(buildCmd *exec.Cmd) {
|
||||
// log.Println("starting build?")
|
||||
// nomCmd := exec.Command("nom","--json")
|
||||
// var err error
|
||||
// buildCmd.Args = append(buildCmd.Args, "--log-format", "internal-json", "-v")
|
||||
// nomCmd.Stdin, err = buildCmd.StderrPipe()
|
||||
// if err != nil {
|
||||
// log.Fatal(err)
|
||||
// }
|
||||
// nomCmd.Stdout = os.Stdout
|
||||
// nomCmd.Start()
|
||||
// log.Println("starting buildcmd?")
|
||||
// buildCmd.Run()
|
||||
// nomCmd.Wait()
|
||||
// }
|
||||
|
||||
func (o *Oizys) NixBuild(nom bool, rest ...string) {
|
||||
var cmdName string
|
||||
if nom {
|
||||
|
@ -364,7 +351,7 @@ func (o *Oizys) CacheBuild(rest ...string) {
|
|||
func (o *Oizys) CheckFlake() {
|
||||
if _, ok := os.LookupEnv("OIZYS_SKIP_CHECK"); !ok {
|
||||
if _, err := os.Stat(o.flake); errors.Is(err, fs.ErrNotExist) {
|
||||
log.Fatalln("path to flake:", o.flake, "does not exist")
|
||||
log.Fatalf("path to flake: %s does not exist", o.flake)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue