From a50ae2e751d77b55138e91be8025fda1d1a2a3b0 Mon Sep 17 00:00:00 2001 From: Lily Anderson Date: Fri, 13 Feb 2026 19:36:19 -0600 Subject: [PATCH] Added server configs. --- .sops.yaml | 7 + flake.lock | 37 +++- flake.nix | 25 +-- modules/hosts/server/configuration.nix | 36 ++++ .../hosts/server/hardware-configuration.nix | 40 ++++ modules/hosts/server/nginx.nix | 172 ++++++++++++++++++ modules/hosts/server/server.nix | 13 ++ secrets/secrets.yaml | 23 +++ 8 files changed, 340 insertions(+), 13 deletions(-) create mode 100644 .sops.yaml create mode 100644 modules/hosts/server/configuration.nix create mode 100644 modules/hosts/server/hardware-configuration.nix create mode 100644 modules/hosts/server/nginx.nix create mode 100644 modules/hosts/server/server.nix create mode 100644 secrets/secrets.yaml diff --git a/.sops.yaml b/.sops.yaml new file mode 100644 index 0000000..581abb3 --- /dev/null +++ b/.sops.yaml @@ -0,0 +1,7 @@ +keys: + - &primary age1mvup35ycxdxum8ergeagtjqxshdprr8av9yg5myl89y5nthwyqhqws86ny +creation_rules: + - path_regex: secrets/secrets.yaml$ + key_groups: + - age: + - *primary diff --git a/flake.lock b/flake.lock index 3c54115..ec45d4c 100644 --- a/flake.lock +++ b/flake.lock @@ -85,6 +85,22 @@ } }, "nixpkgs_2": { + "locked": { + "lastModified": 1770380644, + "narHash": "sha256-P7dWMHRUWG5m4G+06jDyThXO7kwSk46C1kgjEWcybkE=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "ae67888ff7ef9dff69b3cf0cc0fbfbcd3a722abe", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_3": { "locked": { "lastModified": 1764667669, "narHash": "sha256-7WUCZfmqLAssbDqwg9cUDAXrSoXN79eEEq17qhTNM/Y=", @@ -106,12 +122,31 @@ "home-manager": "home-manager", "import-tree": "import-tree", "nixpkgs": "nixpkgs", + "sops-nix": "sops-nix", "wrappers": "wrappers" } }, + "sops-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1770683991, + "narHash": "sha256-xVfPvXDf9QN3Eh9dV+Lw6IkWG42KSuQ1u2260HKvpnc=", + "owner": "Mic92", + "repo": "sops-nix", + "rev": "8b89f44c2cc4581e402111d928869fe7ba9f7033", + "type": "github" + }, + "original": { + "owner": "Mic92", + "repo": "sops-nix", + "type": "github" + } + }, "wrappers": { "inputs": { - "nixpkgs": "nixpkgs_2" + "nixpkgs": "nixpkgs_3" }, "locked": { "lastModified": 1770971207, diff --git a/flake.nix b/flake.nix index 0e135fe..e8590bc 100644 --- a/flake.nix +++ b/flake.nix @@ -1,17 +1,18 @@ { - description = "Lily's NixOS, LiNix"; + description = "Lily's NixOS, LiNix"; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; - wrappers.url = "github:Lassulus/wrappers"; - flake-parts.url = "github:hercules-ci/flake-parts"; - import-tree.url = "github:vic/import-tree"; - home-manager = { - url = "github:nix-community/home-manager"; - inputs.nixpkgs.follows = "nixpkgs"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable"; + wrappers.url = "github:Lassulus/wrappers"; + flake-parts.url = "github:hercules-ci/flake-parts"; + import-tree.url = "github:vic/import-tree"; + sops-nix.url = "github:Mic92/sops-nix"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; - }; + }; - outputs = inputs: inputs.flake-parts.lib.mkFlake {inherit inputs;} (inputs.import-tree ./modules); + outputs = inputs: inputs.flake-parts.lib.mkFlake {inherit inputs;} (inputs.import-tree ./modules); } diff --git a/modules/hosts/server/configuration.nix b/modules/hosts/server/configuration.nix new file mode 100644 index 0000000..f8df0cd --- /dev/null +++ b/modules/hosts/server/configuration.nix @@ -0,0 +1,36 @@ +{self, inputs, ...}: { + flake.nixosModules.serverConfig = { pkgs, ... }: { + boot.loader.systemd-boot.enable = true; + boot.loader.efi.canTouchEfiVariables = true; + + networking.hostName = "lily-server"; + networking.networkmanager.enable = true; + + services.displayManager.sddm.enable = true; + services.desktopManager.plasma6.enable = true; + + services.openssh = { + enable = true; + settings = { + PasswordAuthentication = false; + PermitRootLogin = "no"; + X11Forwarding = false; + }; + }; + + nixpkgs.config.allowUnfree = true; + networking.firewall.allowedTCPPorts = [ 22 80 443 9001 9002 ]; + + nix.settings.experimental-features = [ "nix-command" "flakes" ]; + + programs.firefox.enable = true; + environment.systemPackages = [ + pkgs.vim + + self.packages.${pkgs.stdenv.hostPlatform.system}.nh + + ]; + system.stateVersion = "24.11"; + }; +} + diff --git a/modules/hosts/server/hardware-configuration.nix b/modules/hosts/server/hardware-configuration.nix new file mode 100644 index 0000000..076d35d --- /dev/null +++ b/modules/hosts/server/hardware-configuration.nix @@ -0,0 +1,40 @@ +{ + flake.nixosModules.serverHardware = { config, lib, modulesPath, ... }: { + imports = [ + (modulesPath + "/installer/scan/not-detected.nix") + ]; + boot.initrd.availableKernelModules = [ "xhci_pci" "ehci_pci" "ahci" "usbhid" "usb_storage" "sd_mod" "sr_mod" ]; + boot.initrd.kernelModules = [ ]; + boot.kernelModules = [ "kvm-intel" ]; + boot.extraModulePackages = [ ]; + + fileSystems = { + "/" = { + device = "/dev/disk/by-uuid/208d39a0-fa7d-4fe4-be61-8867e7a51bc8"; + fsType = "ext4"; + }; + + "/boot" = { + device = "/dev/disk/by-uuid/AED2-D209"; + fsType = "vfat"; + options = [ "fmask=0077" "dmask=0077" ]; + }; + }; + + swapDevices = [ { + device = "/dev/disk/by-uuid/ec9d9773-d48b-4221-af73-7c365fe0966d"; + } ]; + +# 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.eno1.useDHCP = lib.mkDefault true; + + nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux"; + hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + + }; +} + diff --git a/modules/hosts/server/nginx.nix b/modules/hosts/server/nginx.nix new file mode 100644 index 0000000..91b69c8 --- /dev/null +++ b/modules/hosts/server/nginx.nix @@ -0,0 +1,172 @@ +{inputs, ...}: { + flake.nixosModules.nginx = { config, pkgs, ... }: { + imports = [ inputs.sops-nix.nixosModules.sops ]; + users.users.nginx.extraGroups = [ "acme" ]; + systemd.services.webdavPrivate = { + description = "Rclone WebDAV server"; + after = [ "network.target" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + ExecStart = '' + ${pkgs.rclone}/bin/rclone serve webdav --addr :8081 --baseurl / --htpasswd /var/www/basic_auth /var/www/dav.lilyanderson.xyz + ''; + Restart = "always"; + }; + }; + + services.nginx = { + enable = true; + + virtualHosts = { + "lilyanderson.xyz" = { + locations."/" = { + root = "/var/www/web"; + }; + }; + + "ai.lilyanderson.xyz" = { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://localhost:9001"; + }; + extraConfig = '' + client_body_timeout 300; + client_header_timeout 300; + keepalive_timeout 300; + proxy_connect_timeout 300; + proxy_send_timeout 300; + proxy_read_timeout 300; + +# Add WebSocket support +proxy_http_version 1.1; +proxy_set_header Upgrade $http_upgrade; +proxy_set_header Connection "upgrade"; + +proxy_set_header Host $host; +proxy_set_header X-Real-IP $remote_addr; +proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; +proxy_set_header X-Forwarded-Proto $scheme; + +# Disable proxy buffering for better streaming response from models +proxy_buffering off; +''; + }; + + "dav.lilyanderson.xyz" = { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://localhost:8081"; + }; + }; + + "swap.lilyanderson.xyz" = { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://192.168.0.101:9001"; + }; + basicAuthFile = "/var/www/basic_auth"; + }; + + "192.168.0.42" = { + }; + + + "git.lilyanderson.xyz" = { + enableACME = true; + forceSSL = true; + locations."/" = { + proxyPass = "http://localhost:3001"; + }; + }; + }; + }; + services.postgresql = { + ensureDatabases = [ config.services.gitea.user ]; + ensureUsers = [ + { + name = config.services.gitea.database.user; + ensureDBOwnership = true; +#ensurePermissions."DATABASE ${config.services.gitea.database.name}" = "ALL PRIVILEGES"; + } + ]; + }; + + sops = { + age.keyFile = "/secrets/age/keys.txt"; + defaultSopsFile = ../../../secrets/secrets.yaml; + defaultSopsFormat = "yaml"; + secrets = { + "postgres/gitea_dbpass".owner = config.services.gitea.user; + "porkbun/api_pk".owner = "root"; + "porkbun/api_sk".owner = "root"; + }; + }; + + services.gitea = { + enable = true; + appName = "Lily's Gitea Server"; + database = { + type = "postgres"; + passwordFile = config.sops.secrets."postgres/gitea_dbpass".path; + }; + + settings.service.DISABLE_REGISTRATION = true; + + settings.server = { + DOMAIN = "git.lilyanderson.xyz"; + ROOT_URL = "https://git.lilyanderson.xyz"; + HTTP_PORT = 3001; + }; + }; + + + + security.acme = { + acceptTerms = true; + defaults.email = "lilylanderson@zoho.com"; + }; + + services.open-webui = { + enable = true; + host = "0.0.0.0"; + port = 9001; + environment = { + ANONYMIZED_TELEMETRY = "False"; + DO_NOT_TRACK = "True"; + SCARF_NO_ANALYTICS = "True"; + ENABLE_LOGIN_FORM = "True"; + }; + }; + + services.oink = { + enable = true; + apiKeyFile = config.sops.secrets."porkbun/api_pk".path; + secretApiKeyFile = config.sops.secrets."porkbun/api_sk".path; + domains = [ + { + domain = "ausrineblackthorn.com"; + subdomain = ""; + ttl = 600; + } + { + domain = "ausrineblackthorn.com"; + subdomain = "*"; + ttl = 600; + } + { + domain = "lilyanderson.xyz"; + subdomain = ""; + ttl = 600; + } + { + domain = "lilyanderson.xyz"; + subdomain = "*"; + ttl = 600; + } + ]; + }; + }; +} diff --git a/modules/hosts/server/server.nix b/modules/hosts/server/server.nix new file mode 100644 index 0000000..a0f5d2e --- /dev/null +++ b/modules/hosts/server/server.nix @@ -0,0 +1,13 @@ +{ inputs, self, ... }: { + flake.nixosConfigurations.lily-server = inputs.nixpkgs.lib.nixosSystem { + modules = [ + self.nixosModules.serverConfig + self.nixosModules.serverHardware + self.nixosModules.nginx + + self.nixosModules.lily + + self.nixosModules.localization + ]; + }; +} diff --git a/secrets/secrets.yaml b/secrets/secrets.yaml new file mode 100644 index 0000000..294d7c5 --- /dev/null +++ b/secrets/secrets.yaml @@ -0,0 +1,23 @@ +porkbun: + api_pk: ENC[AES256_GCM,data:B2jR1JqqXegJ0xv7N6ydQy53m7GK8cEP0TclKdYynUgHeYjKYhuxbXh4+4wQer1IhZ9Xt9303TyYfjdUrH7Yzmk1yUg=,iv:mgKW9ZUrRA/VyxEdu6Hlq5JnoY7wczt5DatM7ibm840=,tag:S04wFVuGr/C2pLmt3jJ0sg==,type:str] + api_sk: ENC[AES256_GCM,data:MuvdysEmAroa/9A5FlDo3Wg9zrv8PBPXJZeJusHAYWGatXcVATYkEejYUfIj2hZIC73DzUExyVK3k1PCbNJiWV7aPSA=,iv:Ob3GRVIed3PFfNbjheOvihfgu0taB0QtGwXKHxEK/6E=,tag:XfeNRFBjwUVrQxARgdXiTA==,type:str] +postgres: + gitea_dbpass: ENC[AES256_GCM,data:mFs+6HQ5viKWqwyTbzO0XE0frhg=,iv:j1nGCUHH7ZdL5XcSwxPngJ1XrIyQdh2Ynr9hl7b2wmY=,tag:KcSDYKVYxV2pdVBmkIxHfQ==,type:str] +env_file: ENC[AES256_GCM,data:O8lNrxeG//OuM2Hgmo71oVncRSnfUMg7Db2YE6/NY2g+iP7T+EWKcujL/OATklMOAVEptRSDXHgCPHJbZFLp4SALmrE2qhnr4NZY3mJU4dJf7CERhFhnLtN60Pj3xmsdoswdf4goYOBlM3iv+x7D3btr5G4AlUFIUnsqU316SZ0CiGT7wHtbdrIIBVGQ5iTfnlK0lio2tTjtqUCTN6ED3xmzZemOtJopkE9GuoDb58q2z0j1uWe5vcg=,iv:44HlK6Owy47VYdt1r+g/X7mUqHM/OAiecKsVgdiAJkI=,tag:3chEB6bWNfWJXXr123y+mg==,type:str] +nextcloud: + pass: ENC[AES256_GCM,data:EY5FH2CCCj4qxCauLHnuGQ==,iv:lxCgsfdT8K/3GmRI5PtMNTFGHlx5uzjTn51ORb9V0/c=,tag:ReYl31yDuhtY7mekhX/uwg==,type:str] +sops: + age: + - recipient: age1mvup35ycxdxum8ergeagtjqxshdprr8av9yg5myl89y5nthwyqhqws86ny + enc: | + -----BEGIN AGE ENCRYPTED FILE----- + YWdlLWVuY3J5cHRpb24ub3JnL3YxCi0+IFgyNTUxOSBxQ3hKR09JSXAvTnh2VDhu + ZzE2V093Z0I2Qzk4elFJaWJNMUF3cGwzWVdBCkRUcGxlNVFlQk1TZnNSSU5Bd2or + Z3VIL3drOEtSbmlxdWY1SnBGallXS2sKLS0tIGxKNjFRMlhiRnlpeGpvMEptTFYv + cGNCaHpWV0hsSlptN041Z1pRMjliUUEKaowR90GNNfov6jGOEufBF1fnj647mn9E + cQGbvv6PeEXJaUgQrr37WNXCdBVCrksd/ofB6hQ/J4qiOajO8ztTLQ== + -----END AGE ENCRYPTED FILE----- + lastmodified: "2025-05-22T04:36:40Z" + mac: ENC[AES256_GCM,data:5NsT0r5JLYV3QOPG46kXvN81eWPEyv7WFizpAO8jXJuJovzMSf5T8/BRqspTepd3y8dBifR3Fyc6K6RcklUA5xCOsZde0Kx5pJI6KaPcSwJAw9iVX7P+ahGdt+gRc9XwNgNKRtBgoqMe8Q76mr4ohxiCLsG0TBboLO/SotrQIeE=,iv:fLCq7Un+ugPmgZL4qpVadw0em1aRCsZ/VRDDXHZ480M=,tag:desvrZhekZulhqd+xxME3g==,type:str] + unencrypted_suffix: _unencrypted + version: 3.10.2