cmd/nixbuild: instantiated deduplicate stat

Use case for this came up while writing tests.
This commit is contained in:
Ophestra 2025-07-18 21:19:16 +09:00
parent d3a8aed237
commit 92ac3275c1
Signed by: cat
SSH Key Fingerprint: SHA256:gQ67O0enBZ7UdZypgtspB2FDM1g3GVw8nX0XSdcFw8Q

View File

@ -118,6 +118,32 @@ func main() {
}). }).
Flag(&resolveFlagOut, "o", command.StringFlag("store-paths"), "Path to write collected store paths") Flag(&resolveFlagOut, "o", command.StringFlag("store-paths"), "Path to write collected store paths")
c.Command("stat", "Compute the instantiated deduplication stat of an installable", func(args []string) error {
var installable string
if err := formatInstallable("instantiated", &installable, flagNixOS, args); err != nil {
return err
}
log.Println("initialising evaluator")
var collective []string
if eval, err := nixbuild.NewInstantiatedEvaluator(ctx, installable); err != nil {
return commandHandlerError(fmt.Sprintf("cannot initialise evaluator: %v", err))
} else {
log.Println("collecting paths")
collective = slices.Collect(eval.Instantiated())
if err := eval.Err(); err != nil {
return commandHandlerError(fmt.Sprintf("cannot collect: %v", err))
}
}
l := len(collective)
slices.Sort(collective)
collective = slices.Compact(collective)
log.Printf("`%s`: %d paths instantiated, %d duplicate, dedup %.1f%%",
installable, l, l-len(collective), float64(l-len(collective))/float64(l)*100)
return nil
})
c.Command("instantiated", "Evaluate an installable and output all derivations instantiated during evaluation", func(args []string) error { c.Command("instantiated", "Evaluate an installable and output all derivations instantiated during evaluation", func(args []string) error {
var installable string var installable string
if err := formatInstallable("instantiated", &installable, flagNixOS, args); err != nil { if err := formatInstallable("instantiated", &installable, flagNixOS, args); err != nil {