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