From 7f99fc48dded24fe439637f2c52ce902f99dd219 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?= Date: Tue, 17 Sep 2024 14:30:59 +0200 Subject: [PATCH] Move Fediversity modules under top-level module --- fediversity/default.nix | 27 +++++++++++++++++++++++++++ fediversity/garage.nix | 10 +++++++--- fediversity/mastodon.nix | 5 ++++- fediversity/peertube.nix | 5 ++++- fediversity/pixelfed.nix | 5 ++++- flake.nix | 21 +++++++++------------ tests/mastodon-garage.nix | 2 +- tests/pixelfed-garage.nix | 6 +----- vm/mastodon-vm.nix | 10 +++++++++- vm/pixelfed-vm.nix | 12 +++++++++++- 10 files changed, 77 insertions(+), 26 deletions(-) create mode 100644 fediversity/default.nix diff --git a/fediversity/default.nix b/fediversity/default.nix new file mode 100644 index 0000000..6e38fbd --- /dev/null +++ b/fediversity/default.nix @@ -0,0 +1,27 @@ +{ lib, ... }: + +let + inherit (lib) mkOption; + inherit (lib.types) types; + +in { + imports = [ + ./garage.nix + ./mastodon.nix + ./pixelfed.nix + ./peertube.nix + ]; + + options = { + fediversity = { + enable = mkOption { + type = types.bool; + default = false; + }; + + mastodon.enable = mkOption { type = types.bool; default = false; }; + pixelfed.enable = mkOption { type = types.bool; default = false; }; + peertube.enable = mkOption { type = types.bool; default = false; }; + }; + }; +} diff --git a/fediversity/garage.nix b/fediversity/garage.nix index 478443d..aad2925 100644 --- a/fediversity/garage.nix +++ b/fediversity/garage.nix @@ -6,8 +6,10 @@ let secret = "82b2b4cbef27bf8917b350d5b10a87c92fa9c8b13a415aeeea49726cf335d74e"; }; in + # TODO: expand to a multi-machine setup -{ config, lib, pkgs, ... }: +{ config, lib, pkgs, ... }: + let inherit (lib) types mkOption mkEnableOption optionalString concatStringsSep; inherit (lib.strings) escapeShellArg; @@ -53,7 +55,9 @@ let ${concatMapAttrs (ensureAccessScriptFn key) ensureAccess} ''; ensureKeysScript = concatMapAttrs ensureKeyScriptFn cfg.ensureKeys; -in { +in + +{ # add in options to ensure creation of buckets and keys options = { services.garage = { @@ -126,7 +130,7 @@ in { }; }; - config = { + config = lib.mkIf config.fediversity.enable { virtualisation.diskSize = 2048; virtualisation.forwardPorts = [ { diff --git a/fediversity/mastodon.nix b/fediversity/mastodon.nix index e0c2ea4..5a349f6 100644 --- a/fediversity/mastodon.nix +++ b/fediversity/mastodon.nix @@ -4,7 +4,10 @@ let secret = "7d37d093435a41f2aab8f13c19ba067d9776c90215f56614adad6ece597dbb34"; }; in -{ config, lib, pkgs, ... }: { + +{ config, lib, pkgs, ... }: + +lib.mkIf (config.fediversity.enable && config.fediversity.mastodon.enable) { #### garage setup services.garage = { ensureBuckets = { diff --git a/fediversity/peertube.nix b/fediversity/peertube.nix index e0d4926..95e1c32 100644 --- a/fediversity/peertube.nix +++ b/fediversity/peertube.nix @@ -4,7 +4,10 @@ let secret = "7295c4201966a02c2c3d25b5cea4a5ff782966a2415e3a196f91924631191395"; }; in -{ config, lib, pkgs, ... }: { + +{ config, lib, pkgs, ... }: + +lib.mkIf (config.fediversity.enable && config.fediversity.peertube.enable) { networking.firewall.allowedTCPPorts = [ 80 9000 ]; services.garage = { diff --git a/fediversity/pixelfed.nix b/fediversity/pixelfed.nix index 9d2281f..1d04f60 100644 --- a/fediversity/pixelfed.nix +++ b/fediversity/pixelfed.nix @@ -4,7 +4,10 @@ let secret = "5be6799a88ca9b9d813d1a806b64f15efa49482dbe15339ddfaf7f19cf434987"; }; in -{ config, lib, pkgs, ... }: { + +{ config, lib, pkgs, ... }: + +lib.mkIf (config.fediversity.enable && config.fediversity.pixelfed.enable) { services.garage = { ensureBuckets = { pixelfed = { diff --git a/flake.nix b/flake.nix index 49d00cb..737ad31 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,7 @@ nixpkgs.url = "github:radvendii/nixpkgs/nixos_rebuild_tests"; }; - outputs = { self, nixpkgs }: + outputs = { self, nixpkgs }: let system = "x86_64-linux"; pkgs = nixpkgs.legacyPackages.${system}; @@ -13,10 +13,7 @@ nixosModules = { ## Fediversity modules - garage = import ./fediversity/garage.nix; - mastodon = import ./fediversity/mastodon.nix; - peertube = import ./fediversity/peertube.nix; - pixelfed = import ./fediversity/pixelfed.nix; + fediversity = import ./fediversity; ## VM-specific modules interactive-vm = import ./vm/interactive-vm.nix; @@ -28,27 +25,27 @@ nixosConfigurations = { mastodon = nixpkgs.lib.nixosSystem { inherit system; - modules = with self.nixosModules; [ interactive-vm mastodon mastodon-vm garage ]; + modules = with self.nixosModules; [ fediversity interactive-vm mastodon-vm ]; }; peertube = nixpkgs.lib.nixosSystem { inherit system; - modules = with self.nixosModules; [ interactive-vm peertube peertube-vm garage ]; + modules = with self.nixosModules; [ fediversity interactive-vm peertube-vm ]; }; pixelfed = nixpkgs.lib.nixosSystem { inherit system; - modules = with self.nixosModules; [ interactive-vm pixelfed pixelfed-vm garage ]; + modules = with self.nixosModules; [ fediversity interactive-vm pixelfed-vm ]; }; all = nixpkgs.lib.nixosSystem { inherit system; modules = with self.nixosModules; [ + fediversity interactive-vm - peertube peertube-vm - pixelfed pixelfed-vm - mastodon mastodon-vm - garage + peertube-vm + pixelfed-vm + mastodon-vm ]; }; }; diff --git a/tests/mastodon-garage.nix b/tests/mastodon-garage.nix index d20c5ad..f98440d 100644 --- a/tests/mastodon-garage.nix +++ b/tests/mastodon-garage.nix @@ -37,7 +37,7 @@ pkgs.nixosTest { nodes = { server = { config, ... }: { virtualisation.memorySize = lib.mkVMOverride 4096; - imports = with self.nixosModules; [ garage mastodon mastodon-vm ]; + imports = with self.nixosModules; [ mastodon-vm ]; # TODO: pair down environment.systemPackages = with pkgs; [ python3 diff --git a/tests/pixelfed-garage.nix b/tests/pixelfed-garage.nix index a08a312..79e1edc 100644 --- a/tests/pixelfed-garage.nix +++ b/tests/pixelfed-garage.nix @@ -136,11 +136,7 @@ pkgs.nixosTest { memorySize = lib.mkVMOverride 8192; cores = 8; }; - imports = with self.nixosModules; [ - garage - pixelfed - pixelfed-vm - ]; + imports = with self.nixosModules; [ pixelfed-vm ]; # TODO: pair down environment.systemPackages = with pkgs; [ python3 diff --git a/vm/mastodon-vm.nix b/vm/mastodon-vm.nix index fcfe3e5..0d13b89 100644 --- a/vm/mastodon-vm.nix +++ b/vm/mastodon-vm.nix @@ -1,9 +1,17 @@ { modulesPath, lib, config, ... }: { - imports = [ (modulesPath + "/virtualisation/qemu-vm.nix") ]; + imports = [ + ../fediversity + (modulesPath + "/virtualisation/qemu-vm.nix") + ]; config = lib.mkMerge [ { + fediversity = { + enable = true; + mastodon.enable = true; + }; + services.mastodon = { # redirects to localhost, but allows it to have a proper domain name localDomain = "mastodon.localhost"; diff --git a/vm/pixelfed-vm.nix b/vm/pixelfed-vm.nix index 451aeda..be238f1 100644 --- a/vm/pixelfed-vm.nix +++ b/vm/pixelfed-vm.nix @@ -1,5 +1,15 @@ { pkgs, modulesPath, ... }: { - imports = [ (modulesPath + "/virtualisation/qemu-vm.nix") ]; + + imports = [ + ../fediversity + (modulesPath + "/virtualisation/qemu-vm.nix") + ]; + + fediversity = { + enable = true; + pixelfed.enable = true; + }; + networking.firewall.allowedTCPPorts = [ 80 ]; services.pixelfed = { domain = "pixelfed.localhost";