From 1fcc7727a61ae16cc0413daad874cd0e685cf58c Mon Sep 17 00:00:00 2001 From: ibizaman Date: Mon, 27 Jan 2025 13:28:35 +0100 Subject: [PATCH] refactor tests and rebase --- .github/workflows/test.yml | 4 ++-- modules/networking/default.nix | 1 + tests/networking-hosts.nix | 17 +++++------------ 3 files changed, 8 insertions(+), 14 deletions(-) diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 4dad1a7bc..e80c3ac0e 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -53,7 +53,7 @@ jobs: nixConfHash=$(shasum -a 256 /etc/nix/nix.conf | cut -d ' ' -f 1) etcHostsHash=$(shasum -a 256 /etc/hosts | cut -d ' ' -f 1) /usr/bin/sed -i.bak \ - "s/# programs.fish.enable = true;/nix.settings.access-tokens = [ \"github.com=\${{ secrets.GITHUB_TOKEN }}\" ]; environment.etc.\"nix\/nix.conf\".knownSha256Hashes = [ \"$nixConfHash\" ];/" \ + "s/# programs.fish.enable = true;/nix.settings.access-tokens = [ \"github.com=\${{ secrets.GITHUB_TOKEN }}\" ]; environment.etc.\"nix\/nix.conf\".knownSha256Hashes = [ \"$nixConfHash\" ]; environment.etc.hosts.knownSha256Hashes = [ \"$etcHostsHash\" ];/" \ ~/.config/nix-darwin/configuration.nix nix run .#darwin-rebuild \ @@ -99,7 +99,7 @@ jobs: nixConfHash=$(shasum -a 256 /etc/nix/nix.conf | cut -d ' ' -f 1) etcHostsHash=$(shasum -a 256 /etc/hosts | cut -d ' ' -f 1) /usr/bin/sed -i.bak \ - "s/# programs.fish.enable = true;/nix.settings.access-tokens = [ \"github.com=\${{ secrets.GITHUB_TOKEN }}\" ]; environment.etc.\"nix\/nix.conf\".knownSha256Hashes = [ \"$nixConfHash\" ]; environment.etc.hosts.knownSha256Hashes = [ \"$etcHostsHash\" ]; environment.etc.hosts.knownSha256Hashes = [ \"$etcHostsHash\" ];/" \ + "s/# programs.fish.enable = true;/nix.settings.access-tokens = [ \"github.com=\${{ secrets.GITHUB_TOKEN }}\" ]; environment.etc.\"nix\/nix.conf\".knownSha256Hashes = [ \"$nixConfHash\" ]; environment.etc.hosts.knownSha256Hashes = [ \"$etcHostsHash\" ];/" \ flake.nix /usr/bin/sed -i.bak \ 's/nixpkgs.hostPlatform = "aarch64-darwin";/nixpkgs.hostPlatform = "'$(nix eval --expr builtins.currentSystem --impure --raw)'";/' \ diff --git a/modules/networking/default.nix b/modules/networking/default.nix index 94d394c86..9b697590d 100644 --- a/modules/networking/default.nix +++ b/modules/networking/default.nix @@ -202,6 +202,7 @@ in environment.etc.hosts = { knownSha256Hashes = [ + # Comes from MacOS: Darwin 24.1.0 Darwin Kernel Version 24.1.0. "c7dd0e2ed261ce76d76f852596c5b54026b9a894fa481381ffd399b556c0e2da" ]; diff --git a/tests/networking-hosts.nix b/tests/networking-hosts.nix index f9edd6550..756e95c47 100644 --- a/tests/networking-hosts.nix +++ b/tests/networking-hosts.nix @@ -7,21 +7,14 @@ }; test = '' + set -v echo checking /etc/hosts file >&2 file=${config.out}/etc/hosts - if ! grep '127.0.0.1' $file | head -n1 | grep localhost$; then - exit 1 - fi - if ! grep '127.0.0.1' $file | tail -n1 | grep my.super.host$; then - exit 2 - fi - if ! grep '::1' $file | grep localhost$; then - exit 3 - fi - if ! grep '10.0.0.1' $file | grep my.super.host\ my.other.host$; then - exit 4 - fi + grep '127.0.0.1' $file | head -n1 | grep localhost$ || exit 1 + grep '127.0.0.1' $file | tail -n1 | grep my.super.host$ || exit 2 + grep '::1' $file | grep localhost$ || exit 3 + grep '10.0.0.1' $file | grep my.super.host\ my.other.host$ || exit 4 ''; }