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"
|
||||||
"os/signal"
|
"os/signal"
|
||||||
"slices"
|
"slices"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
|
|
||||||
"gensokyo.uk/nix"
|
"gensokyo.uk/nix"
|
||||||
@ -27,6 +28,7 @@ func main() {
|
|||||||
defer stop()
|
defer stop()
|
||||||
|
|
||||||
var (
|
var (
|
||||||
|
flagStore string
|
||||||
flagNixOS bool
|
flagNixOS bool
|
||||||
flagVerbose bool
|
flagVerbose bool
|
||||||
flagJSON bool
|
flagJSON bool
|
||||||
@ -40,8 +42,14 @@ func main() {
|
|||||||
}
|
}
|
||||||
ctx = nix.New(nixCtx, nil, os.Stdout, stderr)
|
ctx = nix.New(nixCtx, nil, os.Stdout, stderr)
|
||||||
|
|
||||||
|
flagStore = strings.TrimSpace(flagStore)
|
||||||
|
if flagStore != string(os.PathSeparator) {
|
||||||
|
ctx = &chrootStoreContext{flagStore, ctx}
|
||||||
|
}
|
||||||
|
|
||||||
return nil
|
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(&flagNixOS, "nixos", command.BoolFlag(false), "Interpret input as NixOS flake installable").
|
||||||
Flag(&flagVerbose, "v", command.BoolFlag(false), "Connect nix stderr").
|
Flag(&flagVerbose, "v", command.BoolFlag(false), "Connect nix stderr").
|
||||||
Flag(&flagJSON, "json", command.BoolFlag(false), "Serialise output in JSON when applicable")
|
Flag(&flagJSON, "json", command.BoolFlag(false), "Serialise output in JSON when applicable")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user