Jip-Hop / jailmaker

Persistent Linux 'jails' on TrueNAS SCALE to install software (k3s, docker, portainer, podman, etc.) with full access to all files via bind mounts thanks to systemd-nspawn!
GNU Lesser General Public License v3.0
430 stars 38 forks source link

Fallback to default config #229

Closed Jip-Hop closed 1 week ago

Jip-Hop commented 2 weeks ago

When providing an incomplete config file, fallback to the default config for the missing values and write the interpolated config file.

Currently this works:

jlmkr create --start --config=- test <<END
initial_setup=apt-get update
    apt-get install -y curl
distro=debian
release=bookworm
END

But the resulting config file is very minimal:

initial_setup=apt-get update
        apt-get install -y curl
distro=debian
release=bookworm
systemd_nspawn_user_args=

And this doesn't work (because image and distro don't fallback to defaults during jlmkr create:

jlmkr create --start --config=- test <<END
initial_setup=apt-get update
    apt-get install -y curl
END

However keep in mind that comments should be preserved when the user provides a complete (or almost complete?) config file. In that case we don't want to take the default config (with comments) as the base.

Lockszmith-GH commented 2 weeks ago

Like it very much - best to surround additions with a BEGIN/END comment

Jip-Hop commented 2 weeks ago

What do you mean? If it's the END tags then I'm afraid it's not possible to use a different tag for BEGIN and END as this is heredoc syntax. But I agree it's probably better to use another delimiter than END but that's up to the user anyway.

Lockszmith-GH commented 2 weeks ago

Not 'tags' per se, but comments showing to the human where the machine put stuff they didn't write. if, in the example you supplied:

initial_setup=apt-get update
    apt-get install -y curl

And the auto-config will add distro and release, the resulting config will look like:

initial_setup=apt-get update
    apt-get install -y curl

#### AUTOMATICALLY ADDED #### BEGIN ####
distro=debian
release=bookworm
#### AUTOMATICALLY ADDED ##### END #####
Jip-Hop commented 2 weeks ago

Hmm that's one option for sure. But I think I rather have something more complete like the default config at the top of jlmkr.py

https://github.com/Jip-Hop/jailmaker/blob/c1f6990b7fca6e2e7e93eca645d3e9b9e141f3e6/jlmkr.py#L37-L101

Lockszmith-GH commented 2 weeks ago

I see... interesting. Not against - just never seen it like that.

Jip-Hop commented 1 week ago

Closing as not planned due to End of Life October 2024 Announcement.