Repository: lima-vm/lima (2026-04-06T11:14:59Z)

Issue:
DNS settings are not propagated when using a base template
### Description

DNS settings are not propagated from base template to main template.
> Discussion on [Slack](https://cloud-native.slack.com/archives/C043N6ZFV9S/p1773853580695349)

## Example:
### Base template:
```yaml
# Debian 13 (trixie) base image
images:
  - location: "https://cdimage.debian.org/images/cloud/trixie/20260316-2418/debian-13-generic-amd64-20260316-2418.qcow2"
    arch: "x86_64"
    digest: "sha512:c6523db54404e320ed30787038f155f649995392697fa2a41e49458d36e056fda020593a03cf910fa7bf93bd5c510b12d6e7c7bf7852a03ee3a64536fecf0127"
  - location: "https://cdimage.debian.org/images/cloud/trixie/20260316-2418/debian-13-generic-arm64-20260316-2418.qcow2"
    arch: "aarch64"
    digest: "sha512:f0460932cd6992539c7c9142bb02a24af83243503bad0179b0813bd6269195785655348ea889daf5927f80853f63b3402a78176967854887dbca9da3859599a0"
  # Fallback images
  - location: "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-amd64.qcow2"
    arch: "x86_64"
  - location: "https://cloud.debian.org/images/cloud/trixie/latest/debian-13-generic-arm64.qcow2"
    arch: "aarch64"

mounts: []
# containerd is managed by k3s, not by Lima, so the values are set to false here.
containerd:
  system: false
  user: false
dns:
  - 1.1.1.1
  - 8.8.8.8

hostResolver:
  enabled: false

provision:
  - mode: system
    script: |
      #!/bin/sh
      if [ ! -f /usr/bin/fish ]; then
        apt update
        apt install -y curl gnupg2
        echo 'deb https://download.opensuse.org/repositories/shells:/fish:/release:/4/Debian_13/ /' | sudo tee /etc/apt/sources.list.d/shells:fish:release:4.list
        curl -fsSL https://download.opensuse.org/repositories/shells:fish:release:4/Debian_13/Release.key | gpg --dearmor | sudo tee /etc/apt/trusted.gpg.d/shells_fish_release_4.gpg > /dev/null
        apt update
        apt install -y fish vim make
        chsh -s $(which fish) {{.User}}
        chsh -s $(which fish)
        hostnamectl set-hostname debian
        reboot
      fi


probes:
  - script: |
      #!/bin/sh
      if ! timeout 30s bash -c "until test -f /usr/bin/fish; do sleep 3; done"; then
           echo >&2 "fish is not installed yet"
           exit 1
      fi

ssh:
  loadDotSSHPubKeys: true

networks:
  - vzNAT: true
    interface: "eth1"

portForwards:
  - ignore: true
    proto: any
    guestIP: 0.0.0.0
vmType: vz
arch: aarch64
cpus: 4
memory: 12GiB
disk: 50GiB
upgradePackages: true
user:
  home: /home/{{.User}}
```
### Main template
```yaml
base:
  - base/debian.yaml
```

### Issue:
DNS setting set on the base template is not propagated to the main template. Not sure if `hostResolver` settings are also propagated.


Discussion:
Can I work on this issue?
> Can I work on this issue?

I've assigned it to you. I'm pretty sure the issue originates from https://github.com/lima-vm/lima/blob/077330a1af14fca926bea4e76c50381a43dcc861/pkg/limatmpl/embed.go#L227-L228

But I can't tell at a glance why this goes wrong; there should be not `dns` entry in the main template, so the DNS list in the base template should not get deleted.

I would start by creating a test for this scenario in `embed_test.go` and then see if the test passes when you comment out the line I quoted above.

The real task is to figure out why it would trigger even when the main template doesn't have a DNS list.



Patch:
diff --git a/pkg/limatmpl/embed.go b/pkg/limatmpl/embed.go
index c95b29adeb4..79a74da40b7 100644
--- a/pkg/limatmpl/embed.go
+++ b/pkg/limatmpl/embed.go
@@ -225,7 +225,8 @@ const mergeDocuments = `
 | $b | select((.base | tag == "!!str") and ($a.base | tag == "!!seq")) | .base = [ "" + .base ]
 
 # Delete base DNS entries if the template list is not empty.
-| $a | select(.dns) | del($b.dns, $c.dns)
+| $b | select($a.dns | length > 0) | del(.dns)
+| $c | select($a.dns | length > 0) | del(.dns)
 
 # Mark all new list fields with a custom tag. This is needed to avoid appending
 # newly copied lists to themselves again when we merge lists.


Test patch:
diff --git a/pkg/limatmpl/embed_test.go b/pkg/limatmpl/embed_test.go
index 5c82fe00292..c3d5916d766 100644
--- a/pkg/limatmpl/embed_test.go
+++ b/pkg/limatmpl/embed_test.go
@@ -100,6 +100,18 @@ minimumLimaVersion: 1.0.2  # or later
 		"dns: [8.8.8.8, 1.2.3.4]",
 		"dns: [1.1.1.1]",
 	},
+	{
+		"dns is copied from base when template has no dns",
+		"",
+		"dns: [1.1.1.1, 8.8.8.8]",
+		"dns: [1.1.1.1, 8.8.8.8]",
+	},
+	{
+		"dns is copied from base when template has empty list",
+		"dns: []",
+		"dns: [1.1.1.1, 8.8.8.8]",
+		"dns: [1.1.1.1, 8.8.8.8]",
+	},
 	{
 		"Update comments on existing maps and lists that don't have comments yet",
 		`#