From dd6271f7d6a4b06704f0f23887092d76330bc80f Mon Sep 17 00:00:00 2001 From: ooks-io Date: Wed, 12 Jun 2024 22:32:58 +1200 Subject: [PATCH] refactor(nixos:tailcale): move options --> ooknet.host.networking.tailscale --- hosts/ooks-x1/default.nix | 154 +++++--------------- hosts/ooksdesk/default.nix | 15 +- hosts/ooksmedia/default.nix | 19 +-- hosts/ooksmicro/default.nix | 86 +++++++---- hosts/ookst480s/default.nix | 80 +++++----- nixos/modules/base/networking/tailscale.nix | 32 +--- nixos/options/host.nix | 33 ++++- 7 files changed, 195 insertions(+), 224 deletions(-) diff --git a/hosts/ooks-x1/default.nix b/hosts/ooks-x1/default.nix index fa56657..9a939fe 100644 --- a/hosts/ooks-x1/default.nix +++ b/hosts/ooks-x1/default.nix @@ -1,128 +1,54 @@ +{ pkgs, lib, ... }: - - - -{ config, inputs, pkgs, ... }: - -# Imports -# ------------------------------------------------------------------------------------------------- +let + inherit (lib) mkDefault; + key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBn3ff3HaZHIyH4K13k8Mwqu/o7jIABJ8rANK+r2PfJk"; +in { imports = [ - inputs.hardware.nixosModules.common-pc-ssd - inputs.hardware.nixosModules.common-cpu-intel - inputs.hardware.nixosModules.common-gpu-intel - ./hardware-configuration.nix - - ../common/user/ooks - ../common/base - ../common/features/bluetooth.nix - ../common/features/greetd.nix + ]; - ]; -# Hostname and networking -# ------------------------------------------------------------------------------------------------- - - networking = { - hostName = "ooksx1"; - networkmanager.enable = true; + ooknet.host = { + name = "ooksx1"; + type = "laptop"; + role = "workstation"; + profiles = [ "console-tools" ]; + admin = { + name = "ooks"; + shell = "fish"; + sshKey = key; + homeManager = true; }; - - -# Printing -# ------------------------------------------------------------------------------------------------- - - services.printing.enable = true; - -# Kernel -# ------------------------------------------------------------------------------------------------ + hardware = { + cpu.type = "intel"; + gpu.type = "intel"; + features = [ + "bluetooth" + "backlight" + "battery" + "ssd" + "audio" + "video" + ]; + battery = { + powersave = { + minFreq = 800; + maxFreq = 1800; + }; + performance = { + minFreq = 1800; + maxFreq = 3600; + }; + }; + }; + }; boot = { kernelPackages = pkgs.linuxKernel.packages.linux_zen; }; - -# Laptop Programs -# ------------------------------------------------------------------------------------------------- - - powerManagement.powertop.enable = true; - programs = { - light.enable = true; - dconf.enable = true; - kdeconnect.enable = true; - }; - - - hardware = { - opengl = { - enable = true; - }; - }; - -# gnupg -# ------------------------------------------------------------------------------------------------- - - programs.gnupg.agent = { - enable = true; - enableSSHSupport = true; - }; - -# Services -# ------------------------------------------------------------------------------------------------- - - services = { - logind = { - lidSwitch = "suspend"; - }; - dbus = { - enable = true; - packages = [ pkgs.gcr ]; - }; - auto-cpufreq = { - enable = true; - settings = { - battery = { - governor = "powersave"; - turbo = "never"; - }; - charger = { - governor = "performance"; - turbo = "auto"; - }; - }; - }; - }; - - systemd = { - user.services.polkit-gnome-authentication-agent-1 = { - description = "polkit-gnome-authentication-agent-1"; - wantedBy = [ "graphical-session.target" ]; - wants = [ "graphical-session.target" ]; - after = [ "graphical-session.target" ]; - serviceConfig = { - Type = "simple"; - ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1"; - Restart = "on-failure"; - RestartSec = 1; - TimeoutStopSec = 10; - }; - }; - }; - -# Firewall -# ------------------------------------------------------------------------------------------------- - - # networking.firewall.allowedTCPPorts = [ ... ]; - # networking.firewall.allowedUDPPorts = [ ... ]; - # Or disable the firewall altogether. - # networking.firewall.enable = false; - -# System Version -# ------------------------------------------------------------------------------------------------- - - system = { - stateVersion = "22.05"; - }; + system.stateVersion = mkDefault "23.11"; } diff --git a/hosts/ooksdesk/default.nix b/hosts/ooksdesk/default.nix index 6e18a2b..6206b65 100644 --- a/hosts/ooksdesk/default.nix +++ b/hosts/ooksdesk/default.nix @@ -1,4 +1,4 @@ -{ lib, config, inputs, pkgs, ... }: +{ lib, pkgs, ... }: let key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBn3ff3HaZHIyH4K13k8Mwqu/o7jIABJ8rANK+r2PfJk"; @@ -13,13 +13,19 @@ in name = "ooksdesk"; type = "desktop"; role = "workstation"; - profiles = [ "gaming" "creative" ]; + profiles = [ "gaming" "creative" "console-tools" ]; admin = { name = "ooks"; shell = "fish"; sshKey = key; homeManager = true; }; + networking = { + tailscale = { + enable = true; + client = true; + }; + }; hardware = { cpu.type = "amd"; cpu.amd.pstate.enable = true; @@ -35,11 +41,6 @@ in }]; }; }; - - ooknet.networking.tailscale = { - enable = true; - client = true; - }; boot = { kernelPackages = pkgs.linuxPackages_xanmod_latest; diff --git a/hosts/ooksmedia/default.nix b/hosts/ooksmedia/default.nix index 1240343..bcebaa4 100644 --- a/hosts/ooksmedia/default.nix +++ b/hosts/ooksmedia/default.nix @@ -12,17 +12,20 @@ in ooknet.host = { name = "ooksmedia"; type = "desktop"; - function = [ - "workstation" - "gaming" - "media-server" - ]; + role = "workstation"; + profiles = [ "media-server" "console-tools" ]; admin = { name = "ooks"; shell = "fish"; sshKey = key; homeManager = true; }; + networking = { + tailscale = { + enable = true; + server = true; + }; + }; hardware = { cpu.type = "intel"; cpu.amd.pstate.enable = true; @@ -34,12 +37,6 @@ in ]; }; }; - - ooknet.networking.tailscale = { - enable = true; - server = true; - }; - boot = { kernelPackages = pkgs.linuxPackages_xanmod_latest; }; diff --git a/hosts/ooksmicro/default.nix b/hosts/ooksmicro/default.nix index 8737850..58c3a90 100644 --- a/hosts/ooksmicro/default.nix +++ b/hosts/ooksmicro/default.nix @@ -1,38 +1,68 @@ -{ pkgs, ... }: +{ pkgs, lib, ... }: + +let + inherit (lib) mkDefault; + key = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIBn3ff3HaZHIyH4K13k8Mwqu/o7jIABJ8rANK+r2PfJk"; +in { imports = [ ./hardware-configuration.nix - ../../profiles - ]; + ]; - activeProfiles = ["base" "laptop"]; - ooknet.user = { - ooks.enable = true; - shell.fish.enable = true; + ooknet.host = { + name = "ooksmicro"; + type = "micro"; + role = "workstation"; + profiles = [ "console-tools" ]; + admin = { + name = "ooks"; + shell = "fish"; + sshKey = key; + homeManager = true; }; - - ooknet.laptop.power = { - powersave = { - minFreq = 800; - maxFreq = 1600; - }; - performance = { - minFreq = 1100; - maxFreq = 2600; - }; - }; - networking = { - hostName = "ooksmicro"; + tailscale = { + enable = true; + client = true; + }; }; - - boot = { - kernelPackages = pkgs.linuxKernel.packages.linux_zen; - # need this due to - kernelParams = [ "fbcon=rotate:1" ]; - # required for keyboard to work during boot - initrd.availableKernelModules = [ "battery" ]; - }; + hardware = { + cpu.type = "intel"; + gpu.type = "intel"; + features = [ + "bluetooth" + "backlight" + "battery" + "ssd" + "audio" + "video" + ]; + battery = { + powersave = { + minFreq = 500; + maxFreq = 800; + }; + performance = { + minFreq = 1200; + maxFreq = 2400; + }; + }; + }; + monitors = [{ + name = "DSI-1"; + width = 720; + height = 1280; + workspace = "1"; + primary = true; + transform = 3; + }]; + }; + + boot = { + kernelPackages = pkgs.linuxKernel.packages.linux_zen; + }; + + system.stateVersion = mkDefault "23.11"; } diff --git a/hosts/ookst480s/default.nix b/hosts/ookst480s/default.nix index 429647f..f019e5b 100644 --- a/hosts/ookst480s/default.nix +++ b/hosts/ookst480s/default.nix @@ -11,43 +11,57 @@ in ]; - ooknet.host = { - name = "ookst480s"; - type = "laptop"; - function = [ "workstation" ]; - admin = { - name = "ooks"; - shell = "fish"; - sshKey = key; - homeManager = true; + ooknet.host = { + name = "ookst480s"; + type = "laptop"; + role = "workstation"; + profiles = [ "console-tools" ]; + admin = { + name = "ooks"; + shell = "fish"; + sshKey = key; + homeManager = true; + }; + networking = { + tailscale = { + enable = true; + client = true; }; - hardware = { - cpu.type = "intel"; - gpu.type = "intel"; - features = [ - "bluetooth" - "backlight" - "battery" - "ssd" - "audio" - "video" - ]; - battery = { - powersave = { - minFreq = 800; - maxFreq = 1800; - }; - performance = { - minFreq = 1800; - maxFreq = 3600; - }; + }; + hardware = { + cpu.type = "intel"; + gpu.type = "intel"; + features = [ + "bluetooth" + "backlight" + "battery" + "ssd" + "audio" + "video" + ]; + monitors = [{ + name = "eDP-1"; + width = 1920; + height = 1080; + workspace = "1"; + primary = true; + }]; + battery = { + powersave = { + minFreq = 800; + maxFreq = 1800; + }; + performance = { + minFreq = 1800; + maxFreq = 3600; }; }; }; + }; - boot = { - kernelPackages = pkgs.linuxKernel.packages.linux_zen; - }; + boot = { + kernelPackages = pkgs.linuxKernel.packages.linux_zen; + }; - system.stateVersion = mkDefault "23.11"; + system.stateVersion = mkDefault "23.11"; } diff --git a/nixos/modules/base/networking/tailscale.nix b/nixos/modules/base/networking/tailscale.nix index 8ec4262..96ccc3c 100644 --- a/nixos/modules/base/networking/tailscale.nix +++ b/nixos/modules/base/networking/tailscale.nix @@ -1,42 +1,14 @@ { lib, config, pkgs, ... }: let - cfg = config.ooknet.networking.tailscale; + cfg = config.ooknet.host.networking.tailscale; inherit (config.services) tailscale; inherit (lib.lists) optionals; - inherit (lib.types) bool listOf str; inherit (lib.strings) concatStringsSep; - inherit (lib) mkIf mkEnableOption mkOption mkDefault; + inherit (lib) mkIf mkDefault; in { - options.ooknet.networking.tailscale = { - enable = mkEnableOption "Enable tailscale system module"; - server = mkOption { - type = bool; - default = false; - description = "Define if the host is a server"; - }; - client = mkOption { - type = bool; - default = cfg.enable; - description = "Define if the host is a client"; - }; - tag = mkOption { - type = listOf str; - default = - if cfg.client then ["tag:client"] - else if cfg.server then ["tag:server"] - else []; - description = "Sets host tag depending on if server/client"; - }; - operator = mkOption { - type = str; - default = "ooks"; - description = "Name of the tailscale operator"; - }; - }; - config = mkIf cfg.enable { services.tailscale = { diff --git a/nixos/options/host.nix b/nixos/options/host.nix index 98f7552..84218d6 100644 --- a/nixos/options/host.nix +++ b/nixos/options/host.nix @@ -3,7 +3,9 @@ let inherit (lib) mkOption mkEnableOption; inherit (lib.types) bool enum listOf int submodule nullOr str; + admin = config.ooknet.host.admin; hardware = config.ooknet.host.hardware; + tailscale = config.ooknet.host.networking.tailscale; in { @@ -24,7 +26,7 @@ in }; profiles = mkOption { - type = listOf (enum ["gaming" "creative" "productivity" "media-server"]); + type = listOf (enum ["gaming" "creative" "productivity" "console-tools" "media-server"]); default = []; }; @@ -52,6 +54,35 @@ in homeManager = mkEnableOption ""; }; + networking = { + tailscale = { + enable = mkEnableOption "Enable tailscale system module"; + server = mkOption { + type = bool; + default = false; + description = "Define if the host is a server"; + }; + client = mkOption { + type = bool; + default = tailscale.enable; + description = "Define if the host is a client"; + }; + tag = mkOption { + type = listOf str; + default = + if tailscale.client then ["tag:client"] + else if tailscale.server then ["tag:server"] + else []; + description = "Sets host tag depending on if server/client"; + }; + operator = mkOption { + type = str; + default = "${admin.name}"; + description = "Name of the tailscale operator"; + }; + }; + }; + hardware = { gpu = { type = mkOption {