Home Explore Blog Models CI



nixpkgs

2nd chunk of `nixos/modules/services/web-apps/akkoma.md`
9b48cf51b001a665316de7391c09262d2ae1f572d6c38cdc0000000100000fa4
  # 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" ];

Title: Akkoma Media Caching, Previews, Frontends, and Federation Policies
Summary
This chunk details advanced configuration for Akkoma, specifically focusing on media handling, frontend customization, and federation policies. It continues the Nginx media proxy setup, providing specific directives for cache path, slice-based caching, proxy buffering, and cache validity. It then outlines how to enable automatic prefetching of remote media via the `MediaProxyWarmingPolicy` and configure media preview generation (including thumbnail dimensions). The document also explains frontend management, demonstrating how to override default frontend configurations (like `akkoma-fe`) through custom Nix derivations to modify settings like `expertLevel` and `postContentType`. Finally, it introduces federation policing modules, highlighting the `:mrf_simple` policy for restricting federation based on instance hostnames.