From b056a38897086e58543d24b360604fbe756898f7 Mon Sep 17 00:00:00 2001 From: Guanran Wang Date: Tue, 7 Nov 2023 15:08:34 +0800 Subject: [PATCH] nixos,networking: add myFlake.nixos.networking.dns --- flake.nix | 10 ++++--- nixos/networking/dns.nix | 34 +++++++++++++++++++----- nixos/presets/core/networking/alidns.nix | 9 ------- 3 files changed, 33 insertions(+), 20 deletions(-) delete mode 100644 nixos/presets/core/networking/alidns.nix diff --git a/flake.nix b/flake.nix index bfa4637..dfe7b6a 100755 --- a/flake.nix +++ b/flake.nix @@ -171,7 +171,6 @@ ./nixos/presets/desktop.nix ./nixos/presets/core/zram-generator.nix ./nixos/presets/core/boot/no-bootloader-menu.nix - ./nixos/presets/core/networking/alidns.nix ./nixos/presets/desktop/gaming.nix ./nixos/presets/desktop/virtualbox.nix ./nixos/presets/desktop/wayland.nix @@ -185,11 +184,14 @@ ./machines/nixos/81fw-lenovo-legion-y7000/machine-1 { - # extra home-manager stuff - home-manager.users.guanranwang = import ./users/guanranwang/home-manager/nixos/presets/desktop/gaming.nix; - networking.hostName = "81FW-NixOS"; # Hostname time.timeZone = "Asia/Shanghai"; # Timezone + + ### Home-Manager + home-manager.users.guanranwang = import ./users/guanranwang/home-manager/nixos/presets/desktop/gaming.nix; + + ### Options + myFlake.nixos.networking.dns = "alidns"; } ]; }; diff --git a/nixos/networking/dns.nix b/nixos/networking/dns.nix index 27b57e4..7655a4b 100644 --- a/nixos/networking/dns.nix +++ b/nixos/networking/dns.nix @@ -1,9 +1,29 @@ -{...}: { - networking.nameservers = [ - ### Google DNS - "8.8.8.8" - "8.8.4.4" - "2001:4860:4860::8888" - "2001:4860:4860::8844" +{ + lib, + config, + ... +}: { + options.myFlake.nixos.networking.dns = lib.mkOption { + type = lib.types.string; + default = "google"; + example = "alidns"; + description = "Select your DNS provider"; + }; + + config.networking.nameservers = lib.mkMerge [ + (lib.mkIf (config.myFlake.nixos.networking.dns == "google") [ + ### Google DNS + "8.8.8.8" + "8.8.4.4" + "2001:4860:4860::8888" + "2001:4860:4860::8844" + ]) + (lib.mkIf (config.myFlake.nixos.networking.dns == "alidns") [ + ### AliDNS + "223.5.5.5" + "223.6.6.6" + "2400:3200::1" + "2400:3200:baba::1" + ]) ]; } diff --git a/nixos/presets/core/networking/alidns.nix b/nixos/presets/core/networking/alidns.nix deleted file mode 100644 index 9085cdf..0000000 --- a/nixos/presets/core/networking/alidns.nix +++ /dev/null @@ -1,9 +0,0 @@ -{lib, ...}: { - networking.nameservers = lib.mkForce [ - ### AliDNS - "223.5.5.5" - "223.6.6.6" - "2400:3200::1" - "2400:3200:baba::1" - ]; -}