From bbe6d20e57fef83c8ba1c8ce9c78024e085c01d0 Mon Sep 17 00:00:00 2001 From: Greg Hellings Date: Tue, 19 Nov 2024 22:43:13 -0600 Subject: [PATCH] Migrate matrix from Container to VM --- flake.lock | 37 ++++++++++++++ flake.nix | 10 ++-- hosts/default.nix | 4 ++ hosts/isaiah/default.nix | 1 - hosts/isaiah/matrix.nix | 99 ------------------------------------- hosts/vm-matrix/default.nix | 95 +++++++++++++++++++++++++++++++++++ pkgs/default.nix | 30 +++++------ 7 files changed, 158 insertions(+), 118 deletions(-) delete mode 100644 hosts/isaiah/matrix.nix create mode 100644 hosts/vm-matrix/default.nix diff --git a/flake.lock b/flake.lock index f90eb28..bb12c0c 100644 --- a/flake.lock +++ b/flake.lock @@ -714,6 +714,42 @@ "type": "github" } }, + "nixlib": { + "locked": { + "lastModified": 1731805462, + "narHash": "sha256-yhEMW4MBi+IAyEJyiKbnFvY1uARyMKJpLUhkczI49wk=", + "owner": "nix-community", + "repo": "nixpkgs.lib", + "rev": "b9f04e3cf71c23bea21d2768051e6b3068d44734", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixpkgs.lib", + "type": "github" + } + }, + "nixos-generators": { + "inputs": { + "nixlib": "nixlib", + "nixpkgs": [ + "nixunstable" + ] + }, + "locked": { + "lastModified": 1731892054, + "narHash": "sha256-BJtD9NGUWaBe4OZ1JO77w8qBP9yHDJJUjsxkG/milFc=", + "owner": "nix-community", + "repo": "nixos-generators", + "rev": "15a87ccb45e06d24a9fd5f99a49782efe11b23f0", + "type": "github" + }, + "original": { + "owner": "nix-community", + "repo": "nixos-generators", + "type": "github" + } + }, "nixpkgs": { "locked": { "lastModified": 1723282977, @@ -971,6 +1007,7 @@ "hmunstable": "hmunstable", "hooks": "hooks", "nix23_05": "nix23_05", + "nixos-generators": "nixos-generators", "nixstable": "nixstable", "nixunstable": "nixunstable", "nixvimstable": "nixvimstable", diff --git a/flake.nix b/flake.nix index 1d38bc9..ff11c8e 100644 --- a/flake.nix +++ b/flake.nix @@ -37,6 +37,10 @@ url = "github:nix-community/home-manager/master"; inputs.nixpkgs.follows = "nixstable"; }; + nixos-generators = { + url = "github:nix-community/nixos-generators"; + inputs.nixpkgs.follows = "nixunstable"; + }; nixvimstable.url = "github:nix-community/nixvim/nixos-24.05"; nixvimunstable.url = "github:nix-community/nixvim/main"; nix23_05.url = "github:NixOS/nixpkgs/nixos-23.05"; @@ -57,9 +61,9 @@ packages_overlay = ( _: prev: (import ./pkgs { - inherit self; + inherit self top; pkgs = prev; - }).packages + }) ); overlays = [ top.agenix.overlays.default @@ -104,7 +108,7 @@ pkgs = import top.nixstable { inherit system overlays; }; }; - imports = [ ./pkgs ]; + packages = import ./pkgs { inherit pkgs top; }; checks = import ./checks.nix { inherit system; diff --git a/hosts/default.nix b/hosts/default.nix index 74358e0..57d1438 100644 --- a/hosts/default.nix +++ b/hosts/default.nix @@ -1,5 +1,6 @@ { top, overlays, ... }: let + vm = args: (unstable (args // { extraMods = [ top.nixos-generators.nixosModules.all-formats ]; })); wsl = args: (unstable (args // { extraMods = [ top.wsl.nixosModules.wsl ]; })); unstable = args: @@ -61,6 +62,9 @@ in hosea = unstable { name = "hosea"; }; jeremiah = unstable { name = "jeremiah"; }; isaiah = unstable { name = "isaiah"; }; + + vm-matrix = vm { name = "vm-matrix"; }; + iso = machine { name = "iso"; }; iso-beta = unstable { name = "iso"; }; # nix build '.#nixosConfigurations.wsl.config.system.build.installer' diff --git a/hosts/isaiah/default.nix b/hosts/isaiah/default.nix index 3075300..04bed7f 100644 --- a/hosts/isaiah/default.nix +++ b/hosts/isaiah/default.nix @@ -4,7 +4,6 @@ ./ceph.nix ./hardware-configuration.nix ./git.nix - ./matrix.nix ./minio.nix ]; diff --git a/hosts/isaiah/matrix.nix b/hosts/isaiah/matrix.nix deleted file mode 100644 index 0c0f870..0000000 --- a/hosts/isaiah/matrix.nix +++ /dev/null @@ -1,99 +0,0 @@ -{ pkgs, ... }: -let - conn = "postgresql:///dendrite?sslmode=disable&host=/run/postgresql"; -in -{ - environment.systemPackages = with pkgs; [ upgrade-pg-cluster ]; - - greg.containers.matrix = { - tailscale = true; - subnet = "204"; - builder = - { config, ... }: - { - networking.firewall.allowedTCPPorts = [ config.services.dendrite.httpPort ]; - - # Environment secrets - age = { - secrets.dendrite = { - file = ../../secrets/dendrite.age; - owner = "dendrite"; - }; - secrets.dendrite_key = { - file = ../../secrets/dendrite_key.age; - owner = "dendrite"; - }; - }; - - users.users.dendrite = { - isSystemUser = true; - group = "dendrite"; - }; - users.groups.dendrite = { }; - - systemd.services.dendrite.serviceConfig = { - User = "dendrite"; - }; - - greg.databases.dendrite = { }; - - services.dendrite = { - enable = true; - environmentFile = config.age.secrets.dendrite.path; - httpPort = 8448; - # Identify ourselves as the root of our own domain - settings = ( - (builtins.listToAttrs ( - (map - (x: { - name = x; - value = { - database.connection_string = conn; - }; - }) - [ - "app_service_api" - "federation_api" - "key_server" - "media_api" - "mscs" - "relay_api" - "room_server" - "sync_api" - ] - ) - )) - // { - user_api.account_database.connection_string = conn; - user_api.device_database.connection_string = conn; - global = { - database = { - connection_string = conn; - max_open_conns = 25; - max_idle_conns = 5; - conn_max_lifetime = -1; - }; - server_name = "thehellings.com"; - trusted_third_party_id_servers = [ - "matrix.org" - "vector.im" - "jupiterbroadcasting.com" - ]; - # Generate this with {path-to-dendrite}/bin/generate-keys --private-key /etc/dendrite.pem - private_key = config.age.secrets.dendrite_key.path; - }; - client_api = { - registration_enabled = false; - registration_shared_secret = "\${REGISTRATION_SHARED_SECRET}"; - }; - } - ); - }; - - systemd.services.dendrite = { - after = [ "postgresql.service" ]; - requires = [ "postgresql.service" ]; - }; - }; - }; -} diff --git a/hosts/vm-matrix/default.nix b/hosts/vm-matrix/default.nix new file mode 100644 index 0000000..a98ca5e --- /dev/null +++ b/hosts/vm-matrix/default.nix @@ -0,0 +1,95 @@ +{ pkgs, config, ... }: +let + conn = "postgresql:///dendrite?sslmode=disable&host=/run/postgresql"; +in +{ + environment.systemPackages = with pkgs; [ upgrade-pg-cluster ]; + + greg = { + tailscale.enable = true; + }; + networking.firewall.allowedTCPPorts = [ config.services.dendrite.httpPort ]; + + # Environment secrets + age = { + secrets.dendrite = { + file = ../../secrets/dendrite.age; + owner = "dendrite"; + }; + secrets.dendrite_key = { + file = ../../secrets/dendrite_key.age; + owner = "dendrite"; + }; + }; + users.users = { + dendrite = { + isSystemUser = true; + group = "dendrite"; + }; + greg.initialPassword = "password"; + }; + users.groups.dendrite = { }; + + systemd.services.dendrite.serviceConfig = { + User = "dendrite"; + }; + + greg.databases.dendrite = { }; + + services.dendrite = { + enable = true; + environmentFile = config.age.secrets.dendrite.path; + httpPort = 8448; + # Identify ourselves as the root of our own domain + settings = ( + (builtins.listToAttrs ( + map + (x: { + name = x; + value = { + database.connection_string = conn; + }; + }) + [ + "app_service_api" + "federation_api" + "key_server" + "media_api" + "mscs" + "relay_api" + "room_server" + "sync_api" + ] + )) + // { + user_api.account_database.connection_string = conn; + user_api.device_database.connection_string = conn; + global = { + database = { + connection_string = conn; + max_open_conns = 25; + max_idle_conns = 5; + conn_max_lifetime = -1; + }; + server_name = "thehellings.com"; + trusted_third_party_id_servers = [ + "matrix.org" + "vector.im" + "jupiterbroadcasting.com" + ]; + # Generate this with {path-to-dendrite}/bin/generate-keys --private-key /etc/dendrite.pem + private_key = config.age.secrets.dendrite_key.path; + }; + client_api = { + registration_enabled = false; + registration_shared_secret = "\${REGISTRATION_SHARED_SECRET}"; + }; + } + ); + }; + + systemd.services.dendrite = { + after = [ "postgresql.service" ]; + requires = [ "postgresql.service" ]; + }; +} diff --git a/pkgs/default.nix b/pkgs/default.nix index 33a175a..955e72c 100644 --- a/pkgs/default.nix +++ b/pkgs/default.nix @@ -1,21 +1,21 @@ -{ pkgs, ... }: +{ pkgs, top, ... }: let c = pkgs.callPackage; in { - packages = { - #default = iso; - #iso = top.self.nixosConfigurations.iso.config.system.build.isoImage; - #iso-beta = self.nixosConfigurations.iso-beta.config.system.build.isoImage; - aacs = c ./aacs.nix { }; - brew = c ./homebrew.nix { }; - create_ssl = c ./create_ssl.nix { }; - inject-darwin = c ./inject-darwin.nix { }; - inject = c ./inject.nix { }; - hms = c ./hms { }; - setup-ssh = c ./setup-ssh { }; - upgrade-pg-cluster = c ./upgrade-pg-cluster.nix { }; - zim = c ./zim.nix { }; - }; + #default = iso; + #iso = top.self.nixosConfigurations.iso.config.system.build.isoImage; + #iso-beta = self.nixosConfigurations.iso-beta.config.system.build.isoImage; + aacs = c ./aacs.nix { }; + brew = c ./homebrew.nix { }; + create_ssl = c ./create_ssl.nix { }; + inject-darwin = c ./inject-darwin.nix { }; + inject = c ./inject.nix { }; + hms = c ./hms { }; + setup-ssh = c ./setup-ssh { }; + upgrade-pg-cluster = c ./upgrade-pg-cluster.nix { }; + zim = c ./zim.nix { }; + + matrix = top.nixosConfigurations.vm-matrix.config.formats.qcow; }