feat: change module import method
This commit is contained in:
parent
da405d1155
commit
1c7a94546d
@ -1,11 +1,38 @@
|
|||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) filterAttrs;
|
inherit (builtins)
|
||||||
inherit (builtins) attrNames readDir;
|
attrValues
|
||||||
moduleDirs =
|
concatLists
|
||||||
|
mapAttrs
|
||||||
|
readDir
|
||||||
|
;
|
||||||
|
inherit (lib) hasSuffix remove;
|
||||||
|
|
||||||
|
filterRoot = remove (./. + "/default.nix");
|
||||||
|
|
||||||
|
findModules =
|
||||||
dir:
|
dir:
|
||||||
map (name: dir + "/${name}") (attrNames (filterAttrs (_: type: type == "directory") (readDir dir)));
|
concatLists (
|
||||||
|
attrValues (
|
||||||
|
mapAttrs (
|
||||||
|
name: type:
|
||||||
|
if type == "directory" then
|
||||||
|
if (readDir (dir + "/${name}")) ? "default.nix" then
|
||||||
|
[
|
||||||
|
(dir + "/${name}")
|
||||||
|
]
|
||||||
|
else
|
||||||
|
findModules (dir + "/${name}")
|
||||||
|
else if (type == "regular" && (hasSuffix ".nix" name)) then
|
||||||
|
[
|
||||||
|
(dir + "/${name}")
|
||||||
|
]
|
||||||
|
else
|
||||||
|
[ ]
|
||||||
|
) (readDir dir)
|
||||||
|
)
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = moduleDirs ./.;
|
imports = filterRoot (findModules ./.);
|
||||||
}
|
}
|
||||||
|
@ -1,4 +0,0 @@
|
|||||||
{ ... }:
|
|
||||||
{
|
|
||||||
imports = [ ./postgresql.nix ];
|
|
||||||
}
|
|
@ -1,11 +1,38 @@
|
|||||||
{ lib, ... }:
|
{ lib, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) filterAttrs;
|
inherit (lib) hasSuffix remove;
|
||||||
inherit (builtins) attrNames readDir;
|
inherit (builtins)
|
||||||
moduleDirs =
|
attrValues
|
||||||
|
concatLists
|
||||||
|
mapAttrs
|
||||||
|
readDir
|
||||||
|
;
|
||||||
|
|
||||||
|
filterRoot = remove (./. + "/default.nix");
|
||||||
|
|
||||||
|
findModules =
|
||||||
dir:
|
dir:
|
||||||
map (name: dir + "/${name}") (attrNames (filterAttrs (_: type: type == "directory") (readDir dir)));
|
concatLists (
|
||||||
|
attrValues (
|
||||||
|
mapAttrs (
|
||||||
|
name: type:
|
||||||
|
if type == "directory" then
|
||||||
|
if (readDir (dir + "/${name}")) ? "default.nix" then
|
||||||
|
[
|
||||||
|
(dir + "/${name}")
|
||||||
|
]
|
||||||
|
else
|
||||||
|
findModules (dir + "/${name}")
|
||||||
|
else if (type == "regular" && (hasSuffix ".nix" name)) then
|
||||||
|
[
|
||||||
|
(dir + "/${name}")
|
||||||
|
]
|
||||||
|
else
|
||||||
|
[ ]
|
||||||
|
) (readDir dir)
|
||||||
|
)
|
||||||
|
);
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
imports = moduleDirs ./.;
|
imports = filterRoot (findModules ./.);
|
||||||
}
|
}
|
||||||
|
@ -1,7 +0,0 @@
|
|||||||
{ ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
./btrfs.nix
|
|
||||||
./zfs.nix
|
|
||||||
];
|
|
||||||
}
|
|
@ -5,26 +5,45 @@
|
|||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
let
|
let
|
||||||
|
inherit (builtins) concatLists filter;
|
||||||
inherit (lib)
|
inherit (lib)
|
||||||
|
getExe
|
||||||
mkDefault
|
mkDefault
|
||||||
mkEnableOption
|
mkEnableOption
|
||||||
mkForce
|
mkForce
|
||||||
mkIf
|
mkIf
|
||||||
mkOption
|
mkOption
|
||||||
optionals
|
|
||||||
;
|
;
|
||||||
inherit (lib.types)
|
inherit (lib.types)
|
||||||
bool
|
bool
|
||||||
listOf
|
listOf
|
||||||
nullOr
|
nullOr
|
||||||
str
|
str
|
||||||
|
submodule
|
||||||
;
|
;
|
||||||
cfg = config.ataraxia.network;
|
cfg = config.ataraxia.networkd;
|
||||||
|
|
||||||
|
ipAddressType = submodule {
|
||||||
|
options = {
|
||||||
|
address = mkOption {
|
||||||
|
type = str;
|
||||||
|
};
|
||||||
|
gateway = mkOption {
|
||||||
|
type = nullOr str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
dns = mkOption {
|
||||||
|
type = listOf str;
|
||||||
|
default = [ ];
|
||||||
|
};
|
||||||
|
gatewayOnLink = mkEnableOption "Enable GatewayOnLink";
|
||||||
|
};
|
||||||
|
};
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options.ataraxia.network = {
|
options.ataraxia.networkd = {
|
||||||
enable = mkEnableOption "Enable systemd-networkd bridged network";
|
enable = mkEnableOption "Enable systemd-networkd bridged network";
|
||||||
enableIPv6 = mkEnableOption "Enable IPv6";
|
disableIPv6 = mkEnableOption "Enable IPv6";
|
||||||
domain = mkOption {
|
domain = mkOption {
|
||||||
type = nullOr str;
|
type = nullOr str;
|
||||||
default = null;
|
default = null;
|
||||||
@ -35,6 +54,7 @@ in
|
|||||||
mac = mkOption {
|
mac = mkOption {
|
||||||
type = str;
|
type = str;
|
||||||
};
|
};
|
||||||
|
# TODO: implement disabling bridge
|
||||||
bridge = {
|
bridge = {
|
||||||
enable = mkOption {
|
enable = mkOption {
|
||||||
type = bool;
|
type = bool;
|
||||||
@ -45,31 +65,21 @@ in
|
|||||||
default = "br0";
|
default = "br0";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
ipv4 = {
|
ipv4 = mkOption {
|
||||||
address = mkOption {
|
type = listOf ipAddressType;
|
||||||
type = str;
|
default = [ ];
|
||||||
};
|
|
||||||
gateway = mkOption {
|
|
||||||
type = str;
|
|
||||||
};
|
|
||||||
dns = mkOption {
|
|
||||||
type = listOf str;
|
|
||||||
default = [ ];
|
|
||||||
};
|
|
||||||
gatewayOnLink = mkEnableOption "Enable GatewayOnLink";
|
|
||||||
};
|
};
|
||||||
ipv6 = {
|
ipv6 = mkOption {
|
||||||
address = mkOption {
|
type = listOf ipAddressType;
|
||||||
type = str;
|
default =
|
||||||
};
|
if !cfg.disableIPv6 then
|
||||||
gateway = mkOption {
|
[
|
||||||
type = str;
|
{
|
||||||
};
|
address = "fc00::1/64";
|
||||||
dns = mkOption {
|
}
|
||||||
type = listOf str;
|
]
|
||||||
default = [ ];
|
else
|
||||||
};
|
[ ];
|
||||||
gatewayOnLink = mkEnableOption "Enable GatewayOnLink";
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -77,11 +87,11 @@ in
|
|||||||
services.resolved.enable = true;
|
services.resolved.enable = true;
|
||||||
networking = {
|
networking = {
|
||||||
dhcpcd.enable = false;
|
dhcpcd.enable = false;
|
||||||
domain = mkIf (cfg ? domain) cfg.domain;
|
domain = cfg.domain;
|
||||||
enableIPv6 = cfg.enableIPv6;
|
enableIPv6 = !cfg.disableIPv6;
|
||||||
nftables.enable = true;
|
nftables.enable = true;
|
||||||
useDHCP = false;
|
useDHCP = false;
|
||||||
useNetworkd = false;
|
useNetworkd = true;
|
||||||
usePredictableInterfaceNames = mkForce true;
|
usePredictableInterfaceNames = mkForce true;
|
||||||
firewall = {
|
firewall = {
|
||||||
enable = true;
|
enable = true;
|
||||||
@ -111,37 +121,26 @@ in
|
|||||||
};
|
};
|
||||||
"40-${cfg.bridge.name}" = {
|
"40-${cfg.bridge.name}" = {
|
||||||
matchConfig.Name = cfg.bridge.name;
|
matchConfig.Name = cfg.bridge.name;
|
||||||
address =
|
address = map (ip: ip.address) (cfg.ipv4 ++ cfg.ipv6);
|
||||||
[
|
dns = concatLists (map (ip: ip.dns) (cfg.ipv4 ++ cfg.ipv6));
|
||||||
cfg.ipv4.address
|
|
||||||
]
|
|
||||||
++ optionals cfg.enableIPv6 [
|
|
||||||
cfg.ipv6.address
|
|
||||||
"fc00::1/64"
|
|
||||||
];
|
|
||||||
dns = cfg.ipv4.dns ++ optionals cfg.enableIPv6 cfg.ipv6.dns;
|
|
||||||
networkConfig.LinkLocalAddressing = "no";
|
networkConfig.LinkLocalAddressing = "no";
|
||||||
linkConfig.RequiredForOnline = "routable";
|
linkConfig.RequiredForOnline = "routable";
|
||||||
routes =
|
routes =
|
||||||
[
|
let
|
||||||
{
|
filteredRoutes = filter (ip: ip.gateway != null) (cfg.ipv4 ++ cfg.ipv6);
|
||||||
Gateway = cfg.ipv4.gateway;
|
routes = map (x: {
|
||||||
GatewayOnLink = mkIf cfg.ipv4.gatewayOnLink true;
|
Gateway = x.gateway;
|
||||||
}
|
GatewayOnLink = x.gatewayOnLink;
|
||||||
]
|
}) filteredRoutes;
|
||||||
++ optionals cfg.enableIPv6 [
|
in
|
||||||
{
|
routes;
|
||||||
Gateway = cfg.ipv6.gateway;
|
|
||||||
GatewayOnLink = mkIf cfg.ipv4.gatewayOnLink true;
|
|
||||||
}
|
|
||||||
];
|
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
system.activationScripts.udp-gro-forwarding = mkIf cfg.bridge.enable {
|
system.activationScripts.udp-gro-forwarding = mkIf cfg.bridge.enable {
|
||||||
text = ''
|
text = ''
|
||||||
${pkgs.ethtool}/bin/ethtool -K ${cfg.bridge.name} rx-udp-gro-forwarding on rx-gro-list off
|
${getExe pkgs.ethtool} -K ${cfg.bridge.name} rx-udp-gro-forwarding on rx-gro-list off
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
@ -2,6 +2,7 @@
|
|||||||
config,
|
config,
|
||||||
lib,
|
lib,
|
||||||
inputs,
|
inputs,
|
||||||
|
flake-nixpkgs,
|
||||||
flake-self,
|
flake-self,
|
||||||
...
|
...
|
||||||
}:
|
}:
|
||||||
@ -15,7 +16,7 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
config = mkIf cfg.enable {
|
config = mkIf cfg.enable {
|
||||||
environment.etc.nixpkgs.source = config.nixpkgs.flake.source;
|
environment.etc.nixpkgs.source = flake-nixpkgs.outPath;
|
||||||
environment.etc.self.source = flake-self.outPath;
|
environment.etc.self.source = flake-self.outPath;
|
||||||
nix = {
|
nix = {
|
||||||
channel.enable = false;
|
channel.enable = false;
|
@ -1,7 +0,0 @@
|
|||||||
{ ... }:
|
|
||||||
{
|
|
||||||
imports = [
|
|
||||||
./hardened.nix
|
|
||||||
./minimal.nix
|
|
||||||
];
|
|
||||||
}
|
|
@ -1,4 +0,0 @@
|
|||||||
{ ... }:
|
|
||||||
{
|
|
||||||
imports = [ ./tailscale.nix ];
|
|
||||||
}
|
|
Loading…
x
Reference in New Issue
Block a user