diff --git a/flake.lock b/flake.lock index e5cf619..31b6f6a 100644 --- a/flake.lock +++ b/flake.lock @@ -7,15 +7,16 @@ ] }, "locked": { - "lastModified": 1699569089, - "narHash": "sha256-MdOnyXrmMdVU9o7GpcbWKgehoK9L76ihp8rTikPcC1k=", - "owner": "lnl7", + "lastModified": 1699735666, + "narHash": "sha256-LxKjDY9Fgjy4bHfvqBl9RwuPSP47hgQA21Ffjtrypaw=", + "owner": "willemml", "repo": "nix-darwin", - "rev": "c8f385766ba076a096caa794309c40f89894d88a", + "rev": "215f56f908ed88d5660d93e064af439a7fb5a7bf", "type": "github" }, "original": { - "owner": "lnl7", + "owner": "willemml", + "ref": "feat/networking.hosts", "repo": "nix-darwin", "type": "github" } diff --git a/flake.nix b/flake.nix index 77a5b6d..66812a3 100644 --- a/flake.nix +++ b/flake.nix @@ -4,7 +4,7 @@ inputs = { nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - darwin.url = "github:lnl7/nix-darwin"; + darwin.url = "github:willemml/nix-darwin?ref=feat/networking.hosts"; darwin.inputs.nixpkgs.follows = "nixpkgs"; emacs-overlay.url = "github:nix-community/emacs-overlay"; diff --git a/nixos/hosts/zeus.nix b/nixos/hosts/zeus.nix index 7bbc0cb..a8e0768 100644 --- a/nixos/hosts/zeus.nix +++ b/nixos/hosts/zeus.nix @@ -3,7 +3,6 @@ ../../common/system.nix ../modules/nix/link-inputs.nix ../modules/nix/use-flake-pkgs.nix - ../modules/darwin/hosts.nix ]; nix = { diff --git a/nixos/modules/darwin/hosts.nix b/nixos/modules/darwin/hosts.nix deleted file mode 100644 index f746d97..0000000 --- a/nixos/modules/darwin/hosts.nix +++ /dev/null @@ -1,85 +0,0 @@ -# copied from https://github.com/NixOS/nixpkgs/blob/85f1ba3e51676fa8cc604a3d863d729026a6b8eb/nixos/modules/config/networking.nix -# -# if you get an error saying operation not permitted, run the following command: -# sudo chflags nouchg,noschg /etc/hosts -{ - config, - lib, - pkgs, - ... -}: let - inherit (lib) types mkBefore; - inherit (lib.lists) optional; - inherit (lib.options) literalExpression literalMD; - inherit (lib.attrsets) attrNames filterAttrs; - inherit (lib.strings) concatStringsSep concatMapStrings; - cfg = config.networking; -in { - options = { - networking.hosts = lib.mkOption { - type = types.attrsOf (types.listOf types.str); - example = literalExpression '' - { - "127.0.0.1" = [ "foo.bar.baz" ]; - "192.168.0.2" = [ "fileserver.local" "nameserver.local" ]; - }; - ''; - description = lib.mdDoc '' - Locally defined maps of hostnames to IP addresses. - ''; - }; - - networking.hostFiles = lib.mkOption { - type = types.listOf types.path; - defaultText = literalMD "Hosts from {option}`networking.hosts` and {option}`networking.extraHosts`"; - example = literalExpression ''[ "''${pkgs.my-blocklist-package}/share/my-blocklist/hosts" ]''; - description = lib.mdDoc '' - Files that should be concatenated together to form {file}`/etc/hosts`. - ''; - }; - - networking.extraHosts = lib.mkOption { - type = types.lines; - default = ""; - example = "192.168.0.1 lanlocalhost"; - description = lib.mdDoc '' - Additional verbatim entries to be appended to {file}`/etc/hosts`. - For adding hosts from derivation results, use {option}`networking.hostFiles` instead. - ''; - }; - }; - - config = { - networking.hosts = let - hostnames = - optional (cfg.hostName != "") cfg.hostName; # Then the hostname (without the domain) - in { - "127.0.0.1" = hostnames; - "::1" = hostnames; - }; - - networking.hostFiles = let - # Note: localhostHosts has to appear first in /etc/hosts so that 127.0.0.1 - # resolves back to "localhost" (as some applications assume) instead of - # the FQDN! By default "networking.hosts" also contains entries for the - # FQDN so that e.g. "hostname -f" works correctly. - localhostHosts = pkgs.writeText "localhost-hosts" '' - 127.0.0.1 localhost - ::1 localhost - 255.255.255.255 broadcasthost - ''; - stringHosts = let - oneToString = set: ip: ip + " " + concatStringsSep " " set.${ip} + "\n"; - allToString = set: concatMapStrings (oneToString set) (attrNames set); - in - pkgs.writeText "string-hosts" (allToString (filterAttrs (_: v: v != []) cfg.hosts)); - extraHosts = pkgs.writeText "extra-hosts" cfg.extraHosts; - in - mkBefore [localhostHosts stringHosts extraHosts]; - - environment.etc.hosts = { - copy = true; - source = pkgs.concatText "hosts" cfg.hostFiles; - }; - }; -}