Nixos Image 26.05 DNS Issue

Hi- I have an issue that is specific to the nixos 26.05 image. When I launch the image the resolv.conf does not have the incus search domain. - see below

nameserver 127.0.0.53
options edns0 trust-ad
search ..

*************************

I ran: resolvectl domain eth0 incus

in container and that fixed the issue. Is there a fix at launch time?

Plan B would be to create a local nix os image with resolvectl domain eth0 incus command already run. Would that be a temporary solution?

Thanks

What does networkctl show about the network?

Sgraber- Thanks for taking a look.

This seems to have added incus as search domain- However, I need this to be done when the container is launched.
**************************************************************************

mkdir -p /etc/systemd/network/50-eth0.network.d

cat >/etc/systemd/network/50-eth0.network.d/dhcp-domains.conf <<‘EOF’
[DHCPv4]
UseDomains=yes
EOF

********************************************************************************

root@nixos:~]# networkctl
IDX LINK TYPE OPERATIONAL SETUP
1 lo loopback carrier unmanaged
75 eth0 ether routable configured

2 links listed.

************************************************

networkctl status eth0 --all
● 1: lo
Link File: n/a
Network File: n/a
State: carrier (unmanaged)
Online state: unknown
Type: loopback
Hardware Address: 00:00:00:00:00:00
MTU: 65536
QDisc: noqueue
IPv6 Address Generation Mode: eui64
Number of Queues (Tx/Rx): 1/1
Address: 127.0.0.1
::1

Jul 24 19:20:29 nixos systemd-networkd[322]: lo: Link UP
Jul 24 19:20:29 nixos systemd-networkd[322]: lo: Gained carrier

● 75: eth0
Link File: /nix/store/vv5bna641lxwxm0nqgy20134y7wivsvp-systemd-260.2/lib/systemd/network/99-default.link
Network File: /etc/systemd/network/50-eth0.network
State: routable (configured)
Online state: online
Type: ether
Kind: veth
Driver: veth
Hardware Address: 10:66:6a:db:25:d8
MTU: 1500 (min: 68, max: 65535)
QDisc: noqueue
IPv6 Address Generation Mode: eui64
Number of Queues (Tx/Rx): 2/2
Auto negotiation: no
Speed: 10Gbps
Duplex: full
Port: tp
Address: 10.34.66.73 (DHCPv4 via 10.34.66.1)
fd42:c4e6:11e0:dc8e:1266:6aff:fedb:25d8
fd42:c4e6:11e0:dc8e:872b:4d78:caa9:d15c
fe80::1266:6aff:fedb:25d8
Gateway: 10.34.66.1
fe80::1266:6aff:fea3:827a
DNS: 10.34.66.1
fd42:c4e6:11e0:dc8e::1
Activation Policy: up
Required For Online: yes
DHCPv4 Client ID: IAID:0x1c62e5b3/DUID
DHCPv6 Client IAID: 0x1c62e5b3
DHCPv6 Client DUID: DUID-EN/Vendor:0000ab11f0cf1a4469512b7e

*****************************************************************************

[root@nixos:~]# cat /run/systemd/netif/leases/*

ADDRESS=10.34.66.73
NETMASK=255.255.255.0
ROUTER=10.34.66.1
SERVER_ADDRESS=10.34.66.1
NEXT_SERVER=10.34.66.1
BROADCAST=10.34.66.255
T1=5month 4w 2d 10h
T2=10month 2w 1d 4h 22min 30s
LIFETIME=11month 4w 2d 9h 30min
DNS=10.34.66.1
DOMAINNAME=incus
HOSTNAME=test
CLIENTID=fxxxxxxxxxxxxxxxxxxxxxxx

Hmm, that’s odd, does Nix have a different default for the DHCP settings somehow?
I’m pretty sure UseDomain=yes is the usual default on most platforms.

I checked nixos sources and UseDomains is not defined anywhere so it inherits values from systemd so it is unset by default.

I would not recommend to change it and all settings should be deployed in the nixos configuration, for example:

systemd.network.networks.eth0.dhcpV4Config.UseDomains = true;

I think it is a problem with the image and may be an oversight. I agree with you that the default behavior should be set the search domain on the incus image which has been my experience with all other incus images.

Nixos is declarative. In the /etc/nixos/, two files get created: configuration.nix and incus.nix. I am still learning nixos and maybe these files need to be changed in the upstream image.

It is definitely an issue if you need DNS at the time the image gets created. Yes it can be manually fixed, but I am using tofu and deploy rs to configure the workload. Deploy rs relies on having SSH access to the target container and I need to initiate the SSH session with the DNS name of the target container.

*********************************************************************************

configuration.nix

Edit this configuration file to define what should be installed on your system. Help is available in the configuration.nix(5) man page and in the NixOS manual (accessible by running ‘nixos-help’).

{ modulesPath, … }:

{
imports = [

Include the default incus configuration.

“${modulesPath}/virtualisation/lxc-container.nix”

Include the container-specific autogenerated configuration.

./incus.nix
];

networking = {
dhcpcd.enable = false;
useDHCP = false;
useHostResolvConf = false;
};

systemd.network = {
enable = true;
networks.“50-eth0” = {
matchConfig.Name = “eth0”;
networkConfig = {
DHCP = “ipv4”;
IPv6AcceptRA = true;
};
linkConfig.RequiredForOnline = “routable”;
};
};

system.stateVersion = “26.05”; # Did you read the comment?
}

**********************************************************

***And incus.nix

{
lib,
config,
pkgs,

}:

WARNING: THIS CONFIGURATION IS AUTOGENERATED AND WILL BE OVERWRITTEN AUTOMATICALLY

{
networking.hostName = “test2”;
}

thanks- I need the dns access when the container is created to use deploy rs .

If I were you, I would separate process of learning NixOS from Incus. What you are trying to do now is to fix your lack of understanding of NixOS with chaotic fixes taken from your previous experiences with non-declarative systems. What you need to do is to create a NixOS configuration which will suit your requirements first, run it on the default naked image you are provided by Incus, and then use NixOS deployment tools. Try to do that without Incus first, to make your learning curve less steep.

incus launch images:nixos/26.05 test1

incus launch images:nixos/26.05 test2

incus exec test1 bash

ping test2

This does not work for me. Does that work for you? How are you fixing this problem?

Thanks

If you could edit your post with the .nix files, and put three backticks (```) on a line of their own before and after the content of each file, it will be much easier to read.

This is a markdown fenced code block - without it, contents of your file are interpreted as markdown - e.g. a comment starting with # is treated as a heading.