Skip to content

Commit da4578a

Browse files
brianmcgeeMagicRB
andcommitted
feat: provide nvd and nix-diff view of facter changes
Provides a `debug` namespace within `config.facter` which can be used to display a diff between the system closure with facter enabled, and without. The diffs are in the form of `nvd` or `nix-diff` output e.g. higher level summary versus detailed breakdown. Usage: - `nix run .#nixosConfigurations.basic.config.facter.debug.nvd` - `nix run .#nixosConfigurations.basic.config.facter.debug.nix-diff` Examples: ``` ❯ nix run .#nixosConfigurations.basic.config.facter.debug.nvd <<< /nix/store/fqbia5p8hfnyzxipfjmzxn8v3b69mjvs-nixos-system-nixos-24.11.20240831.12228ff >>> /nix/store/ijkh9sq03y72pfrjvncrsrhwh7g6k8q0-nixos-system-nixos-24.11.20240831.12228ff Added packages: [A.] #1 X-Reload-Triggers-systemd-networkd <none> [A.] #2 X-Restart-Triggers-systemd-networkd <none> [A.] #3 X-Restart-Triggers-systemd-resolved <none> [A.] #4 etc-systemd-networkd.conf <none> [A.] #5 etc-systemd-resolved.conf <none> [A.] #6 graphics-driver.conf <none> [A.] #7 graphics-drivers <none> [A.] #8 hwdata 0.385 [A.] #9 libXfixes 6.0.1 [A.] #10 libXxf86vm 1.1.5 [A.] #11 libdrm 2.4.122 [A.] #12 libpciaccess 0.18.1 [A.] #13 libxshmfence 1.3.2 [A.] #14 llvm 18.1.8-lib [A.] #15 lm-sensors 3.6.0 [A.] #16 mesa 24.2.1, 24.2.1-drivers [A.] #17 unit 99-ethernet-default-dhcp.network, 99-wireless-client-dhcp.network [A.] #18 unit-systemd-network-wait-online-.service <none> [A.] #19 unit-systemd-networkd-wait-online.service <none> [A.] #20 unit-systemd-networkd.service <none> [A.] #21 unit-systemd-networkd.socket <none> [A.] #22 unit-systemd-resolved.service <none> [A.] #23 vulkan-loader 1.3.283.0 [A.] #24 wayland 1.23.0 [A.] #25 xcb-util-keysyms 0.4.1 Removed packages: [R.] #1 X-Restart-Triggers-resolvconf <none> [R-] #2 dhcpcd 10.0.6 [R.] #3 dhcpcd.conf <none> [R-] #4 openresolv 3.13.2 [R.] #5 unit-dhcpcd.service <none> [R.] #6 unit-network-setup.service <none> [R.] #7 unit-resolvconf.service <none> [R.] #8 unit-script-network-setup-start <none> Closure size: 562 -> 581 (55 paths added, 36 paths removed, delta +19, disk usage +700.6MiB). ``` ``` ❯ nix run .#nixosConfigurations.basic.config.facter.debug.nix-diff - /nix/store/fqbia5p8hfnyzxipfjmzxn8v3b69mjvs-nixos-system-nixos-24.11.20240831.12228ff:{out} + /nix/store/ijkh9sq03y72pfrjvncrsrhwh7g6k8q0-nixos-system-nixos-24.11.20240831.12228ff:{out} • The input derivation named `boot.json` differs - /nix/store/zcmdy29f5di6rrfkkld3x773q1d7c1bv-boot.json.drv:{out} + /nix/store/j0wxsmw6fxgzd59pdcljkpq430jbk8jn-boot.json.drv:{out} • The input derivation named `initrd-linux-6.6.48` differs - /nix/store/3z3jgifv3rj5wrh4cx23gzc9hlrwrxwj-initrd-linux-6.6.48.drv:{out} + /nix/store/ds7pcp97k33p93z460b5vzrii02jjkcf-initrd-linux-6.6.48.drv:{out} • The input derivation named `initrd-nixos.conf` differs - /nix/store/y458hw08d5hv2bcf295fv9wvbsfvprrq-initrd-nixos.conf.drv:{out} + /nix/store/989v278ws16mnvlx6fwsa925vgx9a0ia-initrd-nixos.conf.drv:{out} • The environments do not match: text='' virtio_balloon virtio_console virtio_rng virtio_gpu bochs dm_mod '' • The input derivation named `linux-6.6.48-modules-shrunk` differs - /nix/store/dk2xshi6hr85wjyia60nizahl2rq31sz-linux-6.6.48-modules-shrunk.drv:{out} + /nix/store/xxk67p9wy7hxq33gd1mfz5dqcsm2mhsr-linux-6.6.48-modules-shrunk.drv:{out} • The environments do not match: rootModules='' virtio_net virtio_pci virtio_mmio virtio_blk 9p 9pnet_virtio uhci_hcd ata_piix floppy virtio_blk virtio_pci ext2 ext4 autofs tpm-tis tpm-crb efivarfs ahci sata_nv sata_via sata_sis sata_uli ata_piix pata_marvell nvme sd_mod sr_mod mmc_block uhci_hcd ehci_hcd ehci_pci ohci_hcd ohci_pci xhci_hcd xhci_pci usbhid hid_generic hid_lenovo hid_apple hid_roccat hid_logitech_hidpp hid_logitech_dj hid_microsoft hid_cherry hid_corsair pcips2 atkbd i8042 rtc_cmos virtio_balloon virtio_console virtio_rng virtio_gpu bochs dm_mod '' • Skipping environment comparison • Skipping environment comparison ... ... ... ``` Co-authored-by: magicrb <[email protected]>
1 parent fa11d87 commit da4578a

File tree

3 files changed

+174
-0
lines changed

3 files changed

+174
-0
lines changed

docs/content/getting-started/nixos-configuration.md

Lines changed: 100 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,104 @@ The NixOS Facter module will attempt to do the following:
8282
We continue to add to and improve [nixos-facter-modules]. Our eventual goal is to replace much if not all of the
8383
functionality currently provided by [nixos-hardware] and [nixos-generate-config].
8484

85+
## Introspection and debugging
86+
87+
You might be asking yourself:
88+
89+
> This is cool and all that, but how do I know what changes `nixos-facter` will be making to my system closure???
90+
91+
And you would be right to be concerned about just applying it without a way of understanding its impact.
92+
93+
That is why we have added the following options for introspecting how `nixos-facter` is affecting a system closure.
94+
95+
### `nvd`
96+
97+
You can output a [nvd diff] of the system closure with and without `nixos-facter` enabled by running
98+
`nix run .#nixosConfigurations.<hostname>.config.facter.debug.nvd`:
99+
100+
```shell
101+
❯ nix run .#nixosConfigurations.basic.config.facter.debug.nvd
102+
<<< /nix/store/fqbia5p8hfnyzxipfjmzxn8v3b69mjvs-nixos-system-nixos-24.11.20240831.12228ff
103+
>>> /nix/store/ijkh9sq03y72pfrjvncrsrhwh7g6k8q0-nixos-system-nixos-24.11.20240831.12228ff
104+
Added packages:
105+
[A.] #01 X-Reload-Triggers-systemd-networkd <none>
106+
[A.] #02 X-Restart-Triggers-systemd-networkd <none>
107+
[A.] #03 X-Restart-Triggers-systemd-resolved <none>
108+
[A.] #04 etc-systemd-networkd.conf <none>
109+
[A.] #05 etc-systemd-resolved.conf <none>
110+
[A.] #06 graphics-driver.conf <none>
111+
[A.] #07 graphics-drivers <none>
112+
[A.] #08 hwdata 0.385
113+
[A.] #09 libXfixes 6.0.1
114+
[A.] #10 libXxf86vm 1.1.5
115+
[A.] #11 libdrm 2.4.122
116+
[A.] #12 libpciaccess 0.18.1
117+
[A.] #13 libxshmfence 1.3.2
118+
[A.] #14 llvm 18.1.8-lib
119+
[A.] #15 lm-sensors 3.6.0
120+
[A.] #16 mesa 24.2.1, 24.2.1-drivers
121+
[A.] #17 unit 99-ethernet-default-dhcp.network, 99-wireless-client-dhcp.network
122+
[A.] #18 unit-systemd-network-wait-online-.service <none>
123+
[A.] #19 unit-systemd-networkd-wait-online.service <none>
124+
[A.] #20 unit-systemd-networkd.service <none>
125+
[A.] #21 unit-systemd-networkd.socket <none>
126+
[A.] #22 unit-systemd-resolved.service <none>
127+
[A.] #23 vulkan-loader 1.3.283.0
128+
[A.] #24 wayland 1.23.0
129+
[A.] #25 xcb-util-keysyms 0.4.1
130+
Removed packages:
131+
[R.] #1 X-Restart-Triggers-resolvconf <none>
132+
[R-] #2 dhcpcd 10.0.6
133+
[R.] #3 dhcpcd.conf <none>
134+
[R-] #4 openresolv 3.13.2
135+
[R.] #5 unit-dhcpcd.service <none>
136+
[R.] #6 unit-network-setup.service <none>
137+
[R.] #7 unit-resolvconf.service <none>
138+
[R.] #8 unit-script-network-setup-start <none>
139+
Closure size: 562 -> 581 (55 paths added, 36 paths removed, delta +19, disk usage +700.6MiB).
140+
```
141+
142+
### `nix-diff`
143+
144+
You can output a [nix-diff] of the system closure with and without `nixos-facter` enabled by running
145+
`nix run .#nixosConfigurations.<hostname>.config.facter.debug.nix-diff`:
146+
147+
```shell
148+
❯ nix run .#nixosConfigurations.basic.config.facter.debug.nix-diff
149+
- /nix/store/fqbia5p8hfnyzxipfjmzxn8v3b69mjvs-nixos-system-nixos-24.11.20240831.12228ff:{out}
150+
+ /nix/store/ijkh9sq03y72pfrjvncrsrhwh7g6k8q0-nixos-system-nixos-24.11.20240831.12228ff:{out}
151+
• The input derivation named `boot.json` differs
152+
- /nix/store/zcmdy29f5di6rrfkkld3x773q1d7c1bv-boot.json.drv:{out}
153+
+ /nix/store/j0wxsmw6fxgzd59pdcljkpq430jbk8jn-boot.json.drv:{out}
154+
• The input derivation named `initrd-linux-6.6.48` differs
155+
- /nix/store/3z3jgifv3rj5wrh4cx23gzc9hlrwrxwj-initrd-linux-6.6.48.drv:{out}
156+
+ /nix/store/ds7pcp97k33p93z460b5vzrii02jjkcf-initrd-linux-6.6.48.drv:{out}
157+
• The input derivation named `initrd-nixos.conf` differs
158+
- /nix/store/y458hw08d5hv2bcf295fv9wvbsfvprrq-initrd-nixos.conf.drv:{out}
159+
+ /nix/store/989v278ws16mnvlx6fwsa925vgx9a0ia-initrd-nixos.conf.drv:{out}
160+
• The environments do not match:
161+
text=''
162+
virtio_balloon
163+
virtio_console
164+
virtio_rng
165+
virtio_gpu
166+
bochs
167+
dm_mod
168+
''
169+
• The input derivation named `linux-6.6.48-modules-shrunk` differs
170+
- /nix/store/dk2xshi6hr85wjyia60nizahl2rq31sz-linux-6.6.48-modules-shrunk.drv:{out}
171+
+ /nix/store/xxk67p9wy7hxq33gd1mfz5dqcsm2mhsr-linux-6.6.48-modules-shrunk.drv:{out}
172+
• The environments do not match:
173+
rootModules=''
174+
virtio_net virtio_pci virtio_mmio virtio_blk 9p 9pnet_virtio uhci_hcd ata_piix floppy virtio_blk virtio_pci ext2 ext4 autofs tpm-tis tpm-crb efivarfs ahci sata_nv sata_via sata_sis sata_uli ata_piix pata_marvell nvme sd_mod sr_mod mmc_block uhci_hcd ehci_hcd ehci_pci ohci_hcd ohci_pci xhci_hcd xhci_pci usbhid hid_generic hid_lenovo hid_apple hid_roccat hid_logitech_hidpp hid_logitech_dj hid_microsoft hid_cherry hid_corsair pcips2 atkbd i8042 rtc_cmos virtio_balloon virtio_console virtio_rng virtio_gpu bochs dm_mod
175+
''
176+
• Skipping environment comparison
177+
• Skipping environment comparison
178+
...
179+
...
180+
...
181+
```
182+
85183
[NixOS configuration]: https://nixos.org/manual/nixos/stable/#sec-configuration-syntax
86184
[detected architecture]: https://github.com/numtide/nixos-facter-modules/blob/main/modules/nixos/system.nix
87185
[detected virtualisation]: https://github.com/numtide/nixos-facter-modules/blob/main/modules/nixos/virtualisation.nix
@@ -91,3 +189,5 @@ The NixOS Facter module will attempt to do the following:
91189
[nixos-facter-modules]: https://github.com/numtide/nixos-facter-modules
92190
[nixos-hardware]: https://github.com/NixOS/nixos-hardware
93191
[nixos-generate-config]: https://github.com/NixOS/nixpkgs/blob/master/nixos/modules/installer/tools/nixos-generate-config.pl
192+
[nvd diff]: https://khumba.net/projects/nvd/
193+
[nix-diff]: https://github.com/Gabriella439/nix-diff

modules/nixos/debug.nix

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
{
2+
lib,
3+
pkgs,
4+
config,
5+
extendModules,
6+
...
7+
}:
8+
{
9+
10+
options = {
11+
12+
system.build = {
13+
noFacter = lib.mkOption {
14+
type = lib.types.unspecified;
15+
description = "A version of the system closure with facter disabled";
16+
};
17+
};
18+
19+
facter.debug = {
20+
nvd = lib.mkOption {
21+
type = lib.types.package;
22+
description = ''
23+
A shell application which will produce an nvd diff of the system closure with and without facter enabled.
24+
'';
25+
};
26+
nix-diff = lib.mkOption {
27+
type = lib.types.package;
28+
description = ''
29+
A shell application which will produce a nix-diff of the system closure with and without facter enabled.
30+
'';
31+
};
32+
};
33+
34+
};
35+
36+
config.system.build = {
37+
noFacter = extendModules {
38+
modules = [
39+
{
40+
# we 'disable' facter by overriding the report and setting it to empty with one caveat: hostPlatform
41+
config.facter.report = lib.mkForce {
42+
system = config.nixpkgs.hostPlatform;
43+
};
44+
}
45+
];
46+
};
47+
};
48+
49+
config.facter.debug = {
50+
51+
nvd = pkgs.writeShellApplication {
52+
name = "facter-diff";
53+
runtimeInputs = [ pkgs.nvd ];
54+
text = ''
55+
nvd diff \
56+
${config.system.build.noFacter.config.system.build.toplevel} \
57+
${config.system.build.toplevel}
58+
'';
59+
};
60+
61+
nix-diff = pkgs.writeShellApplication {
62+
name = "facter-diff";
63+
runtimeInputs = [ pkgs.nix-diff ];
64+
text = ''
65+
nix-diff \
66+
${config.system.build.noFacter.config.system.build.toplevel} \
67+
${config.system.build.toplevel}
68+
'';
69+
};
70+
71+
};
72+
73+
}

modules/nixos/facter.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
imports = [
88
./bluetooth.nix
99
./disk.nix
10+
./debug.nix
1011
./fingerprint
1112
./firmware.nix
1213
./graphics

0 commit comments

Comments
 (0)