Commit Graph

64 Commits

Author SHA1 Message Date
stuebinm
6afb255d97 nixos: remove all uses of lib.mdDoc
these changes were generated with nixq 0.0.2, by running

  nixq ">> lib.mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> mdDoc[remove] Argument[keep]" --batchmode nixos/**.nix
  nixq ">> Inherit >> mdDoc[remove]" --batchmode nixos/**.nix

two mentions of the mdDoc function remain in nixos/, both of which
are inside of comments.

Since lib.mdDoc is already defined as just id, this commit is a no-op as
far as Nix (and the built manual) is concerned.
2024-04-13 10:07:35 -07:00
Maximilian Bosch
e7533df80f
nixos/mastodon: stop mastodon-init-db.service if check for seeded DB fails
The postgresql runs on a different node than my mastodon itself. Sometimes when
rebooting the entire host it can happen that mastodon gets started
before the DB[1] is up. In that case `mastodon-init-db.service` ran
through with the following log output:

    2024-03-07 15:30:56.856
    Migrating database (this might be a noop)
    2024-03-07 15:30:56.856
    /nix/store/xzm7www0qb7jg5zrgg7knynckx5yhki9-unit-script-mastodon-init-db-start/bin/mastodon-init-db-start: line 9: [: -eq: unary operator expected

It seems wrong to me to have this unit pass if the DB isn't even up,
especially with such an error.

This patch now checks if the exit code of the psql check was non-zero
and fails the entire unit. A retry can be implemented e.g. with
Restart/RestartSec then (which is more elegant than adding a while/sleep
loop anyways) like this:

    systemd.services.mastodon-init-db = {
      serviceConfig = {
        Restart = "on-failure";
        RestartSec = "5s";
        RestartMode = "direct";
        RemainAfterExit = true;
      };
      unitConfig = {
        StartLimitBurst = 5;
        StartLimitIntervalSec = "60";
      };
    };

Also using `-t --csv` now to not render the column name and to not
render a table so we don't need to rely on the format of psql (and parse
it with `sed(1)`).

[1] I added a script that blocks until postgres is there in the meantime
    though.
2024-03-22 17:51:20 +01:00
Izorkin
c1a97e1f49
nixos/mastodon: add option redis.passwordFile 2024-02-17 15:52:58 +03:00
Izorkin
cf62e3257f
nixos/mastodon: redis now uses unix socket by default 2024-02-16 16:39:31 +03:00
Isa
24930dadca mastodon: set LimitNOFILE 2024-01-26 12:30:57 +01:00
Izorkin
8a0a8c7a04
nixos/mastodon: replace ffmpeg to ffmpeg-headless 2023-12-20 18:01:55 +03:00
networkException
4dd61b6e68
nixos/mastodon: properly escape arguments to psql in init-db script 2023-12-19 21:02:13 +01:00
Trolli Schmittlauch
cbf69c83d3 nixos/mastodon: clarify the need to set streamingProcesses
Explicitly declaring that option is now necessary, but wasn't in the module shipped with 23.05.
2023-12-04 02:18:39 +01:00
Ryan Lahfa
ccfe07c316
Merge pull request #266270 from Ma27/postgresql-ownership-15 2023-11-17 18:02:17 +01:00
Izorkin
63ed35dac4 nixos/mastodon: update elasticsearch configuration 2023-11-15 14:01:47 +01:00
Kerstin Humm
c82195d9e8
mastodon: 4.1.6 -> 4.2.1
- run streaming processes in separate systemd services
- remove redundancy in test
- fix update script
- release notes

See https://github.com/mastodon/mastodon/releases/tag/v4.2.1 for details
2023-11-14 21:13:46 +01:00
Maximilian Bosch
48459567ae nixos/postgresql: drop ensurePermissions, fix ensureUsers for postgresql15
Closes #216989

First of all, a bit of context: in PostgreSQL, newly created users don't
have the CREATE privilege on the public schema of a database even with
`ALL PRIVILEGES` granted via `ensurePermissions` which is how most of
the DB users are currently set up "declaratively"[1]. This means e.g. a
freshly deployed Nextcloud service will break early because Nextcloud
itself cannot CREATE any tables in the public schema anymore.

The other issue here is that `ensurePermissions` is a mere hack. It's
effectively a mixture of SQL code (e.g. `DATABASE foo` is relying on how
a value is substituted in a query. You'd have to parse a subset of SQL
to actually know which object are permissions granted to for a user).

After analyzing the existing modules I realized that in every case with
a single exception[2] the UNIX system user is equal to the db user is
equal to the db name and I don't see a compelling reason why people
would change that in 99% of the cases. In fact, some modules would even
break if you'd change that because the declarations of the system user &
the db user are mixed up[3].

So I decided to go with something new which restricts the ways to use
`ensure*` options rather than expanding those[4]. Effectively this means
that

* The DB user _must_ be equal to the DB name.
* Permissions are granted via `ensureDBOwnerhip` for an attribute-set in
  `ensureUsers`. That way, the user is actually the owner and can
  perform `CREATE`.
* For such a postgres user, a database must be declared in
  `ensureDatabases`.

For anything else, a custom state management should be implemented. This
can either be `initialScript`, doing it manual, outside of the module or
by implementing proper state management for postgresql[5], but the
current state of `ensure*` isn't even declarative, but a convergent tool
which is what Nix actually claims to _not_ do.

Regarding existing setups: there are effectively two options:

* Leave everything as-is (assuming that system user == db user == db
  name): then the DB user will automatically become the DB owner and
  everything else stays the same.

* Drop the `createDatabase = true;` declarations: nothing will change
  because a removal of `ensure*` statements is ignored, so it doesn't
  matter at all whether this option is kept after the first deploy (and
  later on you'd usually restore from backups anyways).

  The DB user isn't the owner of the DB then, but for an existing setup
  this is irrelevant because CREATE on the public schema isn't revoked
  from existing users (only not granted for new users).

[1] not really declarative though because removals of these statements
    are simply ignored for instance: https://github.com/NixOS/nixpkgs/issues/206467
[2] `services.invidious`: I removed the `ensure*` part temporarily
    because it IMHO falls into the category "manage the state on your
    own" (see the commit message). See also
    https://github.com/NixOS/nixpkgs/pull/265857
[3] e.g. roundcube had `"DATABASE ${cfg.database.username}" = "ALL PRIVILEGES";`
[4] As opposed to other changes that are considered a potential fix, but
    also add more things like collation for DBs or passwords that are
    _never_ touched again when changing those.
[5] As suggested in e.g. https://github.com/NixOS/nixpkgs/issues/206467
2023-11-13 17:16:25 +01:00
Felix Buehler
933a41a73f treewide: use optional instead of 'then []' 2023-06-25 09:11:40 -03:00
figsoda
701bcdbead nixos: fix typos 2023-05-19 22:31:04 -04:00
Kerstin Humm
aff288424f
nixos/mastodon: fixup sidekiq jobClasses assertion
See https://github.com/NixOS/nixpkgs/pull/225005#issuecomment-1516677321
2023-04-20 22:58:34 +02:00
Sandro
6152b09a6a
Merge pull request #225005 from erictapen/mastodon-sidekiq 2023-04-12 21:31:50 +02:00
Kerstin Humm
431ccf26e4
nixos/mastodon: add assertion for only allowing one sidekiq scheduler queue 2023-04-09 13:24:43 +02:00
Viv Lim
c778f4d225 nixos/mastodon: Allow configuring sidekiq processes
This change allows the number of sidekiq processes and which job classes
they handle to be configured.

An instance admin may choose to have separate sidekiq processes handling
jobs related to local users (`default` job class) and jobs related to
federation (`push`, `pull`, `ingress`), so that as the instance grows
and takes on more federation traffic, the local users' experience is not
as impacted.

For more details, see https://docs.joinmastodon.org/admin/scaling/#sidekiq

This pr also includes the following changes suggested in review:

- adds syslog identifiers for mastodon services
- moves working directory config to common cfgService
- adds mastodon.target
2023-04-06 16:30:16 +02:00
George Shammas
fef1559b05 nixos/mastodon: Add the ability to pass environment files 2023-01-15 00:18:40 -05:00
Sandro Jäckel
3071db258b
nixos/mastodon: remove duplicated shebang 2023-01-07 18:06:57 +01:00
Izorkin
8e14bf10c2
nixos/mastodon: update database configuration 2022-12-16 16:19:39 +03:00
Izorkin
e2cebf2134
nixos/mastodon: fix init db on remote postgresql 2022-12-16 16:14:39 +03:00
Vladimir Pouzanov
65aed3b37f
Allow to override the https settings 2022-12-09 19:23:50 +00:00
Lin Yinfeng
56099e008e nixos/mastodon: allow appending other env files to serviceConfig.EnvironmentFile 2022-12-07 15:07:17 +01:00
Sandro
e38618a657
Merge pull request #203825 from SuperSandro2000/mastodon-tootctl
Closes https://github.com/NixOS/nixpkgs/issues/199029
2022-12-04 11:29:45 +01:00
Sandro Jäckel
6e845a8491
nixos/mastodon: replace mastodon-env with a proper wrapper mastodon-tootctl 2022-12-03 02:59:39 +01:00
Daniel Nagy
dbe8182e74
treewide: switch to port type for nixos modules 2022-12-01 22:30:00 +01:00
Izorkin
93de6bf9ed nixos/mastodon: add smtp assertions 2022-11-28 12:07:32 +01:00
Izorkin
17933082cc nixos/mastodon: fix emoji import 2022-11-21 11:43:28 +01:00
Justinas Stankevicius
3f6eb10dbd nixos/mastodon: fix definition of mastodon-media-auto-remove 2022-11-12 22:22:41 +01:00
Manuel Bärenz
891dfb1b63 nixos/mastodon: add option mediaAutoRemove 2022-11-07 18:58:58 +01:00
Izorkin
2bb8cc27bd nixos/mastodon: fix start services 2022-10-26 16:35:23 +02:00
pennae
1d41cff3dc nixos/*: convert straggler options to MD 2022-08-31 17:27:38 +02:00
pennae
ef176dcf7e nixos/*: automatically convert option descriptions
conversions were done using https://github.com/pennae/nix-doc-munge
using (probably) rev f34e145 running

    nix-doc-munge nixos/**/*.nix
    nix-doc-munge --import nixos/**/*.nix

the tool ensures that only changes that could affect the generated
manual *but don't* are committed, other changes require manual review
and are discarded.
2022-08-31 16:32:53 +02:00
pennae
6039648c50 nixos/*: automatically convert option docs 2022-08-19 22:40:58 +02:00
pennae
8f8e101527 nixos/*: normalize <package> to <literal>
this renders the same in the manpage and a little more clearly in the
html manual. in the manpage there continues to be no distinction from
regular text, the html manual gets code-type markup (which was probably
the intention for most of these uses anyway).
2022-08-19 22:40:58 +02:00
pennae
61e93df189 nixos/*: automatically convert option docs to MD
once again using nix-doc-munge (69d080323a)
2022-08-03 22:46:41 +02:00
pennae
16102dce2f nixos/*: replace <code> in option docs with <literal>
markdown can't represent the difference without another extension and
both the html manual and the manpage render them the same, so keeping the
distinction is not very useful on its own. with the distinction removed
we can automatically convert many options that use <code> tags to markdown.

the manpage remains unchanged, html manual does not render
differently (but class names on code tags do change from "code" to "literal").
2022-08-03 21:03:23 +02:00
pennae
2e751c0772 treewide: automatically md-convert option descriptions
the conversion procedure is simple:

 - find all things that look like options, ie calls to either `mkOption`
   or `lib.mkOption` that take an attrset. remember the attrset as the
   option
 - for all options, find a `description` attribute who's value is not a
   call to `mdDoc` or `lib.mdDoc`
 - textually convert the entire value of the attribute to MD with a few
   simple regexes (the set from mdize-module.sh)
 - if the change produced a change in the manual output, discard
 - if the change kept the manual unchanged, add some text to the
   description to make sure we've actually found an option. if the
   manual changes this time, keep the converted description

this procedure converts 80% of nixos options to markdown. around 2000
options remain to be inspected, but most of those fail the "does not
change the manual output check": currently the MD conversion process
does not faithfully convert docbook tags like <code> and <package>, so
any option using such tags will not be converted at all.
2022-07-30 15:16:34 +02:00
Jelle Besseling
0f69a517a4 nixos/mastodon: use redis.servers 2022-05-13 15:39:44 +02:00
Kerstin Humm
f44b12fb52 mastodon: use correct GitHub Url
The tootsuite organization was renamed to mastodon ages ago.
2022-03-31 13:17:11 +02:00
Kerstin Humm
23a1971a4e nixos/mastodon: preload libjemalloc.so
Co-authored-by: Izorkin <izorkin@elven.pw>
2022-03-31 13:17:11 +02:00
Jelle Besseling
29366071a4 nixos/mastodon: add RAILS_ROOT to mastodon-env 2022-02-19 16:42:45 +01:00
Izorkin
d1a8806e39 nixos/mastodon: allow '@resources' filter to mastodon-web service 2021-11-07 11:59:36 +01:00
Izorkin
a71576b07b nixos/mastodon/streaming: add '@memlock' SystemCallFilter 2021-11-06 16:45:20 +01:00
Izorkin
91e510ae22 nixos/mastodon: add '@ipc' SystemCallFilter 2021-11-06 16:45:20 +01:00
Izorkin
700ea62f54 nixos/mastodon: remove duplicates SystemCallFilters 2021-11-06 16:45:20 +01:00
Izorkin
943f15d4b7 nixos/mastodon: add new sandboxing options 2021-11-06 16:45:20 +01:00
Izorkin
1d948428c8
nixos/mastodon: fix send e-mail notifications 2021-10-26 10:59:39 +03:00
Naïm Favier
2ddc335e6f
nixos/doc: clean up defaults and examples 2021-10-04 12:47:20 +02:00