aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFuwn <[email protected]>2024-09-17 16:52:35 -0700
committerFuwn <[email protected]>2024-09-17 16:52:35 -0700
commit2db46a96a8499d0102d386f23e972891c4443426 (patch)
treea42eb9097d62ac2231dd6454b81cde46c522b843
parent51d86c7be9756674252b39412ca3b9cb1227b406 (diff)
downloadrui-2db46a96a8499d0102d386f23e972891c4443426.tar.xz
rui-2db46a96a8499d0102d386f23e972891c4443426.zip
feat(rui): editor and flake file configuration
-rw-r--r--rui.go48
1 files changed, 38 insertions, 10 deletions
diff --git a/rui.go b/rui.go
index 6a2848f..e81aeec 100644
--- a/rui.go
+++ b/rui.go
@@ -11,7 +11,9 @@ import (
)
type Configuration struct {
- Notify bool `json:"notify"`
+ Notify bool `json:"notify"`
+ Editor string `json:"editor"`
+ Flake string `json:"flake"`
}
var configuration Configuration
@@ -110,8 +112,14 @@ func main() {
user = os.Getenv("USER")
}
+ flake := configuration.Flake
+
+ if flake == "" {
+ flake = os.Getenv("FLAKE")
+ }
+
err = Command("home-manager", append([]string{"switch",
- "--flake", fmt.Sprintf("%s#%s", os.Getenv("FLAKE"), user)},
+ "--flake", fmt.Sprintf("%s#%s", flake, user)},
extraArgs...)...)
}
@@ -134,7 +142,12 @@ func main() {
},
},
Action: func(c *cli.Context) error {
- target := os.Getenv("FLAKE")
+ flake := configuration.Flake
+
+ if flake == "" {
+ flake = os.Getenv("FLAKE")
+ }
+
extraArgs := []string{}
if c.Bool("impure") {
@@ -142,11 +155,11 @@ func main() {
}
if user := c.String("user"); user != "" {
- target = fmt.Sprintf("%s#%s", target, user)
+ flake = fmt.Sprintf("%s#%s", flake, user)
}
return Command("home-manager", append([]string{"news", "--flake",
- target}, extraArgs...)...)
+ flake}, extraArgs...)...)
},
},
},
@@ -191,8 +204,14 @@ func main() {
}
}
+ flake := configuration.Flake
+
+ if flake == "" {
+ flake = os.Getenv("FLAKE")
+ }
+
err = Command(escalator, "nixos-rebuild", "switch", "--flake",
- fmt.Sprintf("%s#%s", os.Getenv("FLAKE"), hostname))
+ fmt.Sprintf("%s#%s", flake, hostname))
}
if err != nil {
@@ -207,13 +226,22 @@ func main() {
{
Name: "edit",
Action: func(c *cli.Context) error {
- editor, err := os.LookupEnv("FLAKE_EDITOR")
+ var found bool
+
+ editor := configuration.Editor
+ flake := configuration.Flake
+
+ if flake == "" {
+ flake = os.Getenv("FLAKE")
+ }
- if err {
- return Command(editor, os.Getenv("FLAKE"))
+ if editor == "" {
+ if editor, found = os.LookupEnv("FLAKE_EDITOR"); !found {
+ editor = os.Getenv("EDITOR")
+ }
}
- return Command(os.Getenv("EDITOR"), os.Getenv("FLAKE"))
+ return Command(editor, flake)
},
},
},