liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

commit 42a315383f5c9499028c5327ba5908462611c432
parent 98cbb93109cc813c079078163cbed539ae3ba4fe
Author: Daniel Barlow <dan@telent.net>
Date:   Tue,  4 Aug 2026 21:54:41 +0100

add option to configure /etc/hosts entries

Diffstat:
Mmodules/base.nix | 19+++++++++++++++----
Mtests/smoke/test.nix | 11++++++++++-
2 files changed, 25 insertions(+), 5 deletions(-)

diff --git a/modules/base.nix b/modules/base.nix @@ -32,7 +32,14 @@ in system.callService = mkOption { type = types.functionTo (types.functionTo types.anything); }; - + hosts = mkOption { + type = with types; attrsOf (listOf str); + description = "Locally defined IP address to hostname map"; + example = { + "127.0.0.1" = [ "foo.bar.baz" ]; + "192.168.0.2" = [ "fileserver.local" "nameserver.local" ]; + }; + }; filesystem = mkOption { type = types.anything; description = '' @@ -115,6 +122,8 @@ in }; imports = [ ./early ]; config = { + hosts."127.0.0.1" = [ "localhost" ] ; + defaultProfile.packages = with pkgs; [ s6 s6-init-bin @@ -226,9 +235,11 @@ in '' ); hosts = symlink ( - pkgs.writeText "hosts" '' - 127.0.0.1 localhost - '' + pkgs.writeText "hosts" ( + lib.concatMapAttrsStringSep "" + (n: v: "${n} ${lib.concatStringsSep " " v}\n") + config.hosts + ) ); in dir { diff --git a/tests/smoke/test.nix b/tests/smoke/test.nix @@ -2,7 +2,13 @@ let img = (import <liminix> { device = import <liminix/devices/qemu>; - liminix-config = <liminix/vanilla-configuration.nix>; + liminix-config = { ... }: + { + imports = [ <liminix/vanilla-configuration.nix> ]; + config.hosts = { + "127.0.0.53" = [ "apple" "orange" ]; + }; + }; }).outputs.rootfs; pkgs = import <nixpkgs> { }; in @@ -21,6 +27,9 @@ pkgs.runCommand "check" trap 'echo "command $(eval echo $BASH_COMMAND) failed with exit code $?"; exit $?' ERR unsquashfs -q -d $destpath -excludes ${img} /dev cd $destpath; + hostsfile=$(echo $(readlink etc/hosts) | sed 's/^.//') + grep -q -E '127.0.0.1.+localhost' $hostsfile + grep -q -E '127.0.0.53.+apple.+orange' $hostsfile db=nix/store/*-s6-rc-database/compiled/ test -d $db chmod -R +w $db