mirror of
https://github.com/gensokyo-zone/infrastructure.git
synced 2026-02-09 12:29:19 -08:00
chore: nf-fmt-nix
This commit is contained in:
parent
7486517713
commit
9903866044
160 changed files with 4570 additions and 3019 deletions
|
|
@ -9,14 +9,18 @@
|
|||
inherit (lib.strings) concatStringsSep;
|
||||
inherit (config.system) nssDatabases;
|
||||
inherit (config) networking;
|
||||
netgroupMemberModule = { config, name, ... }: {
|
||||
netgroupMemberModule = {
|
||||
config,
|
||||
name,
|
||||
...
|
||||
}: {
|
||||
options = with lib.types; {
|
||||
hostname = mkOption {
|
||||
type = str;
|
||||
default = name;
|
||||
};
|
||||
user = mkOption {
|
||||
type = either (enum [ null "-" ]) str;
|
||||
type = either (enum [null "-"]) str;
|
||||
default = "-";
|
||||
};
|
||||
domain = mkOption {
|
||||
|
|
@ -32,7 +36,11 @@
|
|||
triple = mkOptionDefault "(${config.hostname},${toString config.user},${config.domain})";
|
||||
};
|
||||
};
|
||||
netgroupModule = { config, name, ... }: {
|
||||
netgroupModule = {
|
||||
config,
|
||||
name,
|
||||
...
|
||||
}: {
|
||||
options = with lib.types; {
|
||||
name = mkOption {
|
||||
type = str;
|
||||
|
|
@ -40,14 +48,14 @@
|
|||
};
|
||||
members = mkOption {
|
||||
type = attrsOf (submodule netgroupMemberModule);
|
||||
default = { };
|
||||
default = {};
|
||||
};
|
||||
fileLine = mkOption {
|
||||
type = str;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
fileLine = mkOptionDefault (concatStringsSep " " ([ config.name ] ++ mapAttrsToList (_: member: member.triple) config.members));
|
||||
fileLine = mkOptionDefault (concatStringsSep " " ([config.name] ++ mapAttrsToList (_: member: member.triple) config.members));
|
||||
};
|
||||
};
|
||||
in {
|
||||
|
|
@ -60,7 +68,7 @@ in {
|
|||
networking = {
|
||||
netgroups = mkOption {
|
||||
type = attrsOf (submodule netgroupModule);
|
||||
default = { };
|
||||
default = {};
|
||||
};
|
||||
extraNetgroups = mkOption {
|
||||
type = lines;
|
||||
|
|
@ -71,17 +79,17 @@ in {
|
|||
config = {
|
||||
system.nssDatabases = {
|
||||
netgroup = mkMerge [
|
||||
(mkBefore [ "files" ])
|
||||
(mkAfter [ "nis" ])
|
||||
(mkBefore ["files"])
|
||||
(mkAfter ["nis"])
|
||||
];
|
||||
};
|
||||
environment.etc."nsswitch.conf".text = mkIf (nssDatabases.netgroup != [ ]) (mkAfter ''
|
||||
environment.etc."nsswitch.conf".text = mkIf (nssDatabases.netgroup != []) (mkAfter ''
|
||||
netgroup: ${concatStringsSep " " nssDatabases.netgroup}
|
||||
'');
|
||||
environment.etc."netgroup" = mkIf (networking.netgroups != { } || networking.extraNetgroups != "") {
|
||||
environment.etc."netgroup" = mkIf (networking.netgroups != {} || networking.extraNetgroups != "") {
|
||||
text = mkMerge (
|
||||
mapAttrsToList (_: ng: ng.fileLine) networking.netgroups
|
||||
++ [ networking.extraNetgroups ]
|
||||
++ [networking.extraNetgroups]
|
||||
);
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,8 @@
|
|||
{config, lib, ...}: let
|
||||
{
|
||||
config,
|
||||
lib,
|
||||
...
|
||||
}: let
|
||||
inherit (lib.options) mkOption mkEnableOption;
|
||||
inherit (lib.modules) mkIf mkOptionDefault;
|
||||
inherit (lib.lists) filter optional;
|
||||
|
|
@ -7,21 +11,32 @@
|
|||
enabledNameservers = filter (ns: ns.enable) (config.networking.nameservers');
|
||||
nameserverModule = {config, ...}: let
|
||||
dnsPort = 53;
|
||||
mkResolvedValue = { address, port, interface ? null, host ? null }: let
|
||||
mkResolvedValue = {
|
||||
address,
|
||||
port,
|
||||
interface ? null,
|
||||
host ? null,
|
||||
}: let
|
||||
isIpv6 = hasInfix ":" address;
|
||||
isPlain = port == dnsPort && interface == null && host == null;
|
||||
addr = if isIpv6 && !isPlain then "[${address}]" else address;
|
||||
in concatStrings (
|
||||
[ addr ]
|
||||
++ optional (port != dnsPort) ":${toString port}"
|
||||
++ optional (interface != null) "%${interface}"
|
||||
++ optional (host != null) "#${host}"
|
||||
);
|
||||
addr =
|
||||
if isIpv6 && !isPlain
|
||||
then "[${address}]"
|
||||
else address;
|
||||
in
|
||||
concatStrings (
|
||||
[addr]
|
||||
++ optional (port != dnsPort) ":${toString port}"
|
||||
++ optional (interface != null) "%${interface}"
|
||||
++ optional (host != null) "#${host}"
|
||||
);
|
||||
in {
|
||||
options = with lib.types; {
|
||||
enable = mkEnableOption "nameserver" // {
|
||||
default = true;
|
||||
};
|
||||
enable =
|
||||
mkEnableOption "nameserver"
|
||||
// {
|
||||
default = true;
|
||||
};
|
||||
address = mkOption {
|
||||
type = str;
|
||||
};
|
||||
|
|
@ -59,12 +74,16 @@ in {
|
|||
options.networking = with lib.types; {
|
||||
nameservers' = mkOption {
|
||||
type = listOf (submodule nameserverModule);
|
||||
default = { };
|
||||
default = {};
|
||||
};
|
||||
};
|
||||
config = {
|
||||
networking.nameservers = mkIf (config.networking.nameservers' != [ ]) (
|
||||
map (ns: if resolved.enable then ns.resolvedValue else ns.value) enabledNameservers
|
||||
networking.nameservers = mkIf (config.networking.nameservers' != []) (
|
||||
map (ns:
|
||||
if resolved.enable
|
||||
then ns.resolvedValue
|
||||
else ns.value)
|
||||
enabledNameservers
|
||||
);
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue