Conversation
NixOS uses the Nix functional language for declarative system configuration, storing network settings in /etc/nixos/*.nix files. None of the existing 8 network manager parsers can handle this format, resulting in empty IP addresses for NixOS targets. This adds a regex-based parser that extracts: - IPv4/IPv6 addresses from .addresses blocks - Default gateway from defaultGateway - DNS nameservers from nameservers list - Interface names from interfaces block - DHCP status from dhcpcd.enable / useDHCP Detection uses /etc/NIXOS marker file or /etc/nixos/configuration.nix. Includes test fixtures based on real-world NixOS networking.nix generated by nixos-infect, with tests for IP, DNS, and gateway extraction.
|
@jmvermeulen thank you for your contribution! As this is your first code contribution, please read the following Contributor License Agreement (CLA). If you agree with the CLA, please reply with the following information:
Contributor License Agreement
Contribution License AgreementThis Contribution License Agreement ("Agreement") governs your Contribution(s) (as defined below) and conveys certain license rights to Fox-IT B.V. ("Fox-IT") for your Contribution(s) to Fox-IT"s open source Dissect project. This Agreement covers any and all Contributions that you ("You" or "Your"), now or in the future, Submit (as defined below) to this project. This Agreement is between Fox-IT B.V. and You and takes effect when you click an “I Accept” button, check box presented with these terms, otherwise accept these terms or, if earlier, when You Submit a Contribution.
|
|
@DissectBot agree |
Move NixOS network configuration parsing to the new network.py plugin as requested in code review. The network_managers plugin is deprecated. Changes: - Add NixOSConfigParser to network.py yielding UnixInterfaceRecord - Extract IPs with prefixLength as proper ip_interface objects - Detect NixOS via /etc/NIXOS marker or /etc/nixos/configuration.nix - Revert all network_managers.py changes - Move test fixtures to tests/_data/plugins/os/unix/linux/nixos/ (LFS) - Add tests to test_network.py instead of test_ips.py
5f067be to
637dde4
Compare
|
|
||
|
|
||
| MANAGERS = [NetworkManagerConfigParser, SystemdNetworkConfigParser, ProcConfigParser] | ||
| class NixOSConfigParser(LinuxNetworkConfigParser): |
There was a problem hiding this comment.
Can you move this class up so that the file structure stays:
- Manager classes
- Lease classes
- Helper functions
| ): | ||
| return | ||
|
|
||
| for config_file in self._config_files(self.config_paths, "*.nix"): |
There was a problem hiding this comment.
@Miauwkeru I think you use NixOS too, is there a nicer way we can parse this using the config helpers?
There was a problem hiding this comment.
nix is a bit specific, so i think we need to make a nix specific config parser for those kind of files. The helper functions we have available will help a bit with creating the parser
Add a Nix configuration parser to configutil that handles the subset of Nix syntax used in NixOS configuration files (attribute sets, dotted paths, lists, strings, booleans, lib.mkForce/mkDefault). Refactor NixOSConfigParser to use configutil.parse(hint="nix") instead of regex, and move the class before lease parsers to maintain file structure.
Remove features not used in nixos-infect networking configs: - let...in blocks, lib.mkOverride/mkIf, block comments - multiline string escapes, null values, path literals
Summary
NixOS uses the Nix functional language for declarative system configuration, storing network settings in
/etc/nixos/*.nixfiles (commonlynetworking.nix). None of the existing network parsers can handle this format, resulting in empty IP addresses for NixOS targets.This adds a
NixOSConfigParserto thenetwork.pyplugin that extracts:.addresses = [...]blocks (as properip_interfaceobjects)defaultGateway = "..."nameservers = [...]interfaces = { name = { ... } }blocks andinterfaces.name.ipvXpatternsdhcpcd.enable/useDHCPDetection
NixOS is detected via the
/etc/NIXOSmarker file or/etc/nixos/configuration.nix. On non-NixOS systems the parser yields nothing.Example
target-infoalso picks up the IPs:Before:
After:
Test fixtures
Based on a real-world
networking.nixstructure generated by nixos-infect, with tests for static IP, DHCP, and non-NixOS detection. All IPs in test fixtures use10.13.37.x(consistent with existing tests) and2001:db8::(RFC 3849 documentation range). Test data files are stored as LFS.Limitations