Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 13 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"encoding/json"
"fmt"
"os"
"slices"
"strings"

"github.com/numtide/nixos-facter/pkg/hwinfo"
Expand Down Expand Up @@ -91,15 +92,25 @@ func init() {
"sysfs", "udev", "block", "wlan",
}

// we strip default and int from the feature list
allFeatures := hwinfo.ProbeFeatureStrings()
slices.DeleteFunc(allFeatures, func(str string) bool {
switch str {
case "default", "int":
return true
default:
return false
}
})

f.StringSliceVarP(
&hardwareFeatures,
"hardware-features",
"f",
defaultFeatures,
fmt.Sprintf(
"Hardware features to probe. Possible values are %s",
// we strip default from the feature list
strings.Replace(strings.Join(hwinfo.ProbeFeatureStrings(), ","), "default,", "", 1),
strings.Join(allFeatures, ","),
),
)
}
Expand Down
4 changes: 4 additions & 0 deletions pkg/hwinfo/hwinfo.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ func Scan(probes []ProbeFeature) ([]Smbios, []*HardwareItem, error) {
// initialise the struct to hold scan data
data := (*C.hd_data_t)(unsafe.Pointer(C.calloc(1, C.size_t(unsafe.Sizeof(C.hd_data_t{})))))

// ProbeFeatureInt needs to always be set, otherwise we don't get pci and usb vendor id lookups.
// https://github.com/openSUSE/hwinfo/blob/c87f449f1d4882c71b0a1e6dc80638224a5baeed/src/hd/hd.c#L597-L605
C.hd_set_probe_feature(data, C.enum_probe_feature(ProbeFeatureInt))

// set the hardware probes to run
for _, probe := range probes {
C.hd_set_probe_feature(data, C.enum_probe_feature(probe))
Expand Down