From 1eeaa04df6d567ebd6964f5c424a2a278494d42a Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Nicolas=20=E2=80=9CNiols=E2=80=9D=20Jeannerod?=
 <nicolas.jeannerod@moduscreate.com>
Date: Fri, 14 Feb 2025 20:10:55 +0100
Subject: [PATCH] Introduce `fediversity.garage.enable`

---
 deployment/flake-part.nix               | 3 +++
 services/fediversity/garage/default.nix | 4 ++--
 services/fediversity/garage/options.nix | 2 ++
 3 files changed, 7 insertions(+), 2 deletions(-)

diff --git a/deployment/flake-part.nix b/deployment/flake-part.nix
index 0eeba75b..8560e9c3 100644
--- a/deployment/flake-part.nix
+++ b/deployment/flake-part.nix
@@ -88,6 +88,7 @@ in
                 s3AccessKeyFile = pkgs.writeText "s3AccessKey" "GKb5615457d44214411e673b7b";
                 s3SecretKeyFile = pkgs.writeText "s3SecretKey" "5be6799a88ca9b9d813d1a806b64f15efa49482dbe15339ddfaf7f19cf434987";
               };
+              garage.enable = true;
             };
           }
         );
@@ -104,6 +105,7 @@ in
                 s3AccessKeyFile = pkgs.writeText "s3AccessKey" "GK3515373e4c851ebaad366558";
                 s3SecretKeyFile = pkgs.writeText "s3SecretKey" "7d37d093435a41f2aab8f13c19ba067d9776c90215f56614adad6ece597dbb34";
               };
+              garage.enable = true;
 
               temp.cores = 1; # FIXME: should come from NixOps4 eventually
             };
@@ -123,6 +125,7 @@ in
                 s3AccessKeyFile = pkgs.writeText "s3AccessKey" "GK1f9feea9960f6f95ff404c9b";
                 s3SecretKeyFile = pkgs.writeText "s3SecretKey" "7295c4201966a02c2c3d25b5cea4a5ff782966a2415e3a196f91924631191395";
               };
+              garage.enable = true;
             };
           }
         );
diff --git a/services/fediversity/garage/default.nix b/services/fediversity/garage/default.nix
index e3a6012d..4d7dc696 100644
--- a/services/fediversity/garage/default.nix
+++ b/services/fediversity/garage/default.nix
@@ -16,7 +16,7 @@ in
 
 let
   inherit (builtins) toString;
-  inherit (lib) optionalString concatStringsSep;
+  inherit (lib) optionalString concatStringsSep mkIf;
   inherit (lib.strings) escapeShellArg;
   inherit (lib.attrsets) filterAttrs mapAttrs';
   concatMapAttrs = scriptFn: attrset: concatStringsSep "\n" (lib.mapAttrsToList scriptFn attrset);
@@ -99,7 +99,7 @@ in
 {
   imports = [ ./options.nix ];
 
-  config = {
+  config = mkIf config.fediversity.garage.enable {
     environment.systemPackages = [
       pkgs.minio-client
       pkgs.awscli
diff --git a/services/fediversity/garage/options.nix b/services/fediversity/garage/options.nix
index baeda2c9..e5281582 100644
--- a/services/fediversity/garage/options.nix
+++ b/services/fediversity/garage/options.nix
@@ -6,6 +6,8 @@ in
 
 {
   options.fediversity.garage = {
+    enable = mkEnableOption "Enable a Garage server on the machine";
+
     ensureBuckets = mkOption {
       type = types.attrsOf (
         types.submodule {