mirror of
https://github.com/nix-community/nix-on-droid.git
synced 2025-11-08 11:36:07 +01:00
modules/environment/networking: implement /etc/hosts options
This commit is contained in:
parent
2301e01d48
commit
b324ef2824
6 changed files with 143 additions and 6 deletions
7
tests/on-device/config-flake-hosts-localhost.cfg.nix
Normal file
7
tests/on-device/config-flake-hosts-localhost.cfg.nix
Normal file
|
|
@ -0,0 +1,7 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
system.stateVersion = "23.05";
|
||||
|
||||
networking.hosts."127.0.0.2" = [ "localhost" ];
|
||||
}
|
||||
37
tests/on-device/config-flake-hosts.bats
Normal file
37
tests/on-device/config-flake-hosts.bats
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
# Copyright (c) 2023, see AUTHORS. Licensed under MIT License, see LICENSE.
|
||||
|
||||
load lib
|
||||
|
||||
@test 'hosts can be configured' {
|
||||
# set up / build / activate the configuration
|
||||
cat "$ON_DEVICE_TESTS_DIR/config-flake-hosts.cfg.nix" \
|
||||
> ~/.config/nixpkgs/nix-on-droid.nix
|
||||
_sed "s|<<FLAKE_URL>>|$FLAKE_URL|g" \
|
||||
"$ON_DEVICE_TESTS_DIR/config-flake.nix" \
|
||||
> ~/.config/nixpkgs/flake.nix
|
||||
|
||||
nix-on-droid switch --flake ~/.config/nixpkgs#device
|
||||
|
||||
# check that /etc/hosts contains configured hosts
|
||||
for entry in '::1 localhost' \
|
||||
'127.0.0.1 localhost' \
|
||||
'127.0.0.2 a b' \
|
||||
'127.0.0.3 c' \
|
||||
'127.0.0.4 d'
|
||||
do
|
||||
grep "$entry" /etc/hosts
|
||||
done
|
||||
}
|
||||
|
||||
@test 'hosts can not map localhost' {
|
||||
# set up / build / activate the configuration
|
||||
cat "$ON_DEVICE_TESTS_DIR/config-flake-hosts-localhost.cfg.nix" \
|
||||
> ~/.config/nixpkgs/nix-on-droid.nix
|
||||
_sed "s|<<FLAKE_URL>>|$FLAKE_URL|g" \
|
||||
"$ON_DEVICE_TESTS_DIR/config-flake.nix" \
|
||||
> ~/.config/nixpkgs/flake.nix
|
||||
|
||||
# check that networking.hosts can't map localhost
|
||||
run nix-on-droid switch --flake ~/.config/nixpkgs#device
|
||||
[ "$status" -eq 1 ]
|
||||
}
|
||||
19
tests/on-device/config-flake-hosts.cfg.nix
Normal file
19
tests/on-device/config-flake-hosts.cfg.nix
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
{ pkgs, ... }:
|
||||
|
||||
{
|
||||
system.stateVersion = "23.05";
|
||||
|
||||
networking = {
|
||||
hosts."127.0.0.2" = [ "a" "b" ];
|
||||
|
||||
extraHosts = ''
|
||||
127.0.0.3 c
|
||||
'';
|
||||
|
||||
hostFiles = [
|
||||
(pkgs.writeText "hosts" ''
|
||||
127.0.0.4 d
|
||||
'')
|
||||
];
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue