1
1
Fork 1
mirror of https://github.com/oddlama/nix-config.git synced 2025-10-10 23:00:39 +02:00

feat(core): add nixos-nftables-firewall; and move some things from core/default.nix to more approriate locations

This commit is contained in:
oddlama 2023-04-16 00:34:35 +02:00
parent 2e45d3f423
commit 12d840c7bf
No known key found for this signature in database
GPG key ID: 14EFE510775FE39A
9 changed files with 92 additions and 93 deletions

View file

@ -16,6 +16,12 @@
impermanence.url = "github:nix-community/impermanence";
nixos-hardware.url = "github:NixOS/nixos-hardware";
nixos-nftables-firewall = {
url = "github:thelegy/nixos-nftables-firewall";
inputs.nixpkgs.follows = "nixpkgs";
};
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
microvm = {

View file

@ -4,17 +4,12 @@
pkgs,
config,
nodeName,
nodeSecrets,
...
}: let
dummyConfig = pkgs.writeText "configuration.nix" ''
assert builtins.trace "This is a dummy config, use colmena!" false;
{ }
'';
in {
}: {
imports = [
./inputrc.nix
./issue.nix
./net.nix
./nix.nix
./resolved.nix
./ssh.nix
@ -25,27 +20,31 @@ in {
];
# Setup secret rekeying parameters
rekey.forceRekeyOnSystem = "x86_64-linux";
rekey.hostPubkey = let
pubkeyPath = ../.. + "/${nodeName}/secrets/host.pub";
in
lib.mkIf (lib.pathExists pubkeyPath || lib.trace "Missing pubkey for ${nodeName}: ${toString pubkeyPath} not found, using dummy replacement key for now." false)
pubkeyPath;
rekey.masterIdentities = inputs.self.secrets.masterIdentities;
rekey.extraEncryptionPubkeys = inputs.self.secrets.extraEncryptionPubkeys;
rekey = {
inherit
(inputs.self.secrets)
masterIdentities
extraEncryptionPubkeys
;
forceRekeyOnSystem = "x86_64-linux";
hostPubkey = let
pubkeyPath = ../.. + "/${nodeName}/secrets/host.pub";
in
lib.mkIf (lib.pathExists pubkeyPath || lib.trace "Missing pubkey for ${nodeName}: ${toString pubkeyPath} not found, using dummy replacement key for now." false)
pubkeyPath;
};
boot = {
kernelParams = ["log_buf_len=10M"];
tmpOnTmpfs = true;
};
environment.etc."nixos/configuration.nix".source = dummyConfig;
# Disable sudo which is entierly unnecessary.
security.sudo.enable = false;
time.timeZone = lib.mkDefault "Europe/Berlin";
i18n.defaultLocale = "C.UTF-8";
console.keyMap = "de-latin1-nodeadkeys";
hardware = {
@ -53,48 +52,7 @@ in {
enableAllFirmware = true;
};
networking = {
hostName = lib.mkDefault nodeName;
# FIXME: would like to use mkForce false for useDHCP, but nixpkgs#215908 blocks that.
useDHCP = true;
useNetworkd = true;
wireguard.enable = true;
dhcpcd.enable = false;
nftables.enable = true;
firewall.enable = true;
};
# Rename known network interfaces
services.udev.packages = let
interfaceNamesUdevRules = pkgs.writeTextFile {
name = "interface-names-udev-rules";
text = lib.concatStringsSep "\n" (lib.mapAttrsToList (
interface: attrs: ''SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${attrs.mac}", NAME:="${interface}"''
)
nodeSecrets.networking.interfaces);
destination = "/etc/udev/rules.d/01-interface-names.rules";
};
in [interfaceNamesUdevRules];
nix.nixPath = [
"nixos-config=${dummyConfig}"
"nixpkgs=/run/current-system/nixpkgs"
];
system = {
extraSystemBuilderCmds = ''
ln -sv ${pkgs.path} $out/nixpkgs
'';
stateVersion = "23.05";
};
systemd.enableUnifiedCgroupHierarchy = true;
systemd.network = {
enable = true;
wait-online.anyInterface = true;
};
users.mutableUsers = false;
home-manager = {

42
hosts/common/core/net.nix Normal file
View file

@ -0,0 +1,42 @@
{
lib,
pkgs,
nodeName,
nodeSecrets,
...
}: let
inherit
(lib)
concatStringsSep
mapAttrsToList
mkDefault
mkForce
;
in {
networking = {
hostName = mkDefault nodeName;
useDHCP = mkForce false;
useNetworkd = true;
wireguard.enable = true;
dhcpcd.enable = false;
nftables.enable = true;
firewall.enable = true;
};
# Rename known network interfaces
services.udev.packages = let
interfaceNamesUdevRules = pkgs.writeTextFile {
name = "interface-names-udev-rules";
text = concatStringsSep "\n" (mapAttrsToList (
interface: attrs: ''SUBSYSTEM=="net", ACTION=="add", ATTR{address}=="${attrs.mac}", NAME:="${interface}"''
)
nodeSecrets.networking.interfaces);
destination = "/etc/udev/rules.d/01-interface-names.rules";
};
in [interfaceNamesUdevRules];
systemd.network = {
enable = true;
wait-online.anyInterface = true;
};
}

View file

@ -3,6 +3,11 @@
pkgs,
...
}: {
environment.etc."nixos/configuration.nix".source = pkgs.writeText "configuration.nix" ''
assert builtins.trace "This is a dummy config, use colmena!" false;
{ }
'';
nix = {
settings = {
auto-optimise-store = true;
@ -30,6 +35,7 @@
plugin-files = ${pkgs.nix-plugins}/lib/nix/plugins
extra-builtins-file = ${../../../nix/extra-builtins.nix}
'';
nixPath = ["nixpkgs=/run/current-system/nixpkgs"];
optimise.automatic = true;
gc.automatic = true;
# Define global flakes for this system
@ -40,4 +46,11 @@
templates.flake = inputs.templates;
};
};
system = {
extraSystemBuilderCmds = ''
ln -sv ${pkgs.path} $out/nixpkgs
'';
stateVersion = "23.05";
};
}

View file

@ -20,9 +20,4 @@
dhcpV6Config.RouteMetric = 40;
};
};
extra.wireguard.vms = {
via = "ward";
addresses = ["10.0.0.10/32"];
};
}

View file

@ -22,18 +22,13 @@
};
};
extra.wireguard.vms = {
server = {
enable = true;
host = "ward";
port = 51822;
openFirewall = true;
externalPeers = {
test1 = ["10.0.0.91/32"];
test2 = ["10.0.0.92/32"];
test3 = ["10.0.0.93/32"];
};
};
addresses = ["10.0.0.1/24"];
};
#extra.wireguard.vms = {
# server = {
# enable = true;
# host = "192.168.1.231";
# port = 51822;
# openFirewall = true;
# };
# addresses = ["10.0.0.1/24"];
#};
}

View file

@ -17,17 +17,4 @@
};
};
};
extra.wireguard.vms = {
server = {
enable = true;
host = "vms";
port = 51822;
openFirewall = true;
externalPeers = {
zack1 = ["10.0.0.90/32"];
};
};
addresses = ["10.0.0.2/24"];
};
}

View file

@ -102,9 +102,10 @@
# The allowed ips of a server node are it's own addreses,
# plus each external peer's addresses,
# plus each client's addresses that is connected via that node.
AllowedIPs =
snCfg.addresses
++ attrValues snCfg.server.externalPeers; # TODO ++ map (n: (wgCfgOf n).addresses) snCfg.ourClientNodes;
AllowedIPs = snCfg.addresses;
# TODO this needed? or even wanted at all?
# ++ attrValues snCfg.server.externalPeers;
# ++ map (n: (wgCfgOf n).addresses) snCfg.ourClientNodes;
Endpoint = "${snCfg.server.host}:${toString snCfg.server.port}";
};
}) (filterSelf associatedServerNodes)

View file

@ -4,6 +4,7 @@
home-manager,
#impermanence,
nixos-hardware,
nixos-nftables-firewall,
nixpkgs,
microvm,
agenix,
@ -25,6 +26,7 @@ in
secrets = self.secrets.content;
nodeSecrets = self.secrets.content.nodes.${nodeName};
nixos-hardware = nixos-hardware.nixosModules;
nixos-nftables-firewall = nixos-nftables-firewall.nixosModules;
#impermanence = impermanence.nixosModules;
};
imports =