cmd/nix-tool: override context for chroot store
This commit is contained in:
parent
0956524d0c
commit
d6d327cb91
17
cmd/nix-tool/chroot.go
Normal file
17
cmd/nix-tool/chroot.go
Normal file
@ -0,0 +1,17 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"context"
|
||||
"os/exec"
|
||||
|
||||
"gensokyo.uk/nix"
|
||||
)
|
||||
|
||||
type chrootStoreContext struct {
|
||||
store string
|
||||
nix.Context
|
||||
}
|
||||
|
||||
func (c *chrootStoreContext) Nix(ctx context.Context, arg ...string) *exec.Cmd {
|
||||
return c.Context.Nix(ctx, append([]string{"--store", c.store}, arg...)...)
|
||||
}
|
@ -10,6 +10,7 @@ import (
|
||||
"os"
|
||||
"os/signal"
|
||||
"slices"
|
||||
"strings"
|
||||
"syscall"
|
||||
|
||||
"gensokyo.uk/nix"
|
||||
@ -27,6 +28,7 @@ func main() {
|
||||
defer stop()
|
||||
|
||||
var (
|
||||
flagStore string
|
||||
flagNixOS bool
|
||||
flagVerbose bool
|
||||
flagJSON bool
|
||||
@ -40,8 +42,14 @@ func main() {
|
||||
}
|
||||
ctx = nix.New(nixCtx, nil, os.Stdout, stderr)
|
||||
|
||||
flagStore = strings.TrimSpace(flagStore)
|
||||
if flagStore != string(os.PathSeparator) {
|
||||
ctx = &chrootStoreContext{flagStore, ctx}
|
||||
}
|
||||
|
||||
return nil
|
||||
}).
|
||||
Flag(&flagStore, "store", command.StringFlag("/"), "Path to the nix root").
|
||||
Flag(&flagNixOS, "nixos", command.BoolFlag(false), "Interpret input as NixOS flake installable").
|
||||
Flag(&flagVerbose, "v", command.BoolFlag(false), "Connect nix stderr").
|
||||
Flag(&flagJSON, "json", command.BoolFlag(false), "Serialise output in JSON when applicable")
|
||||
|
Loading…
x
Reference in New Issue
Block a user