diff --git a/deployment/check/cli/constants.nix b/deployment/check/cli/constants.nix index ce3b5e4d..3e23d9e9 100644 --- a/deployment/check/cli/constants.nix +++ b/deployment/check/cli/constants.nix @@ -4,6 +4,7 @@ "mastodon" "peertube" "pixelfed" + "attic" ]; pathToRoot = ../../..; pathFromRoot = ./.; diff --git a/deployment/check/cli/flake-part.nix b/deployment/check/cli/flake-part.nix new file mode 100644 index 00000000..fbb24589 --- /dev/null +++ b/deployment/check/cli/flake-part.nix @@ -0,0 +1,91 @@ +{ + self, + inputs, + lib, + sources, + ... +}: + +let + inherit (builtins) fromJSON readFile listToAttrs; + + targetMachines = [ + "garage" + "mastodon" + "peertube" + "pixelfed" + "attic" + ]; + pathToRoot = /. + (builtins.unsafeDiscardStringContext self); + pathFromRoot = ./.; + enableAcme = true; + +in +{ + _class = "flake"; + + perSystem = + { pkgs, ... }: + { + checks.deployment-cli = pkgs.testers.runNixOSTest { + imports = [ + ../common/nixosTest.nix + ./nixosTest.nix + ]; + _module.args = { inherit inputs sources; }; + inherit + targetMachines + pathToRoot + pathFromRoot + enableAcme + ; + }; + }; + + nixops4Deployments = + let + makeTargetResource = nodeName: { + imports = [ ../common/targetResource.nix ]; + _module.args = { inherit inputs sources; }; + inherit + nodeName + pathToRoot + pathFromRoot + enableAcme + ; + }; + + ## The deployment function - what we are here to test! + ## + ## TODO: Modularise `deployment/default.nix` to get rid of the nested + ## function calls. + makeTestDeployment = + args: + (import ../..) + { + inherit lib; + inherit (inputs) nixops4 nixops4-nixos; + fediversity = import ../../../services/fediversity; + } + (listToAttrs ( + map (nodeName: { + name = "${nodeName}ConfigurationResource"; + value = makeTargetResource nodeName; + }) targetMachines + )) + (fromJSON (readFile ../../configuration.sample.json) // args); + + in + { + check-deployment-cli-nothing = makeTestDeployment { }; + + check-deployment-cli-mastodon-pixelfed = makeTestDeployment { + mastodon.enable = true; + pixelfed.enable = true; + }; + + check-deployment-cli-peertube = makeTestDeployment { + peertube.enable = true; + }; + }; +} diff --git a/deployment/check/cli/nixosTest.nix b/deployment/check/cli/nixosTest.nix index d171a182..80ee3be3 100644 --- a/deployment/check/cli/nixosTest.nix +++ b/deployment/check/cli/nixosTest.nix @@ -68,6 +68,11 @@ in s3AccessKeyFile = dummyFile; s3SecretKeyFile = dummyFile; }; + attic = { + enable = true; + s3AccessKeyFile = dummyFile; + s3SecretKeyFile = dummyFile; + }; temp.cores = 1; temp.initialUser = { username = "dummy"; @@ -92,6 +97,7 @@ in nodes.mastodon.virtualisation.memorySize = 4 * 1024; nodes.pixelfed.virtualisation.memorySize = 4 * 1024; nodes.peertube.virtualisation.memorySize = 5 * 1024; + nodes.attic.virtualisation.memorySize = 2 * 1024; ## FIXME: The test of presence of the services are very simple: we only ## check that there is a systemd service of the expected name on the @@ -106,6 +112,7 @@ in mastodon.fail("systemctl status mastodon-web.service") peertube.fail("systemctl status peertube.service") pixelfed.fail("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") with subtest("Run deployment with no services enabled"): deployer.succeed("nixops4 apply check-deployment-cli-nothing --show-trace --no-interactive 1>&2") @@ -115,6 +122,7 @@ in mastodon.fail("systemctl status mastodon-web.service") peertube.fail("systemctl status peertube.service") pixelfed.fail("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") with subtest("Run deployment with Mastodon and Pixelfed enabled"): deployer.succeed("nixops4 apply check-deployment-cli-mastodon-pixelfed --show-trace --no-interactive 1>&2") @@ -124,6 +132,7 @@ in mastodon.succeed("systemctl status mastodon-web.service") peertube.fail("systemctl status peertube.service") pixelfed.succeed("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") with subtest("Run deployment with only Peertube enabled"): deployer.succeed("nixops4 apply check-deployment-cli-peertube --show-trace --no-interactive 1>&2") @@ -133,5 +142,6 @@ in mastodon.fail("systemctl status mastodon-web.service") peertube.succeed("systemctl status peertube.service") pixelfed.fail("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") ''; } diff --git a/deployment/check/common/deployerNode.nix b/deployment/check/common/deployerNode.nix index 987a0a7c..fe21beda 100644 --- a/deployment/check/common/deployerNode.nix +++ b/deployment/check/common/deployerNode.nix @@ -40,7 +40,7 @@ in ## default. These values have been trimmed down to the gigabyte. ## Memory use is expected to be dominated by the NixOS evaluation, ## which happens on the deployer. - memorySize = 4 * 1024; + memorySize = 5 * 1024; diskSize = 4 * 1024; cores = 2; }; @@ -61,6 +61,7 @@ in sources.flake-parts sources.flake-inputs sources.git-hooks + sources.vars pkgs.stdenv pkgs.stdenvNoCC diff --git a/deployment/check/panel/constants.nix b/deployment/check/panel/constants.nix index ce3b5e4d..3e23d9e9 100644 --- a/deployment/check/panel/constants.nix +++ b/deployment/check/panel/constants.nix @@ -4,6 +4,7 @@ "mastodon" "peertube" "pixelfed" + "attic" ]; pathToRoot = ../../..; pathFromRoot = ./.; diff --git a/deployment/check/panel/nixosTest.nix b/deployment/check/panel/nixosTest.nix index ffcb8e53..85b3719b 100644 --- a/deployment/check/panel/nixosTest.nix +++ b/deployment/check/panel/nixosTest.nix @@ -33,6 +33,7 @@ let enableMastodon, enablePeertube, enablePixelfed, + enableAttic, }: hostPkgs.writers.writePython3Bin "interact-with-panel" { @@ -94,6 +95,7 @@ let checkbox_set(driver.find_element(By.XPATH, "//input[@name = 'mastodon.enable']"), ${toPythonBool enableMastodon}) checkbox_set(driver.find_element(By.XPATH, "//input[@name = 'peertube.enable']"), ${toPythonBool enablePeertube}) checkbox_set(driver.find_element(By.XPATH, "//input[@name = 'pixelfed.enable']"), ${toPythonBool enablePixelfed}) + checkbox_set(driver.find_element(By.XPATH, "//input[@name = 'attic.enable']"), ${toPythonBool enableAttic}) print("Start deployment...") driver.find_element(By.XPATH, "//button[@id = 'deploy-button']").click() @@ -208,6 +210,11 @@ in s3AccessKeyFile = dummyFile; s3SecretKeyFile = dummyFile; }; + attic = { + enable = true; + s3AccessKeyFile = dummyFile; + s3SecretKeyFile = dummyFile; + }; temp.cores = 1; temp.initialUser = { username = "dummy"; @@ -253,6 +260,7 @@ in nodes.mastodon.virtualisation.memorySize = 4 * 1024; nodes.pixelfed.virtualisation.memorySize = 4 * 1024; nodes.peertube.virtualisation.memorySize = 5 * 1024; + nodes.attic.virtualisation.memorySize = 2 * 1024; ## FIXME: The test of presence of the services are very simple: we only ## check that there is a systemd service of the expected name on the @@ -325,6 +333,7 @@ in mastodon.fail("systemctl status mastodon-web.service") peertube.fail("systemctl status peertube.service") pixelfed.fail("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") with subtest("Run deployment with no services enabled"): client.succeed("${ @@ -333,6 +342,7 @@ in enableMastodon = false; enablePeertube = false; enablePixelfed = false; + enableAttic = false; } }/bin/interact-with-panel >&2") @@ -341,6 +351,7 @@ in mastodon.fail("systemctl status mastodon-web.service") peertube.fail("systemctl status peertube.service") pixelfed.fail("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") with subtest("Run deployment with Mastodon and Pixelfed enabled"): client.succeed("${ @@ -349,6 +360,7 @@ in enableMastodon = true; enablePeertube = false; enablePixelfed = true; + enableAttic = false; } }/bin/interact-with-panel >&2") @@ -357,6 +369,7 @@ in mastodon.succeed("systemctl status mastodon-web.service") peertube.fail("systemctl status peertube.service") pixelfed.succeed("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") with subtest("Run deployment with only Peertube enabled"): client.succeed("${ @@ -365,6 +378,7 @@ in enableMastodon = false; enablePeertube = true; enablePixelfed = false; + enableAttic = false; } }/bin/interact-with-panel >&2") @@ -373,5 +387,6 @@ in mastodon.fail("systemctl status mastodon-web.service") peertube.succeed("systemctl status peertube.service") pixelfed.fail("systemctl status phpfpm-pixelfed.service") + attic.fail("systemctl status atticd.service") ''; } diff --git a/infra/common/resource.nix b/infra/common/resource.nix index 26b57c29..20475364 100644 --- a/infra/common/resource.nix +++ b/infra/common/resource.nix @@ -33,8 +33,10 @@ in ## should go into the `./nixos` subdirectory. nixos.module = { imports = [ - "${sources.agenix}/modules/age.nix" - "${sources.disko}/module.nix" + "${agenix}/modules/age.nix" + "${disko}/module.nix" + "${vars}/options.nix" + "${vars}/backends/on-machine.nix" ./options.nix ./nixos ]; diff --git a/services/fediversity/attic/default.nix b/services/fediversity/attic/default.nix index 292ebff5..dcfc3858 100644 --- a/services/fediversity/attic/default.nix +++ b/services/fediversity/attic/default.nix @@ -48,12 +48,7 @@ in attic = { inherit (config.fediversity.attic) s3AccessKeyFile s3SecretKeyFile; ensureAccess = { - peertube-videos = { - read = true; - write = true; - owner = true; - }; - peertube-playlists = { + attic = { read = true; write = true; owner = true; @@ -108,8 +103,8 @@ in outPath = "./attic.env"; text = '' ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64=${fileContents config.vars.generators.attic.files.token.path} - AWS_ACCESS_KEY_ID=$(cat ${config.fediversity.peertube.s3AccessKeyFile}) - AWS_SECRET_ACCESS_KEY=$(cat ${config.fediversity.peertube.s3SecretKeyFile}) + AWS_ACCESS_KEY_ID=$(cat ${config.fediversity.attic.s3AccessKeyFile}) + AWS_SECRET_ACCESS_KEY=$(cat ${config.fediversity.attic.s3SecretKeyFile}) ''; } }/bin/attic.env"; @@ -255,41 +250,54 @@ in #default-retention-period = "6 months"; }; - jwt = { - # WARNING: Changing _anything_ in this section will break any existing - # tokens. If you need to regenerate them, ensure that you use the the - # correct secret and include the `iss` and `aud` claims. + # jwt = { + # WARNING: Changing _anything_ in this section will break any existing + # tokens. If you need to regenerate them, ensure that you use the the + # correct secret and include the `iss` and `aud` claims. - # JWT `iss` claim - # - # Set this to the JWT issuer that you want to validate. - # If this is set, all received JWTs will validate that the `iss` claim - # matches this value. - #token-bound-issuer = "some-issuer"; + # JWT `iss` claim + # + # Set this to the JWT issuer that you want to validate. + # If this is set, all received JWTs will validate that the `iss` claim + # matches this value. + #token-bound-issuer = "some-issuer"; - # JWT `aud` claim - # - # Set this to the JWT audience(s) that you want to validate. - # If this is set, all received JWTs will validate that the `aud` claim - # contains at least one of these values. - #token-bound-audiences = ["some-audience1", "some-audience2"]; - }; + # JWT `aud` claim + # + # Set this to the JWT audience(s) that you want to validate. + # If this is set, all received JWTs will validate that the `aud` claim + # contains at least one of these values. + #token-bound-audiences = ["some-audience1", "some-audience2"]; + # }; # jwt.signing = { - # # JWT RS256 secret key - # # - # # Set this to the base64-encoded private half of an RSA PEM PKCS1 key. - # # TODO - # # You can also set it via the `ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64` - # # environment variable. - # token-rs256-secret-base64 = "%token_rs256_secret_base64%"; + # You must configure JWT signing and verification inside your TOML configuration by setting one of the following options in the [jwt.signing] block: + # * token-rs256-pubkey-base64 + # * token-rs256-secret-base64 + # * token-hs256-secret-base64 + # or by setting one of the following environment variables: + # * ATTIC_SERVER_TOKEN_RS256_PUBKEY_BASE64 + # * ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64 + # * ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64 + # Options will be tried in that same order (configuration options first, then environment options if none of the configuration options were set, starting with the respective RSA pubkey option, the RSA secret option, and finally the HMAC secret option). The first option that is found will be used. + # If an RS256 pubkey (asymmetric RSA PEM PKCS1 public key) is provided, it will only be possible to verify received JWTs, and not sign new JWTs. + # If an RS256 secret (asymmetric RSA PEM PKCS1 private key) is provided, it will be used for both signing new JWTs and verifying received JWTs. + # If an HS256 secret (symmetric HMAC secret) is provided, it will be used for both signing new JWTs and verifying received JWTs. - # # JWT HS256 secret key - # # - # # Set this to the base64-encoded HMAC secret key. - # # You can also set it via the `ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64` - # # environment variable. - # #token-hs256-secret-base64 = ""; + # JWT RS256 secret key + # + # Set this to the base64-encoded private half of an RSA PEM PKCS1 key. + # TODO + # You can also set it via the `ATTIC_SERVER_TOKEN_RS256_SECRET_BASE64` + # environment variable. + # token-rs256-secret-base64 = "%token_rs256_secret_base64%"; + + # JWT HS256 secret key + # + # Set this to the base64-encoded HMAC secret key. + # You can also set it via the `ATTIC_SERVER_TOKEN_HS256_SECRET_BASE64` + # environment variable. + #token-hs256-secret-base64 = ""; # }; }; };