sign: wrap signing from stdin
This commit is contained in:
@@ -12,7 +12,7 @@ import (
|
||||
"slices"
|
||||
"syscall"
|
||||
|
||||
"git.gensokyo.uk/yonah/nixbuild"
|
||||
"gensokyo.uk/nix"
|
||||
"hakurei.app/command"
|
||||
)
|
||||
|
||||
@@ -21,7 +21,7 @@ type commandHandlerError string
|
||||
func (c commandHandlerError) Error() string { return string(c) }
|
||||
|
||||
func main() {
|
||||
var ctx nixbuild.Context
|
||||
var ctx nix.Context
|
||||
|
||||
nixCtx, stop := signal.NotifyContext(context.Background(), os.Interrupt, syscall.SIGTERM)
|
||||
defer stop()
|
||||
@@ -39,7 +39,7 @@ func main() {
|
||||
if flagVerbose {
|
||||
stderr = os.Stderr
|
||||
}
|
||||
ctx = nixbuild.New(nixCtx, nil, os.Stdout, stderr)
|
||||
ctx = nix.New(nixCtx, nil, os.Stdout, stderr)
|
||||
|
||||
return nil
|
||||
}).
|
||||
@@ -52,7 +52,7 @@ func main() {
|
||||
return commandHandlerError("show requires at least 1 argument")
|
||||
}
|
||||
|
||||
if drv, err := nixbuild.DerivationShow(ctx, slices.Values(args)); err != nil {
|
||||
if drv, err := nix.DerivationShow(ctx, slices.Values(args)); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot show: %v", err))
|
||||
} else {
|
||||
log.Printf("got %d derivations:\n%#v", len(drv), drv)
|
||||
@@ -65,12 +65,27 @@ func main() {
|
||||
return commandHandlerError("build requires at least 1 argument")
|
||||
}
|
||||
|
||||
if err := nixbuild.Build(ctx, slices.Values(args)); err != nil {
|
||||
if err := nix.Build(ctx, slices.Values(args)); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot build: %v", err))
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
var (
|
||||
flagSignKey string
|
||||
)
|
||||
c.NewCommand("sign", command.UsageInternal, func(args []string) error {
|
||||
if len(args) < 1 {
|
||||
return commandHandlerError("sign requires at least 1 argument")
|
||||
}
|
||||
|
||||
if err := nix.Sign(ctx, flagSignKey, slices.Values(args)); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot sign: %v", err))
|
||||
}
|
||||
return nil
|
||||
}).
|
||||
Flag(&flagSignKey, "key", command.StringFlag("/var/lib/persist/cache/key"), "File containing the secret signing key")
|
||||
|
||||
var (
|
||||
resolveFlagOut string
|
||||
)
|
||||
@@ -82,23 +97,23 @@ func main() {
|
||||
|
||||
log.Printf("evaluating %s", installable)
|
||||
var installables []string
|
||||
if v, err := nixbuild.EvalInstantiated(ctx, installable); err != nil {
|
||||
if v, err := nix.EvalInstantiated(ctx, installable); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot evaluate for instantiated derivations: %v", err))
|
||||
} else {
|
||||
installables = v
|
||||
}
|
||||
|
||||
log.Println("building instantiated derivations")
|
||||
if err := nixbuild.Build(ctx, slices.Values(installables)); err != nil {
|
||||
if err := nix.Build(ctx, slices.Values(installables)); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot build: %v", err))
|
||||
}
|
||||
|
||||
var collective []string
|
||||
log.Println("collecting store paths")
|
||||
if derivations, err := nixbuild.DerivationShow(ctx, slices.Values(installables)); err != nil {
|
||||
if derivations, err := nix.DerivationShow(ctx, slices.Values(installables)); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot show: %v", err))
|
||||
} else {
|
||||
collective = nixbuild.CollectFromDerivations(derivations)
|
||||
collective = nix.CollectFromDerivations(derivations)
|
||||
}
|
||||
|
||||
f, err := os.Create(resolveFlagOut)
|
||||
@@ -110,7 +125,7 @@ func main() {
|
||||
return commandHandlerError(fmt.Sprintf("cannot serialise JSON: %v", err))
|
||||
}
|
||||
} else {
|
||||
if _, err = nixbuild.WriteStdin(f, slices.Values(collective)); err != nil {
|
||||
if _, err = nix.WriteStdin(f, slices.Values(collective)); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot write store path list: %v", err))
|
||||
}
|
||||
}
|
||||
@@ -126,7 +141,7 @@ func main() {
|
||||
|
||||
log.Println("initialising evaluator")
|
||||
var collective []string
|
||||
if eval, err := nixbuild.NewInstantiatedEvaluator(ctx, installable); err != nil {
|
||||
if eval, err := nix.NewInstantiatedEvaluator(ctx, installable); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot initialise evaluator: %v", err))
|
||||
} else {
|
||||
log.Println("collecting paths")
|
||||
@@ -150,7 +165,7 @@ func main() {
|
||||
return err
|
||||
}
|
||||
|
||||
if v, err := nixbuild.EvalInstantiated(ctx, installable); err != nil {
|
||||
if v, err := nix.EvalInstantiated(ctx, installable); err != nil {
|
||||
return commandHandlerError(fmt.Sprintf("cannot evaluate for instantiated derivations: %v", err))
|
||||
} else if flagJSON {
|
||||
if err = json.NewEncoder(os.Stdout).Encode(v); err != nil {
|
||||
@@ -158,7 +173,7 @@ func main() {
|
||||
}
|
||||
return nil
|
||||
} else {
|
||||
_, _ = nixbuild.WriteStdin(os.Stdout, slices.Values(v))
|
||||
_, _ = nix.WriteStdin(os.Stdout, slices.Values(v))
|
||||
return nil
|
||||
}
|
||||
})
|
||||
|
||||
Reference in New Issue
Block a user