diff --git a/fediversity/default.nix b/fediversity/default.nix new file mode 100644 index 00000000..6e38fbda --- /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 478443d5..aad2925f 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 e0c2ea42..5a349f6f 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 e0d49269..95e1c32a 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 9d2281fb..1d04f608 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 49d00cb4..737ad310 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 d20c5ad5..f98440d0 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 a08a312e..79e1edc2 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 fcfe3e54..0d13b89e 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 451aeda1..be238f13 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";