mirror of
https://github.com/Swarsel/.dotfiles.git
synced 2026-04-14 21:29:12 +02:00
feat[server]: first working microvm
This commit is contained in:
parent
e00defbd83
commit
2f4ebcba44
40 changed files with 759 additions and 194 deletions
|
|
@ -1,4 +1,4 @@
|
|||
{ self, lib, config, vars, ... }:
|
||||
{ self, lib, config, vars, withHomeManager, ... }:
|
||||
{
|
||||
options.swarselmodules.stylix = lib.mkEnableOption "stylix config";
|
||||
config = {
|
||||
|
|
@ -12,6 +12,7 @@
|
|||
image = config.swarselsystems.wallpaper;
|
||||
}
|
||||
vars.stylix);
|
||||
} // lib.optionalAttrs withHomeManager {
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
stylix = {
|
||||
targets = vars.stylixHomeTargets;
|
||||
|
|
|
|||
|
|
@ -1,19 +1,20 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
{ lib, config, pkgs, withHomeManager, ... }:
|
||||
let
|
||||
inherit (config.swarselsystems) mainUser;
|
||||
in
|
||||
{
|
||||
options.swarselmodules.sway = lib.mkEnableOption "sway config";
|
||||
config = lib.mkIf config.swarselmodules.sway {
|
||||
programs.sway = {
|
||||
enable = true;
|
||||
package = pkgs.swayfx;
|
||||
wrapperFeatures = {
|
||||
base = true;
|
||||
gtk = true;
|
||||
config = lib.mkIf config.swarselmodules.sway
|
||||
{
|
||||
programs.sway = {
|
||||
enable = true;
|
||||
package = pkgs.swayfx;
|
||||
wrapperFeatures = {
|
||||
base = true;
|
||||
gtk = true;
|
||||
};
|
||||
};
|
||||
|
||||
inherit (config.home-manager.users.${mainUser}.wayland.windowManager.sway) extraSessionCommands;
|
||||
};
|
||||
} // lib.optionalAttrs withHomeManager {
|
||||
inherit (config.home-manager.users.${mainUser}.wayland.windowManager.sway) extraSessionCommands;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -138,6 +138,10 @@ in
|
|||
type = types.nullOr types.str;
|
||||
default = null;
|
||||
};
|
||||
isHome = mkOption {
|
||||
type = types.bool;
|
||||
default = false;
|
||||
};
|
||||
};
|
||||
})
|
||||
);
|
||||
|
|
@ -188,6 +192,9 @@ in
|
|||
wanAddress6 = mkOption {
|
||||
type = types.nullOr types.net.ipv6;
|
||||
};
|
||||
isHome = mkOption {
|
||||
type = types.bool;
|
||||
};
|
||||
};
|
||||
}
|
||||
);
|
||||
|
|
|
|||
|
|
@ -1,45 +1,47 @@
|
|||
{ self, lib, config, globals, ... }:
|
||||
{ self, lib, config, globals, withHomeManager, ... }:
|
||||
let
|
||||
inherit (config.swarselsystems) mainUser homeDir;
|
||||
inherit (config.repo.secrets.common.emacs) radicaleUser;
|
||||
modules = config.home-manager.users.${mainUser}.swarselmodules;
|
||||
|
||||
certsSopsFile = self + /secrets/repo/certs.yaml;
|
||||
in
|
||||
{
|
||||
config = lib.mkIf config.swarselsystems.withHomeManager {
|
||||
sops = {
|
||||
secrets = (lib.optionalAttrs modules.mail
|
||||
{
|
||||
config = { } // lib.optionalAttrs withHomeManager {
|
||||
sops =
|
||||
let
|
||||
modules = config.home-manager.users.${mainUser}.swarselmodules;
|
||||
in
|
||||
{
|
||||
secrets = (lib.optionalAttrs modules.mail {
|
||||
address1-token = { owner = mainUser; };
|
||||
address2-token = { owner = mainUser; };
|
||||
address3-token = { owner = mainUser; };
|
||||
address4-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.waybar {
|
||||
github-notifications-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.emacs {
|
||||
fever-pw = { path = "${homeDir}/.emacs.d/.fever"; owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.zsh {
|
||||
croc-password = { owner = mainUser; };
|
||||
github-nixpkgs-review-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.emacs {
|
||||
emacs-radicale-pw = { owner = mainUser; };
|
||||
github-forge-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs (modules ? optional-work) {
|
||||
harica-root-ca = { sopsFile = certsSopsFile; path = "${homeDir}/.aws/certs/harica-root.pem"; owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.anki {
|
||||
anki-user = { owner = mainUser; };
|
||||
anki-pw = { owner = mainUser; };
|
||||
});
|
||||
templates = {
|
||||
authinfo = lib.mkIf modules.emacs {
|
||||
path = "${homeDir}/.emacs.d/.authinfo";
|
||||
content = ''
|
||||
machine ${globals.services.radicale.domain} login ${radicaleUser} password ${config.sops.placeholder.emacs-radicale-pw}
|
||||
'';
|
||||
owner = mainUser;
|
||||
github-notifications-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.emacs {
|
||||
fever-pw = { path = "${homeDir}/.emacs.d/.fever"; owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.zsh {
|
||||
croc-password = { owner = mainUser; };
|
||||
github-nixpkgs-review-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.emacs {
|
||||
emacs-radicale-pw = { owner = mainUser; };
|
||||
github-forge-token = { owner = mainUser; };
|
||||
}) // (lib.optionalAttrs (modules ? optional-work) {
|
||||
harica-root-ca = { sopsFile = certsSopsFile; path = "${homeDir}/.aws/certs/harica-root.pem"; owner = mainUser; };
|
||||
}) // (lib.optionalAttrs modules.anki {
|
||||
anki-user = { owner = mainUser; };
|
||||
anki-pw = { owner = mainUser; };
|
||||
});
|
||||
templates = {
|
||||
authinfo = lib.mkIf modules.emacs {
|
||||
path = "${homeDir}/.emacs.d/.authinfo";
|
||||
content = ''
|
||||
machine ${globals.services.radicale.domain} login ${radicaleUser} password ${config.sops.placeholder.emacs-radicale-pw}
|
||||
'';
|
||||
owner = mainUser;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
{ self, inputs, config, lib, homeLib, outputs, globals, nodes, minimal, configName, arch, type, ... }:
|
||||
{ self, inputs, config, lib, homeLib, outputs, globals, nodes, minimal, configName, arch, type, withHomeManager, ... }:
|
||||
{
|
||||
options.swarselmodules.home-manager = lib.mkEnableOption "home-manager";
|
||||
config = lib.mkIf config.swarselmodules.home-manager {
|
||||
home-manager = lib.mkIf config.swarselsystems.withHomeManager {
|
||||
home-manager = lib.mkIf withHomeManager {
|
||||
useGlobalPkgs = true;
|
||||
useUserPackages = true;
|
||||
verbose = true;
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ self, lib, pkgs, config, outputs, inputs, minimal, globals, ... }:
|
||||
{ self, lib, pkgs, config, outputs, inputs, minimal, globals, withHomeManager, ... }:
|
||||
let
|
||||
inherit (config.swarselsystems) mainUser;
|
||||
inherit (config.repo.secrets.common) atticPublicKey;
|
||||
|
|
@ -122,18 +122,19 @@ in
|
|||
nixpkgs = {
|
||||
overlays = [
|
||||
outputs.overlays.default
|
||||
] ++ lib.optionals withHomeManager [
|
||||
(final: prev:
|
||||
let
|
||||
additions = final: _: import "${self}/pkgs/config" {
|
||||
inherit self config lib;
|
||||
pkgs = final;
|
||||
homeConfig = config.home-manager.users.${config.swarselsystems.mainUser};
|
||||
homeConfig = config.home-manager.users.${config.swarselsystems.mainUser} or { };
|
||||
};
|
||||
in
|
||||
additions final prev
|
||||
)
|
||||
];
|
||||
config = {
|
||||
config = lib.mkIf (!config.swarselsystems.isMicroVM) {
|
||||
allowUnfree = true;
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@
|
|||
description = "Leon S";
|
||||
password = lib.mkIf (minimal || config.swarselsystems.isPublic) "setup";
|
||||
hashedPasswordFile = lib.mkIf (!minimal && !config.swarselsystems.isPublic) config.sops.secrets.main-user-hashed-pw.path;
|
||||
extraGroups = [ "wheel" ] ++ lib.optionals (!minimal) [ "networkmanager" "syncthing" "docker" "lp" "audio" "video" "vboxusers" "libvirtd" "scanner" ];
|
||||
extraGroups = [ "wheel" ] ++ lib.optionals (!minimal && !config.swarselsystems.isMicroVM) [ "networkmanager" "syncthing" "docker" "lp" "audio" "video" "vboxusers" "libvirtd" "scanner" ];
|
||||
packages = with pkgs; [ ];
|
||||
};
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ self, lib, config, outputs, globals, ... }:
|
||||
{ self, lib, config, outputs, globals, withHomeManager, ... }:
|
||||
let
|
||||
macUser = globals.user.work;
|
||||
in
|
||||
|
|
@ -7,20 +7,22 @@ in
|
|||
];
|
||||
|
||||
options.swarselmodules.optional.darwin = lib.mkEnableOption "optional darwin settings";
|
||||
config = lib.mkIf config.swarselmodules.optional.darwin {
|
||||
nix.settings.experimental-features = "nix-command flakes";
|
||||
nixpkgs = {
|
||||
hostPlatform = "x86_64-darwin";
|
||||
overlays = [ outputs.overlays.default ];
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
config = lib.mkIf config.swarselmodules.optional.darwin
|
||||
{
|
||||
nix.settings.experimental-features = "nix-command flakes";
|
||||
nixpkgs = {
|
||||
hostPlatform = "x86_64-darwin";
|
||||
overlays = [ outputs.overlays.default ];
|
||||
config = {
|
||||
allowUnfree = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
system.stateVersion = 4;
|
||||
} // lib.optionalAttrs withHomeManager {
|
||||
home-manager.users."${macUser}".imports = [
|
||||
"${self}/modules/home/darwin"
|
||||
];
|
||||
|
||||
system.stateVersion = 4;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# @ future me: dont panic, optionals and darwin are not read in by readNix
|
||||
{ lib, ... }:
|
||||
let
|
||||
importNames = lib.swarselsystems.readNix "modules/nixos";
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
# @ future me: dont panic, this file is not read in by readNix
|
||||
{ lib, ... }:
|
||||
let
|
||||
importNames = lib.swarselsystems.readNix "modules/nixos/optional";
|
||||
|
|
|
|||
|
|
@ -1,12 +1,7 @@
|
|||
{ self, config, ... }:
|
||||
{ self, lib, config, withHomeManager, ... }:
|
||||
{
|
||||
config = {
|
||||
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
"${self}/modules/home/optional/framework.nix"
|
||||
];
|
||||
};
|
||||
|
||||
services = {
|
||||
fwupd = {
|
||||
|
|
@ -29,5 +24,11 @@
|
|||
defaultStrategy = "lazy";
|
||||
};
|
||||
};
|
||||
} // lib.optionalAttrs withHomeManager {
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
"${self}/modules/home/optional/framework.nix"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,13 +1,7 @@
|
|||
{ self, pkgs, config, ... }:
|
||||
{ self, lib, pkgs, config, withHomeManager, ... }:
|
||||
{
|
||||
config = {
|
||||
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
"${self}/modules/home/optional/gaming.nix"
|
||||
];
|
||||
};
|
||||
|
||||
programs.steam = {
|
||||
enable = true;
|
||||
package = pkgs.steam;
|
||||
|
|
@ -41,6 +35,12 @@
|
|||
# ];
|
||||
# };
|
||||
# };
|
||||
} // lib.optionalAttrs withHomeManager {
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
"${self}/modules/home/optional/gaming.nix"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,28 @@
|
|||
_:
|
||||
{ self, inputs, ... }:
|
||||
{
|
||||
# imports = [
|
||||
# inputs.microvm.nixosModules.microvm
|
||||
# ];
|
||||
imports = [
|
||||
inputs.disko.nixosModules.disko
|
||||
inputs.home-manager.nixosModules.home-manager
|
||||
inputs.impermanence.nixosModules.impermanence
|
||||
inputs.lanzaboote.nixosModules.lanzaboote
|
||||
inputs.microvm.nixosModules.host
|
||||
inputs.microvm.nixosModules.microvm
|
||||
inputs.nix-index-database.nixosModules.nix-index
|
||||
inputs.nix-minecraft.nixosModules.minecraft-servers
|
||||
inputs.nix-topology.nixosModules.default
|
||||
inputs.nswitch-rcm-nix.nixosModules.nswitch-rcm
|
||||
inputs.simple-nixos-mailserver.nixosModules.default
|
||||
inputs.sops.nixosModules.sops
|
||||
inputs.stylix.nixosModules.stylix
|
||||
inputs.swarsel-nix.nixosModules.default
|
||||
inputs.nixos-nftables-firewall.nixosModules.default
|
||||
|
||||
config =
|
||||
{ };
|
||||
(inputs.nixos-extra-modules + "/modules/interface-naming.nix")
|
||||
|
||||
"${self}/modules/shared/meta.nix"
|
||||
];
|
||||
|
||||
config = {
|
||||
system.stateVersion = "23.05";
|
||||
};
|
||||
}
|
||||
|
|
|
|||
116
modules/nixos/optional/systemd-networkd-vlan.nix
Normal file
116
modules/nixos/optional/systemd-networkd-vlan.nix
Normal file
|
|
@ -0,0 +1,116 @@
|
|||
{ lib, config, globals, ... }:
|
||||
{
|
||||
|
||||
systemd.network = {
|
||||
wait-online.anyInterface = true;
|
||||
netdevs = {
|
||||
"10-veth" = {
|
||||
netdevConfig = {
|
||||
Kind = "veth";
|
||||
Name = "veth-br";
|
||||
};
|
||||
peerConfig = {
|
||||
Name = "veth-int";
|
||||
};
|
||||
};
|
||||
"20-br" = {
|
||||
netdevConfig = {
|
||||
Kind = "bridge";
|
||||
Name = "br";
|
||||
};
|
||||
};
|
||||
} // lib.flip lib.concatMapAttrs globals.networks.home-lan.vlans (
|
||||
vlanName: vlanCfg: {
|
||||
"30-vlan-${vlanName}" = {
|
||||
netdevConfig = {
|
||||
Kind = "vlan";
|
||||
Name = "vlan-${vlanName}";
|
||||
};
|
||||
vlanConfig.Id = vlanCfg.id;
|
||||
};
|
||||
"40-me-${vlanName}" = {
|
||||
netdevConfig = {
|
||||
Name = "me-${vlanName}";
|
||||
Kind = "macvlan";
|
||||
};
|
||||
extraConfig = ''
|
||||
[MACVLAN]
|
||||
Mode=bridge
|
||||
'';
|
||||
};
|
||||
}
|
||||
);
|
||||
networks = {
|
||||
"40-br" = {
|
||||
matchConfig.Name = "br";
|
||||
bridgeConfig = { };
|
||||
linkConfig = {
|
||||
ActivationPolicy = "always-up";
|
||||
RequiredForOnline = "no";
|
||||
};
|
||||
networkConfig = {
|
||||
ConfigureWithoutCarrier = true;
|
||||
LinkLocalAddressing = "no";
|
||||
};
|
||||
};
|
||||
"15-veth-br" = {
|
||||
matchConfig.Name = "veth-br";
|
||||
|
||||
linkConfig = {
|
||||
RequiredForOnline = "no";
|
||||
};
|
||||
|
||||
networkConfig = {
|
||||
Bridge = "br";
|
||||
};
|
||||
};
|
||||
"15-veth-int" = {
|
||||
matchConfig.Name = "veth-int";
|
||||
|
||||
linkConfig = {
|
||||
ActivationPolicy = "always-up";
|
||||
RequiredForOnline = "no";
|
||||
};
|
||||
|
||||
networkConfig = {
|
||||
ConfigureWithoutCarrier = true;
|
||||
LinkLocalAddressing = "no";
|
||||
};
|
||||
|
||||
vlan = map (name: "vlan-${name}") (builtins.attrNames globals.networks.home-lan.vlans);
|
||||
};
|
||||
"90-macvtap-ignore" = {
|
||||
matchConfig.Kind = "macvtap";
|
||||
linkConfig.ActivationPolicy = "manual";
|
||||
linkConfig.Unmanaged = "yes";
|
||||
};
|
||||
} // lib.flip lib.concatMapAttrs globals.networks.home-lan.vlans (
|
||||
vlanName: vlanCfg: {
|
||||
"30-vlan-${vlanName}" = {
|
||||
matchConfig.Name = "vlan-${vlanName}";
|
||||
networkConfig.LinkLocalAddressing = "no";
|
||||
networkConfig.MACVLAN = "me-${vlanName}";
|
||||
linkConfig.RequiredForOnline = "no";
|
||||
};
|
||||
"40-me-${vlanName}" = {
|
||||
address = [
|
||||
vlanCfg.hosts.${config.node.name}.cidrv4
|
||||
vlanCfg.hosts.${config.node.name}.cidrv6
|
||||
];
|
||||
matchConfig.Name = "me-${vlanName}";
|
||||
networkConfig = {
|
||||
IPv4Forwarding = "yes";
|
||||
IPv6PrivacyExtensions = "yes";
|
||||
IPv6SendRA = true;
|
||||
IPv6AcceptRA = false;
|
||||
};
|
||||
ipv6Prefixes = [
|
||||
{ Prefix = vlanCfg.cidrv6; }
|
||||
];
|
||||
linkConfig.RequiredForOnline = "routable";
|
||||
};
|
||||
}
|
||||
);
|
||||
};
|
||||
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
{ self, config, ... }:
|
||||
{ self, config, withHomeManager, ... }:
|
||||
{
|
||||
config = {
|
||||
config = { } // lib.optionalAttrs withHomeManager {
|
||||
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ self, lib, pkgs, config, ... }:
|
||||
{ self, lib, pkgs, config, withHomeManager, ... }:
|
||||
let
|
||||
inherit (config.swarselsystems) mainUser homeDir;
|
||||
iwd = config.networking.networkmanager.wifi.backend == "iwd";
|
||||
|
|
@ -18,12 +18,6 @@ in
|
|||
};
|
||||
config = {
|
||||
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
"${self}/modules/home/optional/work.nix"
|
||||
];
|
||||
};
|
||||
|
||||
sops =
|
||||
let
|
||||
secretNames = [
|
||||
|
|
@ -198,7 +192,7 @@ in
|
|||
openssh = {
|
||||
enable = true;
|
||||
extraConfig = ''
|
||||
'';
|
||||
'';
|
||||
};
|
||||
|
||||
syncthing = {
|
||||
|
|
@ -236,6 +230,13 @@ in
|
|||
# ];
|
||||
# };
|
||||
# };
|
||||
} // lib.optionalAttrs withHomeManager {
|
||||
|
||||
home-manager.users."${config.swarselsystems.mainUser}" = {
|
||||
imports = [
|
||||
"${self}/modules/home/optional/work.nix"
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
||||
|
|
|
|||
76
modules/nixos/server/kea.nix
Normal file
76
modules/nixos/server/kea.nix
Normal file
|
|
@ -0,0 +1,76 @@
|
|||
{ lib, config, globals, confLib, ... }:
|
||||
let
|
||||
inherit (confLib.gen { name = "kea"; dir = "/var/lib/private/kea"; }) serviceName serviceDir;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
swarselmodules.server.${serviceName} = lib.mkEnableOption "enable ${serviceName} on server";
|
||||
};
|
||||
config = lib.mkIf config.swarselmodules.server.${serviceName} {
|
||||
|
||||
environment.persistence."/persist".directories = lib.mkIf config.swarselsystems.isImpermanence [
|
||||
{ directory = serviceDir; mode = "0700"; }
|
||||
];
|
||||
|
||||
services.kea.dhcp4 = {
|
||||
enable = true;
|
||||
settings = {
|
||||
lease-database = {
|
||||
name = "/var/lib/kea/dhcp4.leases";
|
||||
persist = true;
|
||||
type = "memfile";
|
||||
};
|
||||
valid-lifetime = 86400;
|
||||
renew-timer = 3600;
|
||||
interfaces-config = {
|
||||
# XXX: BUG: why does this bind other macvtaps?
|
||||
interfaces = map (name: "me-${name}") (builtins.attrNames globals.networks.home-lan.vlans);
|
||||
service-sockets-max-retries = -1;
|
||||
};
|
||||
subnet4 = lib.flip lib.mapAttrsToList globals.networks.home-lan.vlans (
|
||||
vlanName: vlanCfg: {
|
||||
inherit (vlanCfg) id;
|
||||
interface = "me-${vlanName}";
|
||||
subnet = vlanCfg.cidrv4;
|
||||
pools = [
|
||||
{
|
||||
pool = "${lib.net.cidr.host 20 vlanCfg.cidrv4} - ${lib.net.cidr.host (-6) vlanCfg.cidrv4}";
|
||||
}
|
||||
];
|
||||
option-data =
|
||||
[
|
||||
{
|
||||
name = "routers";
|
||||
data = vlanCfg.hosts.hintbooth.ipv4; # FIXME: how to advertise v6 address also?
|
||||
}
|
||||
];
|
||||
# Advertise DNS server for VLANS that have internet access
|
||||
# ++
|
||||
# lib.optional
|
||||
# (lib.elem vlanName [
|
||||
# "services"
|
||||
# "home"
|
||||
# "devices"
|
||||
# "guests"
|
||||
# ])
|
||||
# {
|
||||
# name = "domain-name-servers";
|
||||
# data = globals.networks.home-lan.vlans.services.hosts.hintbooth-adguardhome.ipv4;
|
||||
# };
|
||||
reservations = lib.concatLists (
|
||||
lib.forEach (builtins.attrValues vlanCfg.hosts) (
|
||||
hostCfg:
|
||||
lib.optional (hostCfg.mac != null) {
|
||||
hw-address = hostCfg.mac;
|
||||
ip-address = hostCfg.ipv4;
|
||||
}
|
||||
)
|
||||
);
|
||||
}
|
||||
);
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
}
|
||||
74
modules/nixos/server/nftables.nix
Normal file
74
modules/nixos/server/nftables.nix
Normal file
|
|
@ -0,0 +1,74 @@
|
|||
{ lib, config, confLib, ... }:
|
||||
let
|
||||
inherit (confLib.gen { name = "nftables"; }) serviceName;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
swarselmodules.${serviceName} = lib.mkEnableOption "enable ${serviceName} on server";
|
||||
};
|
||||
config = lib.mkIf config.swarselmodules.${serviceName} {
|
||||
|
||||
networking.nftables = {
|
||||
stopRuleset = lib.mkDefault ''
|
||||
table inet filter {
|
||||
chain input {
|
||||
type filter hook input priority filter; policy drop;
|
||||
ct state invalid drop
|
||||
ct state {established, related} accept
|
||||
|
||||
iifname lo accept
|
||||
meta l4proto ipv6-icmp accept
|
||||
meta l4proto icmp accept
|
||||
ip protocol igmp accept
|
||||
tcp dport ${toString (lib.head config.services.openssh.ports)} accept
|
||||
}
|
||||
chain forward {
|
||||
type filter hook forward priority filter; policy drop;
|
||||
}
|
||||
chain output {
|
||||
type filter hook output priority filter; policy accept;
|
||||
}
|
||||
}
|
||||
'';
|
||||
|
||||
firewall = {
|
||||
enable = true;
|
||||
localZoneName = "local";
|
||||
snippets = {
|
||||
nnf-common.enable = false;
|
||||
nnf-conntrack.enable = true;
|
||||
nnf-drop.enable = true;
|
||||
nnf-loopback.enable = true;
|
||||
nnf-ssh.enable = true;
|
||||
};
|
||||
|
||||
rules.untrusted-to-local = {
|
||||
from = [ "untrusted" ];
|
||||
to = [ "local" ];
|
||||
|
||||
inherit (config.networking.firewall)
|
||||
allowedTCPPorts
|
||||
allowedTCPPortRanges
|
||||
allowedUDPPorts
|
||||
allowedUDPPortRanges
|
||||
;
|
||||
};
|
||||
|
||||
rules.icmp-and-igmp = {
|
||||
after = [
|
||||
"ct"
|
||||
"ssh"
|
||||
];
|
||||
from = "all";
|
||||
to = [ "local" ];
|
||||
extraLines = [
|
||||
"meta l4proto ipv6-icmp accept"
|
||||
"meta l4proto icmp accept"
|
||||
"ip protocol igmp accept"
|
||||
];
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
}
|
||||
|
|
@ -1,4 +1,4 @@
|
|||
{ lib, config, pkgs, ... }:
|
||||
{ lib, config, pkgs, withHomeManager, ... }:
|
||||
{
|
||||
options.swarselmodules.server.packages = lib.mkEnableOption "enable packages on server";
|
||||
config = lib.mkIf config.swarselmodules.server.packages {
|
||||
|
|
@ -14,6 +14,7 @@
|
|||
tmux
|
||||
busybox
|
||||
swarsel-deploy
|
||||
] ++ lib.optionals withHomeManager [
|
||||
swarsel-gens
|
||||
swarsel-switch
|
||||
];
|
||||
|
|
|
|||
|
|
@ -1,56 +1,142 @@
|
|||
{ lib, config, ... }:
|
||||
{ lib, config, globals, ... }:
|
||||
let
|
||||
serviceName = "router";
|
||||
in
|
||||
{
|
||||
options.swarselmodules.server.${serviceName} = lib.mkEnableOption "enable ${serviceName} on server";
|
||||
config = lib.mkIf config.swarselmodules.server.${serviceName} {
|
||||
config = lib.mkIf config.swarselmodules.server.${serviceName}
|
||||
{
|
||||
services.avahi.reflector = true;
|
||||
|
||||
systemd.network = {
|
||||
wait-online.anyInterface = true;
|
||||
networks = {
|
||||
"30-lan0" = {
|
||||
matchConfig.Name = "lan0";
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
ConfigureWithoutCarrier = true;
|
||||
networking.nftables = {
|
||||
firewall = {
|
||||
zones = {
|
||||
untrusted.interfaces = [ "lan" ];
|
||||
wgHome.interfaces = [ "wgHome" ];
|
||||
adguardhome.ipv4Addresses = [ globals.networks.home-lan.vlans.services.hosts.hintbooth-adguardhome.ipv4 ];
|
||||
adguardhome.ipv6Addresses = [ globals.networks.home-lan.vlans.services.hosts.hintbooth-adguardhome.ipv6 ];
|
||||
}
|
||||
// lib.flip lib.concatMapAttrs globals.networks.home-lan.vlans (
|
||||
vlanName: _: {
|
||||
"vlan-${vlanName}".interfaces = [ "me-${vlanName}" ];
|
||||
}
|
||||
);
|
||||
|
||||
rules = {
|
||||
masquerade-internet = {
|
||||
from = map (name: "vlan-${name}") (builtins.attrNames globals.networks.home-lan.vlans);
|
||||
to = [ "untrusted" ];
|
||||
# masquerade = true; NOTE: custom rule below for ip4 + ip6
|
||||
late = true; # Only accept after any rejects have been processed
|
||||
verdict = "accept";
|
||||
};
|
||||
|
||||
# Allow access to the AdGuardHome DNS server from any VLAN that has internet access
|
||||
access-adguardhome-dns = {
|
||||
from = map (name: "vlan-${name}") (builtins.attrNames globals.networks.home-lan.vlans);
|
||||
to = [ "adguardhome" ];
|
||||
verdict = "accept";
|
||||
};
|
||||
|
||||
# Allow devices in the home VLAN to talk to any of the services or home devices.
|
||||
access-services = {
|
||||
from = [ "vlan-home" ];
|
||||
to = [
|
||||
"vlan-services"
|
||||
"vlan-devices"
|
||||
];
|
||||
late = true;
|
||||
verdict = "accept";
|
||||
};
|
||||
|
||||
# Allow the services VLAN to talk to our wireguard server
|
||||
services-to-local = {
|
||||
from = [ "vlan-services" ];
|
||||
to = [ "local" ];
|
||||
allowedUDPPorts = [ 52829 ];
|
||||
};
|
||||
|
||||
# Forward traffic between wireguard participants
|
||||
forward-proxy-home-vpn-traffic = {
|
||||
from = [ "wgHome" ];
|
||||
to = [ "wgHome" ];
|
||||
verdict = "accept";
|
||||
};
|
||||
};
|
||||
};
|
||||
"30-lan1" = {
|
||||
matchConfig.Name = "lan1";
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
ConfigureWithoutCarrier = true;
|
||||
|
||||
chains.postrouting = {
|
||||
masquerade-internet = {
|
||||
after = [ "hook" ];
|
||||
late = true;
|
||||
rules =
|
||||
lib.forEach
|
||||
(map (name: "vlan-${name}") (builtins.attrNames globals.networks.home-lan.vlans))
|
||||
(
|
||||
zone:
|
||||
lib.concatStringsSep " " [
|
||||
"meta protocol { ip, ip6 }"
|
||||
(lib.head config.networking.nftables.firewall.zones.${zone}.ingressExpression)
|
||||
(lib.head config.networking.nftables.firewall.zones.untrusted.egressExpression)
|
||||
"masquerade random"
|
||||
]
|
||||
);
|
||||
};
|
||||
};
|
||||
"30-lan2" = {
|
||||
matchConfig.Name = "lan2";
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
"30-lan3" = {
|
||||
matchConfig.Name = "lan3";
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
"10-wan" = {
|
||||
matchConfig.Name = "wan";
|
||||
networkConfig = {
|
||||
# start a DHCP Client for IPv4 Addressing/Routing
|
||||
DHCP = "ipv4";
|
||||
DNSOverTLS = true;
|
||||
DNSSEC = true;
|
||||
IPv6PrivacyExtensions = false;
|
||||
IPForward = true;
|
||||
};
|
||||
# make routing on this interface a dependency for network-online.target
|
||||
linkConfig.RequiredForOnline = "routable";
|
||||
};
|
||||
};
|
||||
|
||||
boot.kernel.sysctl = {
|
||||
"net.ipv4.ip_forward" = 1;
|
||||
"net.ipv4.conf.all.forwarding" = true;
|
||||
"net.ipv6.conf.all.forwarding" = true;
|
||||
};
|
||||
|
||||
systemd.network = {
|
||||
wait-online.anyInterface = true;
|
||||
networks = {
|
||||
"30-lan1" = {
|
||||
matchConfig.MACAddress = config.repo.secrets.local.networking.networks.lan1.mac;
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
Bridge = "br";
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
"30-lan2" = {
|
||||
matchConfig.MACAddress = config.repo.secrets.local.networking.networks.lan2.mac;
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
Bridge = "br";
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
"30-lan3" = {
|
||||
matchConfig.MACAddress = config.repo.secrets.local.networking.networks.lan3.mac;
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
Bridge = "br";
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
"30-lan4" = {
|
||||
matchConfig.MACAddress = config.repo.secrets.local.networking.networks.lan4.mac;
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
Bridge = "br";
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
"30-lan5" = {
|
||||
matchConfig.MACAddress = config.repo.secrets.local.networking.networks.lan5.mac;
|
||||
linkConfig.RequiredForOnline = "enslaved";
|
||||
networkConfig = {
|
||||
Bridge = "br";
|
||||
ConfigureWithoutCarrier = true;
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,16 +22,18 @@ in
|
|||
}
|
||||
config.swarselsystems.shellAliases;
|
||||
|
||||
nixpkgs.config.permittedInsecurePackages = [
|
||||
# matrix
|
||||
"olm-3.2.16"
|
||||
# sonarr
|
||||
"aspnetcore-runtime-wrapped-6.0.36"
|
||||
"aspnetcore-runtime-6.0.36"
|
||||
"dotnet-sdk-wrapped-6.0.428"
|
||||
"dotnet-sdk-6.0.428"
|
||||
#
|
||||
"SDL_ttf-2.0.11"
|
||||
];
|
||||
nixpkgs.config = lib.mkIf (!config.swarselsystems.isMicroVM) {
|
||||
perittedInsecurePackages = [
|
||||
# matrix
|
||||
"olm-3.2.16"
|
||||
# sonarr
|
||||
"aspnetcore-runtime-wrapped-6.0.36"
|
||||
"aspnetcore-runtime-6.0.36"
|
||||
"dotnet-sdk-wrapped-6.0.428"
|
||||
"dotnet-sdk-6.0.428"
|
||||
#
|
||||
"SDL_ttf-2.0.11"
|
||||
];
|
||||
};
|
||||
};
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
{ self, lib, config, ... }:
|
||||
{ self, lib, config, withHomeManager, ... }:
|
||||
{
|
||||
options.swarselmodules.server.ssh = lib.mkEnableOption "enable ssh on server";
|
||||
config = lib.mkIf config.swarselmodules.server.ssh {
|
||||
|
|
@ -21,16 +21,18 @@
|
|||
}
|
||||
];
|
||||
};
|
||||
users.users."${config.swarselsystems.mainUser}".openssh.authorizedKeys.keyFiles = [
|
||||
(self + /secrets/public/ssh/yubikey.pub)
|
||||
(self + /secrets/public/ssh/magicant.pub)
|
||||
# (lib.mkIf config.swarselsystems.isBastionTarget (self + /secrets/public/ssh/jump.pub))
|
||||
];
|
||||
users.users.root.openssh.authorizedKeys.keyFiles = [
|
||||
(self + /secrets/public/ssh/yubikey.pub)
|
||||
(self + /secrets/public/ssh/magicant.pub)
|
||||
# (lib.mkIf config.swarselsystems.isBastionTarget (self + /secrets/public/ssh/jump.pub))
|
||||
];
|
||||
users.users = {
|
||||
"${config.swarselsystems.mainUser}".openssh.authorizedKeys.keyFiles = lib.mkIf withHomeManager [
|
||||
(self + /secrets/public/ssh/yubikey.pub)
|
||||
(self + /secrets/public/ssh/magicant.pub)
|
||||
# (lib.mkIf config.swarselsystems.isBastionTarget (self + /secrets/public/ssh/jump.pub))
|
||||
];
|
||||
root.openssh.authorizedKeys.keyFiles = [
|
||||
(self + /secrets/public/ssh/yubikey.pub)
|
||||
(self + /secrets/public/ssh/magicant.pub)
|
||||
# (lib.mkIf config.swarselsystems.isBastionTarget (self + /secrets/public/ssh/jump.pub))
|
||||
];
|
||||
};
|
||||
security.sudo.extraConfig = ''
|
||||
Defaults env_keep+=SSH_AUTH_SOCK
|
||||
'';
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue