Skip to content

treewide: migrate nixos modules to networking.hosts #414780

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 7, 2025

Conversation

JohnRTitor
Copy link
Member

Split off from #413925 as this doesn't need a discussion on whether extraHosts need to be kept.

Things done

  • Built on platform(s)
    • x86_64-linux
    • aarch64-linux
    • x86_64-darwin
    • aarch64-darwin
  • For non-Linux: Is sandboxing enabled in nix.conf? (See Nix manual)
    • sandbox = relaxed
    • sandbox = true
  • Tested, as applicable:
  • Tested compilation of all packages that depend on this change using nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage
  • Fits CONTRIBUTING.md.

Add a 👍 reaction to pull requests you find important.

@github-actions github-actions bot added 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 8.has: module (update) This PR changes an existing module in `nixos/` 6.topic: nixos-container Imperative and declarative systemd-nspawn containers 6.topic: testing Tooling for automated testing of packages and modules labels Jun 7, 2025
@JohnRTitor JohnRTitor requested a review from mweinelt June 7, 2025 15:51
@github-actions github-actions bot added 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux. labels Jun 7, 2025
@JohnRTitor
Copy link
Member Author

JohnRTitor commented Jun 7, 2025

Tests built successfully on nix community linux builder..

[johnrtitor@build01:~]$ nix build github:nixos/nixpkgs/refs/pull/414780/merge#nixosTests.kubernetes.dns-multi-node --print-out-paths
/nix/store/3sag9grqi74v8sf4k9f94pvl2xjwyf8f-vm-test-run-kubernetes-dns-multinode

[johnrtitor@build01:~]$ nix build github:nixos/nixpkgs/master#nixosTests.kubernetes.rbac-single-node --print-out-paths
/nix/store/ykhzag3wlfp9xz555zp3val6bb0gsf0l-vm-test-run-kubernetes-rbac-singlenode

[johnrtitor@build01:~]$ nix build github:nixos/nixpkgs/master#nixosTests.kubernetes.rbac-multi-node --print-out-paths
/nix/store/rypj7gqcq7fi2vds5whgdz6shmr44xqq-vm-test-run-kubernetes-rbac-multinode


[johnrtitor@build01:~]$ nix build github:nixos/nixpkgs/master#nixosTests.kubernetes.dns-multi-node --print-out-paths
/nix/store/p6njkf9w9ywb34q1nsk801pvh2vcyi1w-vm-test-run-kubernetes-dns-multinode
[johnrtitor@build01:~]$ nix build github:nixos/nixpkgs/refs/pull/414780/merge#nixosTests.containers-hosts --print-out-paths
evaluation warning: system.stateVersion is not set, defaulting to 25.11. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.
evaluation warning: system.stateVersion is not set, defaulting to 25.11. Read why this matters on https://nixos.org/manual/nixos/stable/options.html#opt-system.stateVersion.
/nix/store/pqhggz01m4x45yjaslzqbiwysicdprdz-vm-test-run-containers-hosts

[johnrtitor@build01:~]$ nix build github:nixos/nixpkgs/refs/pull/414780/merge#nixosTests.gitlab --print-build-logs --print-out-paths
/nix/store/jq0zihw1cg5hbhq318mj7p4h0jippc5x-vm-test-run-gitlab

@JohnRTitor JohnRTitor merged commit cd64f1b into NixOS:master Jun 7, 2025
21 of 23 checks passed
@JohnRTitor JohnRTitor deleted the migrate-to-networking-hosts branch June 7, 2025 17:39
@vcunat
Copy link
Member

vcunat commented Jun 8, 2025

nixosTests.acme.http01-builtin did break:
https://hydra.nixos.org/build/299342505

and so nixos-unstable* channels are blocked by that now.

@JohnRTitor
Copy link
Member Author

Could you give me 2 hrs? I can try preparing a fix, else I'll open a revert PR.

@gravndal
Copy link
Contributor

gravndal commented Jun 8, 2025

This broke eval for simple nixos containers like:

  containers.evalfailure.config =
    { ... }:
    {
      environment.systemPackages = [ pkgs.hello ];
    };
       … from call site                                                                                                                                                                     
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/nixos/modules/virtualisation/nixos-containers.nix:1087:28:                                                                   
         1086|         # Generate /etc/hosts entries for the containers.                                                                                                                    
         1087|         networking.hosts = lib.mapAttrs' (name: cfg: {                                                                                                                       
             |                            ^                                                                                                                                                 
         1088|           name = head (splitString "/" cfg.localAddress);                                                                                                                    
                                                                                                                                                                                            
       … while calling 'mapAttrs''                                                                                                                                                          
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/lib/attrsets.nix:1045:18:                                                                                                    
         1044|   */                                                                                                                                                                         
         1045|   mapAttrs' = f: set: listToAttrs (mapAttrsToList f set);                                                                                                                    
             |                  ^                                                                                                                                                           
         1046|                                                                                                                                                                              
                                                                                                                                                                                            
       … while calling the 'listToAttrs' builtin                                                                                                                                            
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/lib/attrsets.nix:1045:23:                                                                                                    
         1044|   */                                                                                                                                                                         
         1045|   mapAttrs' = f: set: listToAttrs (mapAttrsToList f set);                                                                                                                    
             |                       ^                                                                                                                                                      
         1046|                                                                                                                                                                              
                                                                                                                                                                                            
       … while evaluating the `name` attribute of an element of the list passed to builtins.listToAttrs                                                                                     
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/nixos/modules/virtualisation/nixos-containers.nix:1088:11:                                                                   
         1087|         networking.hosts = lib.mapAttrs' (name: cfg: {                                                                                                                       
         1088|           name = head (splitString "/" cfg.localAddress);                                                                                                                    
             |           ^                                                                                                                                                                  
         1089|           value = lib.optionals (cfg.localAddress != null) [ "${name}.containers" ];                                                                                         
                                                                                                                                                                                            
       … while calling the 'head' builtin                                                                                                                                                   
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/nixos/modules/virtualisation/nixos-containers.nix:1088:18:                                                                   
         1087|         networking.hosts = lib.mapAttrs' (name: cfg: {                                                                                                                       
         1088|           name = head (splitString "/" cfg.localAddress);                                                                                                                    
             |                  ^                                                                                                                                                           
         1089|           value = lib.optionals (cfg.localAddress != null) [ "${name}.containers" ];                                                                                         
                                                                                                                                                                                            
       … while calling 'addContextFrom'                                                                                                                                                     
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/lib/strings.nix:1645:25:                                                                                                     
         1644|   */                                                                                                                                                                         
         1645|   addContextFrom = src: target: substring 0 0 src + target;                                                                                                                  
             |                         ^                                                                                                                                                    
         1646|                                                                                                                                                                              
                                                                                                                                                                                            
       … while calling the 'substring' builtin                                                                                                                                              
         at /nix/store/wshl2a8akx0g41wkb8k5i3c8131y0lfx-source/lib/strings.nix:1645:33:                                                                                                     
         1644|   */                                                                                                                                                                         
         1645|   addContextFrom = src: target: substring 0 0 src + target;                                                                                                                  
             |                                 ^                                                                                                                                            
         1646|                                                                                                                                                                              
                                                                                                                                                                                            
       … while evaluating the third argument (the string) passed to builtins.substring                                                                                                      
                                                                                                                                                                                            
       error: cannot coerce null to a string: null

@JohnRTitor
Copy link
Member Author

I absoulutely love how these aren't caught by our nixosTests.containers-hosts.

Revert PR: #415085

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS 6.topic: nixos-container Imperative and declarative systemd-nspawn containers 6.topic: testing Tooling for automated testing of packages and modules 8.has: module (update) This PR changes an existing module in `nixos/` 10.rebuild-darwin: 0 This PR does not cause any packages to rebuild on Darwin. 10.rebuild-linux: 1-10 This PR causes between 1 and 10 packages to rebuild on Linux.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants