-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #114 from numtide/feat/godoc
feat/godoc
- Loading branch information
Showing
25 changed files
with
995 additions
and
820 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
go_doc |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,3 @@ | ||
/* | ||
Copyright © 2024 NAME HERE <EMAIL ADDRESS> | ||
*/ | ||
package main | ||
|
||
import ( | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,27 @@ | ||
{pkgs, ...}: | ||
{ | ||
pkgs, | ||
perSystem, | ||
... | ||
}: | ||
pkgs.mkShellNoCC { | ||
packages = with pkgs; | ||
[ | ||
mkdocs | ||
] | ||
++ (with pkgs.python3Packages; [ | ||
mike | ||
mkdocs-material | ||
]); | ||
# Pop an empty shell on systems that aren't supported by godoc | ||
lib.optionals (perSystem.godoc ? default) | ||
([ | ||
perSystem.godoc.default | ||
(pkgs.writeScriptBin "gen-reference" '' | ||
out="./docs/content/reference/go_doc" | ||
godoc -c -o $out . | ||
'') | ||
(pkgs.writeScriptBin "mkdocs" '' | ||
# generate reference docs first | ||
gen-reference | ||
# execute the underlying command | ||
${pkgs.mkdocs}/bin/mkdocs "$@" | ||
'') | ||
] | ||
++ (with pkgs.python3Packages; [ | ||
mike | ||
mkdocs-material | ||
])); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,14 @@ | ||
// Package build contains constants and values set at build time via -X flags. | ||
package build | ||
|
||
var ( | ||
Name = "nixos-facter" | ||
// Name is the program name, typically set via Nix to match the derivation's `pname`. | ||
Name = "nixos-facter" | ||
// Version is the program version, typically set via Nix to match the derivation's `version`. | ||
Version = "v0.0.0+dev" | ||
System = "" | ||
|
||
// ReportVersion is used to indicate significant changes in the report output | ||
// System is the architecture that this program was built for e.g. x86_64-linux. | ||
// It is set via Nix to match the Nixpkgs system. | ||
System = "" | ||
// ReportVersion is used to indicate significant changes in the report output and is embedded JSON report produced. | ||
ReportVersion uint = 2 | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,106 @@ | ||
// Package facter contains types and utilities for scanning a system and generating a report, detailing key aspects of | ||
// the system and its connected hardware. | ||
package facter | ||
|
||
import ( | ||
"fmt" | ||
|
||
"github.com/numtide/nixos-facter/pkg/ephem" | ||
|
||
"github.com/numtide/nixos-facter/pkg/build" | ||
"github.com/numtide/nixos-facter/pkg/hwinfo" | ||
"github.com/numtide/nixos-facter/pkg/virt" | ||
) | ||
|
||
// Report represents a detailed report on the system’s hardware, virtualisation, SMBios, and swap entries. | ||
type Report struct { | ||
// Version is a monotonically increasing number, | ||
// used to indicate breaking changes or new features in the report output. | ||
Version uint `json:"version"` | ||
|
||
// System indicates the system architecture e.g. x86_64-linux. | ||
System string `json:"system"` | ||
|
||
// Virtualisation indicates the type of virtualisation or container environment present on the system. | ||
Virtualisation virt.Type `json:"virtualisation"` | ||
|
||
// Hardware provides detailed information about the system’s hardware components, such as CPU, memory, and peripherals. | ||
Hardware Hardware `json:"hardware,omitempty"` | ||
|
||
// Smbios provides detailed information about the system's SMBios data, such as BIOS, board, chassis, memory, and processors. | ||
Smbios Smbios `json:"smbios,omitempty"` | ||
|
||
// Swap contains a list of swap entries representing the system's swap devices or files and their respective details. | ||
Swap []*ephem.SwapEntry `json:"swap,omitempty"` | ||
} | ||
|
||
// Scanner defines a type responsible for scanning and reporting system hardware information. | ||
type Scanner struct { | ||
// Swap indicates whether the system swap information should be reported. | ||
Swap bool | ||
|
||
// Ephemeral indicates whether the scanner should report ephemeral details, | ||
// such as swap. | ||
Ephemeral bool | ||
|
||
// Features is a list of ProbeFeature types that should be scanned for. | ||
Features []hwinfo.ProbeFeature | ||
} | ||
|
||
// Scan scans the system's hardware and software information and returns a report. | ||
// It also detects IOMMU groups and handles errors gracefully if scanning fails. | ||
func (s *Scanner) Scan() (*Report, error) { | ||
var err error | ||
report := Report{ | ||
Version: build.ReportVersion, | ||
} | ||
|
||
if build.System == "" { | ||
return nil, fmt.Errorf("system is not set") | ||
} | ||
report.System = build.System | ||
|
||
var smbios []hwinfo.Smbios | ||
var devices []hwinfo.HardwareDevice | ||
|
||
smbios, devices, err = hwinfo.Scan(s.Features) | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to scan hardware: %w", err) | ||
} | ||
|
||
// read iommu groups | ||
iommuGroups, err := hwinfo.IOMMUGroups() | ||
if err != nil { | ||
return nil, fmt.Errorf("failed to read iommu groups: %w", err) | ||
} | ||
|
||
for idx := range devices { | ||
// lookup iommu group before adding to the report | ||
device := devices[idx] | ||
groupId, ok := iommuGroups[device.SysfsId] | ||
if ok { | ||
device.SysfsIOMMUGroupId = &groupId | ||
} | ||
if err = report.Hardware.add(device); err != nil { | ||
return nil, fmt.Errorf("failed to add to hardware report: %w", err) | ||
} | ||
} | ||
|
||
for idx := range smbios { | ||
if err = report.Smbios.add(smbios[idx]); err != nil { | ||
return nil, fmt.Errorf("failed to add to smbios report: %w", err) | ||
} | ||
} | ||
|
||
if report.Virtualisation, err = virt.Detect(); err != nil { | ||
return nil, fmt.Errorf("failed to detect virtualisation: %w", err) | ||
} | ||
|
||
if s.Ephemeral || s.Swap { | ||
if report.Swap, err = ephem.SwapEntries(); err != nil { | ||
return nil, fmt.Errorf("failed to detect swap devices: %w", err) | ||
} | ||
} | ||
|
||
return &report, nil | ||
} |
Oops, something went wrong.