Skip to content

Add NixOS network manager support#1567

Open
jmvermeulen wants to merge 4 commits intofox-it:mainfrom
jmvermeulen:feature/nixos-network-manager
Open

Add NixOS network manager support#1567
jmvermeulen wants to merge 4 commits intofox-it:mainfrom
jmvermeulen:feature/nixos-network-manager

Conversation

@jmvermeulen
Copy link

@jmvermeulen jmvermeulen commented Feb 23, 2026

Summary

NixOS uses the Nix functional language for declarative system configuration, storing network settings in /etc/nixos/*.nix files (commonly networking.nix). None of the existing network parsers can handle this format, resulting in empty IP addresses for NixOS targets.

This adds a NixOSConfigParser to the network.py plugin that extracts:

  • IPv4/IPv6 addresses with prefix length from .addresses = [...] blocks (as proper ip_interface objects)
  • Default gateway from defaultGateway = "..."
  • DNS nameservers from nameservers = [...]
  • Interface names from interfaces = { name = { ... } } blocks and interfaces.name.ipvX patterns
  • DHCP status from dhcpcd.enable / useDHCP

Detection

NixOS is detected via the /etc/NIXOS marker file or /etc/nixos/configuration.nix. On non-NixOS systems the parser yields nothing.

Example

$ target-query -f network.interfaces /path/to/nixos-image.E01
<unix/network/interface hostname='test-nixos' domain=None name='eth0' type='static' enabled=None
  cidr=[net.ipinterface('10.13.37.10/24'), net.ipinterface('2001:db8::1/64')]
  gateway=[net.ipaddress('10.13.37.0')]
  dns=[net.ipaddress('10.13.37.1'), net.ipaddress('10.13.37.2')]
  source='/etc/nixos/networking.nix' configurator='nixos'>

target-info also picks up the IPs:

Before:

Hostname       : test-nixos
Ips            :
Os family      : linux
Os version     : NixOS 25.05 (Warbler)

After:

Hostname       : test-nixos
Ips            : 10.13.37.10, 2001:db8::1
Os family      : linux
Os version     : NixOS 25.05 (Warbler)

Test fixtures

Based on a real-world networking.nix structure generated by nixos-infect, with tests for static IP, DHCP, and non-NixOS detection. All IPs in test fixtures use 10.13.37.x (consistent with existing tests) and 2001:db8:: (RFC 3849 documentation range). Test data files are stored as LFS.

Limitations

  • The parser uses regex rather than a full Nix language parser, so highly dynamic configurations using Nix functions/variables for network values won't be parsed. In practice, most NixOS network configs are straightforward static declarations.

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.
@DissectBot
Copy link

@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:

@DissectBot agree [company="{your company}"]

Options:

  • (default - no company specified) I have sole ownership of intellectual property rights to my Submissions and I am not making Submissions in the course of work for my employer.
  • (when company given) I am making Submissions in the course of work for my employer (or my employer has intellectual property rights in my Submissions by contract or applicable law). I have permission from my employer to make Submissions and enter into this Agreement on behalf of my employer. By signing below, the defined term “You” includes me and my employer.
Contributor License Agreement

Contribution License Agreement

This 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.

  1. Definitions.
    "Contribution" means any original work of authorship, including any modifications or additions to an existing work, that is intentionally submitted by You to Fox-IT for inclusion in, or documentation of, any of the software products owned or managed by, or on behalf of, Fox-IT as part of the Project (the "Work").
    "Project" means any of the projects owned or managed by Fox-IT and offered under a license approved by the Open Source Initiative (www.opensource.org).
    "Submit" means any form of electronic, verbal, or written communication sent to Fox-IT or its representatives, including but not limited to communication on electronic mailing lists, source code control systems, and issue tracking systems that are managed by, or on behalf of, Fox-IT for the purpose of discussing and improving the Work, but excluding communication that is conspicuously marked or otherwise designated in writing by You as "Not a Contribution."

  2. Grant of Copyright License. Subject to the terms and conditions of this Agreement, You hereby grant to Fox-IT and to recipients of software distributed by Fox-IT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable copyright license to reproduce, prepare derivative works of, publicly display, publicly perform, sublicense, and distribute Your Contributions and such derivative works.

  3. Grant of Patent License. Subject to the terms and conditions of this Agreement, You hereby grant to Fox-IT and to recipients of software distributed by Fox-IT a perpetual, worldwide, non-exclusive, no-charge, royalty-free, irrevocable (except as stated in this section) patent license to make, have made, use, maintain, offer to sell, sell, import, and otherwise transfer the Work, where such license applies only to those patent claims licensable by You that are necessarily infringed by Your Contribution(s) alone or by combination of Your Contribution(s) with the Work to which such Contribution(s) was submitted. If any entity institutes patent litigation against You or any other entity (including a cross-claim or counterclaim in a lawsuit) alleging that your Contribution, or the Work to which you have contributed, constitutes direct or contributory patent infringement, then any patent licenses granted to that entity under this Agreement for that Contribution or Work shall terminate as of the date such litigation is filed.

  4. Representations. You represent that:

    • You are legally entitled to grant the above license.
    • each of Your Contributions is Your original creation (see section 8 for submissions on behalf of others).
    • Your Contribution submissions include complete details of any third-party license or other restriction (including, but not limited to, related patents and trademarks) of which you are personally aware and which are associated with any part of Your Contributions.
  5. Employer. If Your Contribution is made in the course of Your work for an employer or Your employer has intellectual property rights in Your Submission by contract or applicable law, You must secure permission from Your employer to make the Contribution before signing this Agreement. In that case, the term "You" in this Agreement will refer to You and the employer collectively. If You change employers in the future and desire to Submit additional Contribution for the new employer, then You agree to sign a new Agreement and secure permission from the new employer before Submitting those Contributions.

  6. Support. You are not expected to provide support for Your Contribution, unless You choose to do so. Any such support provided to the Project is provided free of charge.

  7. Warranty. Unless required by applicable law or agreed to in writing, You provide Your Contributions on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, including, without limitation, any warranties or conditions of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE.

  8. Third party material. Should You wish to submit work that is not Your original creation, You may only submit it to Fox-IT separately from any Contribution, identifying the complete details of its source and of any license or other restriction (including, but not limited to, related patents, trademarks, and license agreements) of which You are personally aware, and conspicuously marking the work as "Submitted on behalf of a third-party: [named here]".

  9. Notify. You agree to notify Fox-IT of any facts or circumstances of which You become aware that would make the above representations inaccurate in any respect.

  10. Governing law / competent court. This Agreement is governed by the laws of the Netherlands. Any disputes that may arise are resolved by arbitration in accordance with the Arbitration Regulations of the Foundation for the Settlement of Automation Disputes (Stichting Geschillenoplossing Automatisering – SGOA – (www.sgoa.eu), this without prejudice to either party"s right to request preliminary relief in preliminary relief proceedings or arbitral preliminary relief proceedings. Arbitration proceedings take place in Amsterdam, or in any other place designated in the Arbitration Regulations. Arbitration shall take place in English.

@jmvermeulen
Copy link
Author

@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
@jmvermeulen jmvermeulen force-pushed the feature/nixos-network-manager branch from 5f067be to 637dde4 Compare February 23, 2026 14:04
@jmvermeulen jmvermeulen requested a review from Schamper February 23, 2026 14:55


MANAGERS = [NetworkManagerConfigParser, SystemdNetworkConfigParser, ProcConfigParser]
class NixOSConfigParser(LinuxNetworkConfigParser):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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"):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Miauwkeru I think you use NixOS too, is there a nicer way we can parse this using the config helpers?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
@jmvermeulen jmvermeulen requested a review from Schamper February 25, 2026 18:36
@Schamper Schamper changed the title feat: add NixOS network manager support for IP extraction Add NixOS network manager support Mar 16, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants