From a8630322f77dbb7be4810099a42352b9278996a1 Mon Sep 17 00:00:00 2001 From: seth Date: Sun, 1 Oct 2023 10:41:09 -0400 Subject: treewide!: flatten to parts/ layout --- parts/systems/atlas/default.nix | 50 ++++++ parts/systems/atlas/hardware-configuration.nix | 29 ++++ parts/systems/atlas/miniflux.nix | 20 +++ parts/systems/atlas/nginx.nix | 32 ++++ parts/systems/caroline/default.nix | 17 ++ parts/systems/default.nix | 47 +++++ parts/systems/glados-wsl/default.nix | 39 +++++ parts/systems/glados/boot.nix | 25 +++ parts/systems/glados/default.nix | 61 +++++++ parts/systems/glados/hardware-configuration.nix | 72 ++++++++ parts/systems/profiles.nix | 101 +++++++++++ parts/systems/turret/default.nix | 38 +++++ parts/systems/turret/files/etc/config/dhcp | 55 ++++++ parts/systems/turret/files/etc/config/dropbear | 5 + parts/systems/turret/files/etc/config/firewall | 189 +++++++++++++++++++++ .../turret/files/etc/config/https-dns-proxy | 18 ++ parts/systems/turret/files/etc/config/luci | 41 +++++ parts/systems/turret/files/etc/config/network | 29 ++++ parts/systems/turret/files/etc/config/rpcd | 10 ++ parts/systems/turret/files/etc/config/system | 16 ++ parts/systems/turret/files/etc/config/ucitrack | 56 ++++++ parts/systems/turret/files/etc/config/uhttpd | 31 ++++ parts/systems/turret/files/etc/config/wireless | 34 ++++ .../turret/files/etc/dropbear/authorized_keys | 1 + 24 files changed, 1016 insertions(+) create mode 100644 parts/systems/atlas/default.nix create mode 100644 parts/systems/atlas/hardware-configuration.nix create mode 100644 parts/systems/atlas/miniflux.nix create mode 100644 parts/systems/atlas/nginx.nix create mode 100644 parts/systems/caroline/default.nix create mode 100644 parts/systems/default.nix create mode 100644 parts/systems/glados-wsl/default.nix create mode 100644 parts/systems/glados/boot.nix create mode 100644 parts/systems/glados/default.nix create mode 100644 parts/systems/glados/hardware-configuration.nix create mode 100644 parts/systems/profiles.nix create mode 100644 parts/systems/turret/default.nix create mode 100644 parts/systems/turret/files/etc/config/dhcp create mode 100644 parts/systems/turret/files/etc/config/dropbear create mode 100644 parts/systems/turret/files/etc/config/firewall create mode 100644 parts/systems/turret/files/etc/config/https-dns-proxy create mode 100644 parts/systems/turret/files/etc/config/luci create mode 100644 parts/systems/turret/files/etc/config/network create mode 100644 parts/systems/turret/files/etc/config/rpcd create mode 100644 parts/systems/turret/files/etc/config/system create mode 100644 parts/systems/turret/files/etc/config/ucitrack create mode 100644 parts/systems/turret/files/etc/config/uhttpd create mode 100644 parts/systems/turret/files/etc/config/wireless create mode 100644 parts/systems/turret/files/etc/dropbear/authorized_keys (limited to 'parts/systems') diff --git a/parts/systems/atlas/default.nix b/parts/systems/atlas/default.nix new file mode 100644 index 0000000..24cb139 --- /dev/null +++ b/parts/systems/atlas/default.nix @@ -0,0 +1,50 @@ +{ + config, + pkgs, + ... +}: { + imports = [ + ./hardware-configuration.nix + ./miniflux.nix + ./nginx.nix + ]; + + _module.args.nixinate = { + host = "atlas"; + sshUser = "root"; + buildOn = "remote"; + substituteOnTarget = true; + hermetic = false; + }; + + boot = { + loader.systemd-boot.enable = true; + loader.efi.canTouchEfiVariables = true; + tmp.cleanOnBoot = true; + }; + + networking = { + domain = "mydadleft.me"; + hostName = "atlas"; + }; + + services = { + guzzle-api = { + enable = true; + domain = "api.${config.networking.domain}"; + nginx = { + enableACME = true; + acmeRoot = null; + addSSL = true; + }; + }; + }; + + users.users.atlas = { + isNormalUser = true; + shell = pkgs.bash; + passwordFile = config.age.secrets.userPassword.path; + }; + + zramSwap.enable = true; +} diff --git a/parts/systems/atlas/hardware-configuration.nix b/parts/systems/atlas/hardware-configuration.nix new file mode 100644 index 0000000..00c6cd8 --- /dev/null +++ b/parts/systems/atlas/hardware-configuration.nix @@ -0,0 +1,29 @@ +{modulesPath, ...}: { + imports = [ + (modulesPath + "/profiles/qemu-guest.nix") + ]; + + boot = { + extraModulePackages = []; + kernelModules = []; + + initrd = { + availableKernelModules = ["virtio_pci" "usbhid"]; + kernelModules = []; + }; + }; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/f0c84809-83f5-414b-a973-496d25d74c6d"; + fsType = "ext4"; + }; + + "/boot" = { + device = "/dev/disk/by-uuid/A253-0826"; + fsType = "vfat"; + }; + }; + + swapDevices = []; +} diff --git a/parts/systems/atlas/miniflux.nix b/parts/systems/atlas/miniflux.nix new file mode 100644 index 0000000..5ed5d40 --- /dev/null +++ b/parts/systems/atlas/miniflux.nix @@ -0,0 +1,20 @@ +{ + config, + self, + ... +}: { + config = { + age.secrets = { + miniflux.file = "${self}/parts/secrets/systems/${config.networking.hostName}/miniflux.age"; + }; + + services.miniflux = { + enable = true; + adminCredentialsFile = config.age.secrets.miniflux.path; + config = { + BASE_URL = "https://miniflux.${config.networking.domain}"; + LISTEN_ADDR = "localhost:7000"; + }; + }; + }; +} diff --git a/parts/systems/atlas/nginx.nix b/parts/systems/atlas/nginx.nix new file mode 100644 index 0000000..cdf483d --- /dev/null +++ b/parts/systems/atlas/nginx.nix @@ -0,0 +1,32 @@ +{ + config, + self, + ... +}: let + inherit (config.networking) domain; + inherit (self.lib.utils.nginx) mkVHosts mkProxy; +in { + server = { + acme.enable = true; + services.cloudflared.enable = true; + }; + + services.nginx = { + enable = true; + + recommendedGzipSettings = true; + recommendedOptimisation = true; + recommendedProxySettings = true; + recommendedTlsSettings = true; + + virtualHosts = mkVHosts { + "miniflux.${domain}" = { + locations = mkProxy "/" "7000"; + }; + + "msix.${domain}" = { + root = "/var/www/msix"; + }; + }; + }; +} diff --git a/parts/systems/caroline/default.nix b/parts/systems/caroline/default.nix new file mode 100644 index 0000000..43dc82f --- /dev/null +++ b/parts/systems/caroline/default.nix @@ -0,0 +1,17 @@ +_: { + desktop = { + homebrew.enable = true; + gpg.enable = true; + }; + + homebrew.casks = ["arc"]; + + networking = rec { + computerName = "caroline"; + hostName = computerName; + }; + + nix.settings.trusted-users = ["seth"]; + + services.tailscale.enable = true; +} diff --git a/parts/systems/default.nix b/parts/systems/default.nix new file mode 100644 index 0000000..e9ef9ba --- /dev/null +++ b/parts/systems/default.nix @@ -0,0 +1,47 @@ +{ + inputs, + self, + withSystem, + ... +}: { + flake = let + inherit (self.lib.configs) mapSystems; + profiles = import ./profiles.nix {inherit self inputs;}; + in { + darwinConfigurations = mapSystems { + caroline = { + system = "x86_64-darwin"; + profile = profiles.personal-darwin; + }; + }; + + nixosConfigurations = mapSystems { + glados = { + modules = with inputs; [ + lanzaboote.nixosModules.lanzaboote + ]; + profile = profiles.personal; + }; + + glados-wsl = { + modules = [inputs.nixos-wsl.nixosModules.wsl]; + profile = profiles.personal; + }; + + atlas = { + modules = [inputs.guzzle_api.nixosModules.default]; + system = "aarch64-linux"; + profile = profiles.server; + }; + }; + + openwrtConfigurations.turret = withSystem "x86_64-linux" ({pkgs, ...}: + pkgs.callPackage ./turret { + inherit (inputs) openwrt-imagebuilder; + }); + }; + + perSystem = {system, ...}: { + apps = (inputs.nixinate.nixinate.${system} self).nixinate; + }; +} diff --git a/parts/systems/glados-wsl/default.nix b/parts/systems/glados-wsl/default.nix new file mode 100644 index 0000000..98b57ed --- /dev/null +++ b/parts/systems/glados-wsl/default.nix @@ -0,0 +1,39 @@ +{ + modulesPath, + pkgs, + ... +}: { + imports = [ + (modulesPath + "/profiles/minimal.nix") + ../../modules/nixos/features/tailscale.nix + ]; + + environment.systemPackages = with pkgs; [ + wslu + ]; + + base.networking.enable = false; + features.tailscale.enable = true; + + wsl = { + enable = true; + defaultUser = "seth"; + nativeSystemd = true; + wslConf.network = { + hostname = "glados-wsl"; + generateResolvConf = true; + }; + startMenuLaunchers = false; + interop.includePath = false; + }; + + services.dbus.apparmor = "disabled"; + + networking.hostName = "glados-wsl"; + + security = { + apparmor.enable = false; + audit.enable = false; + auditd.enable = false; + }; +} diff --git a/parts/systems/glados/boot.nix b/parts/systems/glados/boot.nix new file mode 100644 index 0000000..4a9af4e --- /dev/null +++ b/parts/systems/glados/boot.nix @@ -0,0 +1,25 @@ +{ + lib, + pkgs, + ... +}: { + environment.systemPackages = with pkgs; [ + sbctl + tpm2-tss + ]; + + boot = { + initrd.systemd.enable = true; + kernelPackages = pkgs.linuxPackages_latest; + + bootspec.enable = true; + loader.systemd-boot.enable = lib.mkForce false; + + lanzaboote = { + enable = true; + pkiBundle = "/etc/secureboot"; + }; + + supportedFilesystems = ["btrfs" "ntfs"]; + }; +} diff --git a/parts/systems/glados/default.nix b/parts/systems/glados/default.nix new file mode 100644 index 0000000..de2c1d5 --- /dev/null +++ b/parts/systems/glados/default.nix @@ -0,0 +1,61 @@ +{lib, ...}: { + imports = [ + ./boot.nix + ./hardware-configuration.nix + ../../modules/nixos/features/tailscale.nix + ../../modules/nixos/features/virtualisation.nix + ]; + + boot = { + kernelParams = ["amd_pstate=active"]; + kernel.sysctl = { + "vm.swappiness" = 100; + "vm.vfs_cache_pressure" = 500; + "vm.dirty_background_ratio" = 1; + "vm.dirty_ratio" = 50; + }; + }; + + desktop.gnome.enable = true; + + features = { + tailscale.enable = true; + virtualisation.enable = true; + }; + + hardware = { + nvidia.enable = true; + ssd.enable = true; + }; + + networking.hostName = "glados"; + + security.tpm2 = { + enable = true; + abrmd.enable = true; + }; + + services = { + flatpak.enable = true; + fwupd.enable = true; + }; + + systemd = { + services."prepare-kexec".wantedBy = ["multi-user.target"]; + tmpfiles.rules = let + nproc = 12; + in + builtins.map + (n: "w /sys/devices/system/cpu/cpu${builtins.toString n}/cpufreq/energy_performance_preference - - - - ${"balance_performance"}") + (lib.range 0 (nproc - 1)); + }; + + powerManagement.cpuFreqGovernor = "powersave"; + + zramSwap = { + enable = true; + algorithm = "zstd"; + swapDevices = 1; + memoryPercent = 50; + }; +} diff --git a/parts/systems/glados/hardware-configuration.nix b/parts/systems/glados/hardware-configuration.nix new file mode 100644 index 0000000..a7ff9e9 --- /dev/null +++ b/parts/systems/glados/hardware-configuration.nix @@ -0,0 +1,72 @@ +# Do not modify this file! It was generated by ‘nixos-generate-config’ +# and may be overwritten by future invocations. Please make changes +# to /etc/nixos/configuration.nix instead. +{ + config, + lib, + modulesPath, + ... +}: { + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + + boot = { + extraModulePackages = []; + kernelModules = ["kvm-amd"]; + + initrd = { + availableKernelModules = ["xhci_pci" "ahci" "usb_storage" "usbhid" "sd_mod"]; + kernelModules = []; + + luks.devices."cryptroot" = { + device = "/dev/disk/by-uuid/bbbc1f37-53f5-4776-a70e-f2779179de50"; + allowDiscards = true; + crypttabExtraOpts = ["tpm2-device=auto"]; + }; + }; + }; + + fileSystems = { + "/" = { + device = "/dev/mapper/cryptroot"; + fsType = "btrfs"; + options = ["subvol=root" "compress=zstd" "noatime"]; + }; + + "/var/log" = { + device = "/dev/mapper/cryptroot"; + fsType = "btrfs"; + options = ["subvol=var_log" "compress=zstd" "noatime"]; + }; + + "/nix" = { + device = "/dev/mapper/cryptroot"; + fsType = "btrfs"; + options = ["subvol=nix" "compress=zstd" "noatime" "nodatacow"]; + }; + + "/home" = { + device = "/dev/mapper/cryptroot"; + fsType = "btrfs"; + options = ["subvol=home" "compress=zstd" "noatime"]; + }; + + "/boot" = { + device = "/dev/disk/by-uuid/B95B-9412"; + fsType = "vfat"; + }; + }; + + swapDevices = []; + + # Enables DHCP on each ethernet and wireless interface. In case of scripted networking + # (the default) this is the recommended approach. When using systemd-networkd it's + # still possible to use this option, but it's recommended to use it in conjunction + # with explicit per-interface declarations with `networking.interfaces..useDHCP`. + networking.useDHCP = lib.mkDefault true; + # networking.interfaces.enp4s0.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; +} diff --git a/parts/systems/profiles.nix b/parts/systems/profiles.nix new file mode 100644 index 0000000..277d3c1 --- /dev/null +++ b/parts/systems/profiles.nix @@ -0,0 +1,101 @@ +{ + inputs, + self, + ... +}: let + specialArgs = {inherit inputs self;}; +in { + personal = { + system = "x86_64-linux"; + builder = inputs.nixpkgs.lib.nixosSystem; + inherit specialArgs; + + modules = with inputs; [ + agenix.nixosModules.default + hm.nixosModules.home-manager + nur.nixosModules.nur + self.nixosModules.default + + ../users/seth/system.nix + + { + age = { + identityPaths = ["/etc/age/key"]; + secrets = let + baseDir = "${self}/parts/secrets/shared"; + in { + rootPassword.file = "${baseDir}/rootPassword.age"; + sethPassword.file = "${baseDir}/sethPassword.age"; + }; + }; + + base.enable = true; + system.stateVersion = "23.11"; + + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = specialArgs; + }; + } + ]; + }; + + personal-darwin = { + builder = inputs.darwin.lib.darwinSystem; + inherit specialArgs; + modules = with inputs; [ + hm.darwinModules.home-manager + self.darwinModules.default + + ../users/seth/system.nix + + { + base.enable = true; + desktop.enable = true; + system.stateVersion = 4; + + home-manager = { + useGlobalPkgs = true; + useUserPackages = true; + extraSpecialArgs = specialArgs; + + users.seth = { + imports = [ + ../users/seth/darwin.nix + ]; + + getchoo.desktop.enable = false; + }; + }; + } + ]; + }; + + server = { + builder = inputs.nixpkgs-stable.lib.nixosSystem; + inherit specialArgs; + + modules = with inputs; [ + agenix.nixosModules.default + ../modules/nixos/base + ../modules/nixos/server + ../modules/nixos/features/tailscale.nix + + { + features.tailscale = { + enable = true; + ssh.enable = true; + }; + + server = { + enable = true; + secrets.enable = true; + }; + + nix.registry.n.flake = nixpkgs-stable; + system.stateVersion = "23.05"; + } + ]; + }; +} diff --git a/parts/systems/turret/default.nix b/parts/systems/turret/default.nix new file mode 100644 index 0000000..faac3d2 --- /dev/null +++ b/parts/systems/turret/default.nix @@ -0,0 +1,38 @@ +{ + pkgs, + openwrt-imagebuilder, + ... +}: let + inherit (pkgs) runCommand; + inherit (pkgs.stdenv) mkDerivation; + inherit (openwrt-imagebuilder.lib) build profiles; + wrtProfiles = profiles { + inherit pkgs; + release = "22.03.3"; + }; + config = mkDerivation { + name = "openwrt-config-files"; + src = ./files; + installPhase = '' + mkdir -p $out + cp -r * $out/ + ''; + }; + image = + wrtProfiles.identifyProfile "netgear_wac104" + // { + packages = ["https-dns-proxy"]; + + files = runCommand "image-files" {} '' + mkdir -p $out/etc/uci-defaults + cat > $out/etc/uci-defaults/99-custom <