diff options
| author | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-01-29 20:15:19 -0600 |
|---|---|---|
| committer | Collin Williams <96917990+bluedragon1221@users.noreply.github.com> | 2026-01-30 08:38:21 -0600 |
| commit | c9a1d2da80bca0a85e8c18f6d2db71c4d1127eda (patch) | |
| tree | 9da79e318ff0533a3708aee85a0b6a6d7f1d1036 /modules/system/nixos | |
| parent | c81952cbcb6c6f1b41c2b6e2a366891991cceaee (diff) | |
Spring Cleaning
- create new module, `system`, that consumes the `boot` module and takes
in the more system-interested services from the `services` module
- touch up left over services (which are more self-hosting interested)
- touch up yo and yoshi configs
Diffstat (limited to 'modules/system/nixos')
| -rw-r--r-- | modules/system/nixos/audio.nix | 23 | ||||
| -rw-r--r-- | modules/system/nixos/bluetooth.nix | 40 | ||||
| -rw-r--r-- | modules/system/nixos/boot.nix | 89 | ||||
| -rw-r--r-- | modules/system/nixos/default.nix | 9 | ||||
| -rw-r--r-- | modules/system/nixos/networking/default.nix | 13 | ||||
| -rw-r--r-- | modules/system/nixos/networking/iwd.nix | 27 | ||||
| -rw-r--r-- | modules/system/nixos/networking/networkd.nix | 60 | ||||
| -rw-r--r-- | modules/system/nixos/networking/networkmanager.nix | 18 | ||||
| -rw-r--r-- | modules/system/nixos/networking/resolved.nix | 18 | ||||
| -rw-r--r-- | modules/system/nixos/networking/tailscale.nix | 33 | ||||
| -rw-r--r-- | modules/system/nixos/polkit.nix | 75 |
11 files changed, 405 insertions, 0 deletions
diff --git a/modules/system/nixos/audio.nix b/modules/system/nixos/audio.nix new file mode 100644 index 0000000..85232f6 --- /dev/null +++ b/modules/system/nixos/audio.nix @@ -0,0 +1,23 @@ +{ + pkgs, + config, + lib, + ... +}: let + cfg = config.collinux.system.audio; +in + lib.mkIf cfg.enable { + security.rtkit.enable = true; + services.pipewire = { + enable = true; + wireplumber.enable = true; + alsa.enable = true; + pulse.enable = false; + }; + + boot.blacklistedKernelModules = ["snd_seq_dummy"]; # remove extraneous alsa midi devices + + environment.systemPackages = with pkgs; [pwvucontrol qpwgraph]; + + users.users.${config.collinux.user.name}.extraGroups = ["audio" "pipewire"]; + } diff --git a/modules/system/nixos/bluetooth.nix b/modules/system/nixos/bluetooth.nix new file mode 100644 index 0000000..1795547 --- /dev/null +++ b/modules/system/nixos/bluetooth.nix @@ -0,0 +1,40 @@ +{ + lib, + config, + ... +}: let + cfg = config.collinux.system.bluetooth; +in + lib.mkIf cfg.enable { + hardware.bluetooth = { + enable = true; + powerOnBoot = true; + + settings.General = { + ControllerMode = "bredr"; + FastConnectable = true; + JustWorksRepairing = "always"; + }; + }; + + systemd.user.services."mpris-proxy" = { + unitConfig = { + BindsTo = ["bluetooth.target"]; + After = ["bluetooth.target"]; + }; + + wantedBy = ["bluetooth.target"]; + + # serviceConfig already exists (?) + }; + + # hardening (down to 2.1 OK) + systemd.services."bluetooth".serviceConfig = { + IPAddressDeny = "any"; + ProtectKernelLogs = true; + ProtectKernelModules = lib.mkForce true; + RestrictAddressFamilies = ["AF_UNIX" "AF_BLUETOOTH"]; + ProtectClock = true; + ProcSubset = "pid"; + }; + } diff --git a/modules/system/nixos/boot.nix b/modules/system/nixos/boot.nix new file mode 100644 index 0000000..b7f5266 --- /dev/null +++ b/modules/system/nixos/boot.nix @@ -0,0 +1,89 @@ +{ + pkgs, + config, + lib, + ... +}: let + cfg = config.collinux.system.boot; +in { + boot = + { + bcache.enable = false; # why is this default on? I DON'T CARE ABOUT bcachefs + initrd = { + verbose = false; + systemd.enable = true; + checkJournalingFS = false; + }; + loader = { + systemd-boot = lib.optionalAttrs (cfg.systemd-boot.enable && !cfg.secureBoot.enable) { + enable = true; + configurationLimit = 3; + }; + efi.canTouchEfiVariables = true; + timeout = cfg.timeout; # hold space to show boot menu if timeout == 0 + }; + + plymouth = lib.mkIf cfg.plymouth.enable { + enable = true; + theme = + if (cfg.plymouth.theme == "catppuccin") + then "catppuccin-macchiato" # for whatever reason catppuccin-mocha has errors + else "nixos-bgrt"; + themePackages = + if (cfg.plymouth.theme == "catppuccin") + then [pkgs.catppuccin-plymouth] + else [pkgs.nixos-bgrt-plymouth]; + }; + + # from hardened.nix + blacklistedKernelModules = [ + # Obscure network protocols + "ax25" + "netrom" + "rose" + + # Old or rare or insufficiently audited filesystems + "adfs" + "affs" + "bfs" + "befs" + "cramfs" + "efs" + # "erofs" # necessary for system.etc.overlay + "exofs" + "freevxfs" + "f2fs" + "hfs" + "hpfs" + "jfs" + "minix" + "nilfs2" + "ntfs" + "omfs" + "qnx4" + "qnx6" + "sysv" + "ufs" + ]; + } + // (lib.optionalAttrs cfg.secureBoot.enable { + lanzaboote = { + enable = true; + pkiBundle = "/var/lib/sbctl"; + }; + }); + + system.etc.overlay = { + enable = true; + mutable = true; # would love this to be false, but we're not there yet + }; + system.nixos-init.enable = true; + + # store journald logs in memory + services.journald.extraConfig = '' + Storage=volatile + RuntimeMaxUse=100M + ''; + + environment.systemPackages = [pkgs.efibootmgr] ++ lib.optional cfg.secureBoot.enable pkgs.sbctl; +} diff --git a/modules/system/nixos/default.nix b/modules/system/nixos/default.nix new file mode 100644 index 0000000..132d99c --- /dev/null +++ b/modules/system/nixos/default.nix @@ -0,0 +1,9 @@ +{ + imports = [ + ./networking + ./boot.nix + ./audio.nix + ./bluetooth.nix + ./polkit.nix + ]; +} diff --git a/modules/system/nixos/networking/default.nix b/modules/system/nixos/networking/default.nix new file mode 100644 index 0000000..a042411 --- /dev/null +++ b/modules/system/nixos/networking/default.nix @@ -0,0 +1,13 @@ +{ + imports = [ + ./iwd.nix + ./networkmanager.nix + ./networkd.nix + ./resolved.nix + ]; + + networking.firewall = { + enable = true; + checkReversePath = "loose"; + }; +} diff --git a/modules/system/nixos/networking/iwd.nix b/modules/system/nixos/networking/iwd.nix new file mode 100644 index 0000000..eea35d8 --- /dev/null +++ b/modules/system/nixos/networking/iwd.nix @@ -0,0 +1,27 @@ +{ + lib, + config, + ... +}: let + cfg = config.collinux.system.network.iwd; +in + lib.mkIf cfg.enable { + networking = { + wireless.iwd = { + enable = true; + settings = { + General = { + EnableNetworkConfiguration = !config.collinux.system.network.networkd.enable; + AddressRandomization = "once"; + AddressRandomizationRange = "full"; + }; + Network.NameResolvingService = "systemd"; # either systemd or resolvconf + }; + }; + + # Disable default networking stuff + dhcpcd.enable = false; + useDHCP = false; + networkmanager.enable = false; + }; + } diff --git a/modules/system/nixos/networking/networkd.nix b/modules/system/nixos/networking/networkd.nix new file mode 100644 index 0000000..37b0908 --- /dev/null +++ b/modules/system/nixos/networking/networkd.nix @@ -0,0 +1,60 @@ +{ + lib, + config, + ... +}: let + cfg = config.collinux.system.network.networkd; + + dhcp_enabled = cfg.static == null; +in + lib.mkIf cfg.enable { + networking = { + wireless = + if !config.collinux.system.network.iwd.enable + then { + enable = true; + networks.${cfg.ssid}.pskRaw = "ext:psk"; + secretsFile = cfg.pskFile; + } + else {}; + + useNetworkd = true; + + # Disable default networking stuff + dhcpcd.enable = false; + useDHCP = false; + networkmanager.enable = false; + }; + + systemd.network = { + enable = true; + + wait-online = { + enable = true; + ignoredInterfaces = ["docker0"]; + anyInterface = true; + }; + + networks."11-lan" = { + name = "wl*"; + + networkConfig = + ( + if dhcp_enabled + then {DHCP = "yes";} + else { + Address = cfg.static.ip; + Gateway = cfg.static.gateway; + DHCP = "no"; + # DNS is managed by systemd-resolved (not specified here) + } + ) + // { + LinkLocalAddressing = "no"; + }; + + dhcpV4Config.UseDNS = "no"; + dhcpV6Config.UseDNS = "no"; + }; + }; + } diff --git a/modules/system/nixos/networking/networkmanager.nix b/modules/system/nixos/networking/networkmanager.nix new file mode 100644 index 0000000..c2d6dd1 --- /dev/null +++ b/modules/system/nixos/networking/networkmanager.nix @@ -0,0 +1,18 @@ +{ + lib, + config, + ... +}: let + cfg = config.collinux.system.network.networkmanager; +in + lib.mkIf cfg.enable { + networking = { + networkmanager = { + enable = true; + dns = "systemd-resolved"; + dhcp = "internal"; + }; + + dhcpcd.enable = false; + }; + } diff --git a/modules/system/nixos/networking/resolved.nix b/modules/system/nixos/networking/resolved.nix new file mode 100644 index 0000000..03333b1 --- /dev/null +++ b/modules/system/nixos/networking/resolved.nix @@ -0,0 +1,18 @@ +{ + networking.resolvconf.enable = false; + + networking.nameservers = [ + "9.9.9.9#dns.quad9.net" + "149.112.112.112#dns.quad9.net" + ]; + + services.resolved = { + enable = true; + dnsovertls = "opportunistic"; + dnssec = "allow-downgrade"; + + # disable extra stuff + llmnr = "false"; + extraConfig = "MulticastDNS=no"; + }; +} diff --git a/modules/system/nixos/networking/tailscale.nix b/modules/system/nixos/networking/tailscale.nix new file mode 100644 index 0000000..552ec8b --- /dev/null +++ b/modules/system/nixos/networking/tailscale.nix @@ -0,0 +1,33 @@ +{ + config, + pkgs, + lib, + ... +}: let + cfg = config.collinux.system.network.tailscale; +in + lib.mkIf cfg.enable { + services.tailscale = { + enable = true; + useRoutingFeatures = "both"; + }; + + networking.firewall = { + trustedInterfaces = ["tailscale0"]; + allowedUDPPorts = [config.services.tailscale.port]; + }; + + systemd.services."tailscaled" = + if config.collinux.services.selfhost.headscale.enable + then { + # don't start tailscale until after headscale starts + wants = lib.mkForce ["network.target" "headscale.target"]; + after = lib.mkForce ["network.target" "headscale.target"]; + } + else { + wants = lib.mkForce ["network.target"]; + after = lib.mkForce ["network.target"]; + }; + + environment.systemPackages = [pkgs.tailscale]; + } diff --git a/modules/system/nixos/polkit.nix b/modules/system/nixos/polkit.nix new file mode 100644 index 0000000..29a06f4 --- /dev/null +++ b/modules/system/nixos/polkit.nix @@ -0,0 +1,75 @@ +{lib, ...}: let + defaultDenyRule = '' + polkit.addRule(function(action, subject) { + // Log denied actions for debugging + polkit.log("DENY: action=" + action.id + " user=" + subject.user); + return polkit.Result.NO; + }); + ''; + + run0Rules = '' + polkit.addRule(function(action, subject) { + if (subject.isInGroup("wheel") && action.id === "org.freedesktop.systemd1.manage-units") { + return polkit.Result.AUTH_ADMIN_KEEP; + } + }); + ''; + + networkRules = '' + polkit.addRule(function(action, subject) { + // Only allow network modifications for wheel group (admins) + if (action.id.startsWith("org.freedesktop.NetworkManager.") && + subject.isInGroup("wheel")) { + return polkit.Result.YES; + } + + // Allow reading network status for all users + if (action.id == "org.freedesktop.NetworkManager.network-control" || + action.id == "org.freedesktop.NetworkManager.settings.modify.system") { + if (subject.isInGroup("wheel")) { + return polkit.Result.YES; + } + return polkit.Result.NO; + } + + return polkit.Result.NOT_HANDLED; + }); + ''; + + powerRules = '' + polkit.addRule(function(action, subject) { + if (action.id.match("org.freedesktop.login1.")) { + return polkit.Result.YES; + } + }); + ''; + + bluetoothRules = '' + polkit.addRule(function(action, subject) { + // Allow users to manage bluetooth devices + if (action.id.startsWith("org.bluez.") && + subject.local && subject.active) { + return polkit.Result.YES; + } + + return polkit.Result.NOT_HANDLED; + }); + ''; +in { + security = { + polkit = { + enable = true; + adminIdentities = ["unix-group:wheel"]; + + extraConfig = lib.concatStringsSep "\n\n" [ + run0Rules + networkRules + powerRules + bluetoothRules + defaultDenyRule + ]; + }; + + soteria.enable = true; + }; +} |
