Home Explore Blog CI



nixpkgs

2nd chunk of `nixos/modules/services/web-apps/akkoma.md`
5132192510f3652a4b5173819965976e252405d551f007470000000100000fbf
  # Adjust the persistent cache size as needed:
  #  Assuming an average object size of 128 KiB, around 1 MiB
  #  of memory is required for the key zone per GiB of cache.
  # Ensure that the cache directory exists and is writable by nginx.
  services.nginx.commonHttpConfig = ''
    proxy_cache_path /var/cache/nginx/cache/akkoma-media-cache
      levels= keys_zone=akkoma_media_cache:16m max_size=16g
      inactive=1y use_temp_path=off;
  '';

  services.akkoma.nginx = {
    locations."/proxy" = {
      proxyPass = "http://unix:/run/akkoma/socket";

      extraConfig = ''
        proxy_cache akkoma_media_cache;

        # Cache objects in slices of 1 MiB
        slice 1m;
        proxy_cache_key $host$uri$is_args$args$slice_range;
        proxy_set_header Range $slice_range;

        # Decouple proxy and upstream responses
        proxy_buffering on;
        proxy_cache_lock on;
        proxy_ignore_client_abort on;

        # Default cache times for various responses
        proxy_cache_valid 200 1y;
        proxy_cache_valid 206 301 304 1h;

        # Allow serving of stale items
        proxy_cache_use_stale error timeout invalid_header updating;
      '';
    };
  };
}
```

#### Prefetch remote media {#modules-services-akkoma-prefetch-remote-media}

The following example enables the `MediaProxyWarmingPolicy` MRF policy which automatically
fetches all media associated with a post through the media proxy, as soon as the post is
received by the instance.

```nix
{
  services.akkoma.config.":pleroma".":mrf".policies =
    map (pkgs.formats.elixirConf { }).lib.mkRaw [
      "Pleroma.Web.ActivityPub.MRF.MediaProxyWarmingPolicy"
  ];
}
```

#### Media previews {#modules-services-akkoma-media-previews}

Akkoma can generate previews for media.

```nix
{
  services.akkoma.config.":pleroma".":media_preview_proxy" = {
    enabled = true;
    thumbnail_max_width = 1920;
    thumbnail_max_height = 1080;
  };
}
```

## Frontend management {#modules-services-akkoma-frontend-management}

Akkoma will be deployed with the `akkoma-fe` and `admin-fe` frontends by default. These can be
modified by setting
[{option}`services.akkoma.frontends`](options.html#opt-services.akkoma.frontends).

The following example overrides the primary frontend’s default configuration using a custom
derivation.

```nix
{
  services.akkoma.frontends.primary.package = pkgs.runCommand "akkoma-fe" {
    config = builtins.toJSON {
      expertLevel = 1;
      collapseMessageWithSubject = false;
      stopGifs = false;
      replyVisibility = "following";
      webPushHideIfCW = true;
      hideScopeNotice = true;
      renderMisskeyMarkdown = false;
      hideSiteFavicon = true;
      postContentType = "text/markdown";
      showNavShortcuts = false;
    };
    nativeBuildInputs = with pkgs; [ jq xorg.lndir ];
    passAsFile = [ "config" ];
  } ''
    mkdir $out
    lndir ${pkgs.akkoma-frontends.akkoma-fe} $out

    rm $out/static/config.json
    jq -s add ${pkgs.akkoma-frontends.akkoma-fe}/static/config.json ${config} \
      >$out/static/config.json
  '';
}
```

## Federation policies {#modules-services-akkoma-federation-policies}

Akkoma comes with a number of modules to police federation with other ActivityPub instances.
The most valuable for typical users is the
[`:mrf_simple`](https://docs.akkoma.dev/stable/configuration/cheatsheet/#mrf_simple) module
which allows limiting federation based on instance hostnames.

This configuration snippet provides an example on how these can be used. Choosing an adequate
federation policy is not trivial and entails finding a balance between connectivity to the rest
of the fediverse and providing a pleasant experience to the users of an instance.


```nix
{
  services.akkoma.config.":pleroma" = with (pkgs.formats.elixirConf { }).lib; {
    ":mrf".policies = map mkRaw [
      "Pleroma.Web.ActivityPub.MRF.SimplePolicy"
    ];

    ":mrf_simple" = {
      # Tag all media as sensitive
      media_nsfw = mkMap {
        "nsfw.weird.kinky" = "Untagged NSFW content";

Title: Akkoma Media Proxy, Previews, Frontend Management, and Federation Policies
Summary
This section covers advanced Akkoma configuration, including setting up a media proxy cache with Nginx, enabling automatic media prefetching, generating media previews, managing frontends with custom configurations, and implementing federation policies to control interactions with other ActivityPub instances.