# Pastebin VzhFpDgb { pkgs, lib, config, ... }: let hosts = pkgs.writeText "hosts" '' ## # Host Database # # localhost is used to configure the loopback interface # when the system is booting. Do not change this entry. ## 127.0.0.1 localhost 255.255.255.255 broadcasthost ::1 localhost ${config.networking.extraHosts} ''; in { options.networking.extraHosts = lib.mkOption { type = lib.types.lines; default = ""; }; config = lib.mkIf (config.networking.extraHosts != "") { system.activationScripts.extraActivation.text = '' echo 'setting up /etc/hosts...' >&2 if [ -e /etc/hosts ]; then storePath=$(head -n 1 /etc/hosts | sed 's|[^/]*\(/nix/store/.*\)$|\1|') if [ ! -e "$storePath" ] || ! diff <(tail -n +2 /etc/hosts) "$storePath"; then echo "warning: not copying ${hosts} because /etc/hosts already exists and is not tagged with an identical store path, skipping..." >&2 skip=1 fi fi if [ ''${skip:-0} != 1 ]; then echo '# '${hosts} > /etc/hosts cat ${hosts} >> /etc/hosts fi ''; }; }