mirror of
https://github.com/CHN-beta/nixos.git
synced 2026-01-12 04:39:23 +08:00
flake: move dns config
This commit is contained in:
17
flake.nix
17
flake.nix
@@ -85,23 +85,10 @@
|
||||
config =
|
||||
{
|
||||
branch = import ./flake/branch.nix;
|
||||
dns =
|
||||
{
|
||||
"chn.moe" = import ./flake/dns/config/chn.moe.nix localLib;
|
||||
wireguard = import ./flake/dns/config/wireguard.nix;
|
||||
};
|
||||
dns = inputs.self.packages.x86_64-linux.dns-push.meta.config;
|
||||
};
|
||||
devShells.x86_64-linux = import ./flake/dev.nix { inherit inputs; };
|
||||
src = import ./flake/src.nix { inherit inputs; };
|
||||
apps.x86_64-linux.dns-push =
|
||||
{
|
||||
type = "app";
|
||||
program = let inherit (inputs.self.packages.x86_64-linux) pkgs; in builtins.toString (pkgs.callPackage ./flake/dns
|
||||
{
|
||||
inherit localLib;
|
||||
tokenPath = inputs.self.nixosConfigurations.pc.config.sops.secrets."acme/token".path;
|
||||
octodns = pkgs.octodns.withProviders (_: [ pkgs.localPackages.octodns-cloudflare ]);
|
||||
});
|
||||
};
|
||||
apps.x86_64-linux.dns-push = { type = "app"; program = inputs.self.packages.x86_64-linux.dns-push; };
|
||||
};
|
||||
}
|
||||
|
||||
@@ -1,18 +1,21 @@
|
||||
{ writeShellScript, writeTextDir, symlinkJoin, octodns, tokenPath, localLib }:
|
||||
{ writeShellScript, writeTextDir, symlinkJoin, octodns, tokenPath, localLib, lib }:
|
||||
let
|
||||
addTtl = config:
|
||||
let addTtl' = attrs: attrs // { octodns.cloudflare.auto-ttl = true; };
|
||||
in builtins.mapAttrs (n: v: if builtins.isList v then builtins.map addTtl' v else addTtl' v) config;
|
||||
config = symlinkJoin
|
||||
config = builtins.listToAttrs (builtins.map
|
||||
(domain: { name = domain; value = import ./config/${domain}.nix localLib; })
|
||||
[ "chn.moe" "nekomia.moe" "mirism.one" ]);
|
||||
configDir = symlinkJoin
|
||||
{
|
||||
name = "config";
|
||||
paths = builtins.map
|
||||
(domain: writeTextDir "${domain}.yaml" (builtins.toJSON (addTtl (import ./config/${domain}.nix localLib))))
|
||||
[ "chn.moe" "nekomia.moe" "mirism.one" ];
|
||||
(domain: writeTextDir "${domain.name}.yaml" (builtins.toJSON (addTtl domain.value)))
|
||||
(localLib.attrsToList config);
|
||||
};
|
||||
in writeShellScript "dns-push"
|
||||
in lib.addMetaAttrs { config = config // { wireguard = import ./config/wireguard.nix; }; } (writeShellScript "dns-push"
|
||||
''
|
||||
export OCTODNS_CONFIG=${config}
|
||||
export CLOUDFLARE_TOKEN=$(cat ${tokenPath})
|
||||
${octodns}/bin/octodns-sync --config-file ${./config.yaml} --doit --force
|
||||
''
|
||||
'')
|
||||
|
||||
@@ -38,6 +38,12 @@
|
||||
else if builtins.isList x then builtins.concatMap getDrv x
|
||||
else [];
|
||||
in pkgs.writeClosure (getDrv (inputs.self.outputs.src));
|
||||
dns-push = pkgs.callPackage ./dns
|
||||
{
|
||||
inherit localLib;
|
||||
tokenPath = inputs.self.nixosConfigurations.pc.config.sops.secrets."acme/token".path;
|
||||
octodns = pkgs.octodns.withProviders (_: [ pkgs.localPackages.octodns-cloudflare ]);
|
||||
};
|
||||
}
|
||||
// (builtins.listToAttrs (builtins.map
|
||||
(system: { inherit (system) name; value = system.value.config.system.build.toplevel; })
|
||||
|
||||
Reference in New Issue
Block a user