commit 8d551299d92fd8bf6e5cb3e63a24dc4adaa3c5bd Author: Mikhail Klementev Date: Mon Jan 9 13:13:56 2023 +0000 Initial diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..849b2f0 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +secrets.nix +hardware-configuration.nix diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..47df30c --- /dev/null +++ b/LICENSE @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) 2023 Mikhail Klementev + +Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. \ No newline at end of file diff --git a/configuration.nix b/configuration.nix new file mode 100644 index 0000000..2c533e3 --- /dev/null +++ b/configuration.nix @@ -0,0 +1,78 @@ +{ config, pkgs, lib, ... }: +let + secrets = import ./secrets.nix; +in { + imports = [ + ./hardware-configuration.nix + ./mastodon.nix + ]; + + boot.loader = { + efi.canTouchEfiVariables = true; + grub = { + enable = true; + efiSupport = true; + device = "nodev"; + mirroredBoots = [{ + devices = [ "nodev" ]; + path = "/boot-fallback"; + }]; + }; + }; + + networking = { + hostName = "lor-sh"; + hostId = (builtins.substring 0 8 (builtins.readFile "/etc/machine-id")); + + useDHCP = false; + + interfaces.eno1 = { + ipv4 = secrets.ipv4; + ipv6 = secrets.ipv6; + }; + + nameservers = [ "1.1.1.1" ]; + + firewall = { + enable = true; + allowedTCPPorts = [ 80 443 ]; + }; + }; + + users.extraUsers.root = { + openssh.authorizedKeys.keys = secrets.pubkeys; + }; + + services.openssh.enable = true; + + environment.systemPackages = with pkgs; [ + vim htop git + ]; + + services.postgresql.settings = { + max_connections = "512"; + shared_buffers = "4096MB"; + }; + + security.acme = { + acceptTerms = true; + defaults.email = secrets.letsencryptEmail; + }; + + time.timeZone = "UTC"; + + system.autoUpgrade = { + enable = true; + allowReboot = true; + }; + + system.stateVersion = "22.11"; + + nix = { + optimise.automatic = true; + gc = { + automatic = true; + options = "--delete-older-than 7d"; + }; + }; +} diff --git a/mastodon.nix b/mastodon.nix new file mode 100644 index 0000000..c2e03c4 --- /dev/null +++ b/mastodon.nix @@ -0,0 +1,112 @@ +{ config, pkgs, lib, ... }: + +let + secrets = import ./secrets.nix; + + branding = '' + cp app/javascript/images/logo.svg app/javascript/images/app-icon.svg + + PATH=$PATH:${pkgs.librsvg}/bin:${pkgs.imagemagick}/bin \ + RAILS_ENV=development rake branding:generate + ''; + + mastodon-lor-sh = (pkgs.mastodon.overrideAttrs(x: { + patchPhase = branding; + mastodon-modules = pkgs.mastodon.mastodon-modules.overrideAttrs(y: { + patchPhase = branding; + }); + })).override { + srcOverride = pkgs.applyPatches { + src = pkgs.fetchgit { + url = "https://github.com/mastodon/mastodon.git"; + rev = "v4.0.2"; # "v${pkgs.mastodon.version}"; + sha256 = "sha256-gNP/YDioLquxasVpgmCqLnCQx4r/gnIQ3N4YrVcI6+s="; + }; + patches = [ + ./patches/logo.patch + ./patches/logo-symbol-wordmark.patch + ./patches/mascot.patch + + ./patches/add-tango-theme.patch + ./patches/add-merveilles-theme.patch + ./patches/add-black-theme.patch + ./patches/themes-config.patch + ./patches/fix-mastodon-light-highlight-color.patch + + ./patches/fix-character-limit.patch + ./patches/max-toot-chars-api.patch + + ./patches/simple-form.patch + ]; + }; + }; + + sidekiq-manager = pkgs.writers.writePython3 "sidekiq-manager" {} '' + from itertools import permutations + from subprocess import Popen + + + def sidekiq(queues, connections=16): + mastodon = "${mastodon-lor-sh}" + cmd = [f"{mastodon}/bin/sidekiq", "-r", mastodon] + cmd += ["-c", f"{connections}"] + for q in queues: + cmd += ['-q', q] + return Popen(cmd) + + + procs = [sidekiq(['mailers', 'pull', 'scheduler'])] + + queues = ['default', 'push', 'ingress'] + procs += [sidekiq(qs) for qs in permutations(queues)] + + for p in procs: + p.wait() + ''; +in { + # Until merge of https://github.com/NixOS/nixpkgs/pull/202408 + systemd.services.mastodon-sidekiq.serviceConfig.ExecStart = + lib.mkForce "${sidekiq-manager}"; + + # https://github.com/mperham/sidekiq/wiki/Memory#bloat + systemd.services.mastodon-sidekiq.environment.MALLOC_ARENA_MAX = "2"; + + services.mastodon = { + enable = true; + + package = mastodon-lor-sh; + + localDomain = "lor.sh"; + configureNginx = true; + + smtp = { + createLocally = false; + authenticate = true; + host = "smtp.eu.mailgun.org"; + port = 587; + fromAddress = "Mastodon "; + user = "mastodon@m.lor.sh"; + passwordFile = builtins.toFile "smtp-password" secrets.smtpPassword; + }; + + vapidPublicKeyFile = builtins.toFile "vapidPublicKey" secrets.vapidPublicKey; + secretKeyBaseFile = builtins.toFile "secretKeyBase" secrets.secretKeyBase; + otpSecretFile = builtins.toFile "otpSecret" secrets.otpSecret; + vapidPrivateKeyFile = builtins.toFile "vapidPrivateKey" secrets.vapidPrivateKey; + + extraConfig = { + S3_ENABLED = "true"; + S3_PROTOCOL = "https"; + S3_BUCKET = "lor-sh"; + S3_REGION = "eu-central-1"; + S3_HOSTNAME = "s3.eu-central-1.wasabisys.com"; + S3_ENDPOINT = "https://s3.eu-central-1.wasabisys.com/lor-sh"; + S3_ALIAS_HOST = "s3.eu-central-1.wasabisys.com/lor-sh/lor-sh"; + AWS_ACCESS_KEY_ID = secrets.AWS_ACCESS_KEY_ID; + AWS_SECRET_ACCESS_KEY = secrets.AWS_SECRET_ACCESS_KEY; + + DEEPL_API_KEY = secrets.DEEPL_API_KEY; + DEEPL_PLAN = "pro"; + }; + }; +} diff --git a/patches/add-black-theme.patch b/patches/add-black-theme.patch new file mode 100644 index 0000000..da6788f --- /dev/null +++ b/patches/add-black-theme.patch @@ -0,0 +1,9 @@ +diff --git a/app/javascript/styles/black.scss b/app/javascript/styles/black.scss +new file mode 100644 +index 000000000..5598dbea0 +--- /dev/null ++++ b/app/javascript/styles/black.scss +@@ -0,0 +1,3 @@ ++$ui-base-color: #000000; ++ ++@import 'application'; diff --git a/patches/add-merveilles-theme.patch b/patches/add-merveilles-theme.patch new file mode 100644 index 0000000..3ec3e42 --- /dev/null +++ b/patches/add-merveilles-theme.patch @@ -0,0 +1,10 @@ +diff --git a/app/javascript/styles/merveilles.scss b/app/javascript/styles/merveilles.scss +new file mode 100644 +index 000000000..5147ae626 +--- /dev/null ++++ b/app/javascript/styles/merveilles.scss +@@ -0,0 +1,4 @@ ++$ui-base-color: #222222; ++$ui-highlight-color: #333333; ++ ++@import "application"; diff --git a/patches/add-tango-theme.patch b/patches/add-tango-theme.patch new file mode 100644 index 0000000..ba8a284 --- /dev/null +++ b/patches/add-tango-theme.patch @@ -0,0 +1,10 @@ +diff --git a/app/javascript/styles/tango.scss b/app/javascript/styles/tango.scss +new file mode 100644 +index 000000000..9699d17b5 +--- /dev/null ++++ b/app/javascript/styles/tango.scss +@@ -0,0 +1,4 @@ ++$ui-base-color: #2f3436; ++$ui-highlight-color: #5c90c7; ++ ++@import 'application'; diff --git a/patches/fix-character-limit.patch b/patches/fix-character-limit.patch new file mode 100644 index 0000000..1d65aba --- /dev/null +++ b/patches/fix-character-limit.patch @@ -0,0 +1,35 @@ +diff --git a/app/javascript/mastodon/features/compose/components/compose_form.js b/app/javascript/mastodon/features/compose/components/compose_form.js +index 6a65f44da..d67e29db3 100644 +--- a/app/javascript/mastodon/features/compose/components/compose_form.js ++++ b/app/javascript/mastodon/features/compose/components/compose_form.js +@@ -90,7 +90,7 @@ class ComposeForm extends ImmutablePureComponent { + const fulltext = this.getFulltextForCharacterCounting(); + const isOnlyWhitespace = fulltext.length !== 0 && fulltext.trim().length === 0; + +- return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 500 || (isOnlyWhitespace && !anyMedia)); ++ return !(isSubmitting || isUploading || isChangingUpload || length(fulltext) > 100500 || (isOnlyWhitespace && !anyMedia)); + } + + handleSubmit = (e) => { +@@ -277,7 +277,7 @@ class ComposeForm extends ImmutablePureComponent { + + +
+- ++ +
+ + +diff --git a/app/validators/status_length_validator.rb b/app/validators/status_length_validator.rb +index e107912b7..1e374a84d 100644 +--- a/app/validators/status_length_validator.rb ++++ b/app/validators/status_length_validator.rb +@@ -1,7 +1,7 @@ + # frozen_string_literal: true + + class StatusLengthValidator < ActiveModel::Validator +- MAX_CHARS = 500 ++ MAX_CHARS = 100500 + URL_PLACEHOLDER_CHARS = 23 + URL_PLACEHOLDER = 'x' * 23 + diff --git a/patches/fix-mastodon-light-highlight-color.patch b/patches/fix-mastodon-light-highlight-color.patch new file mode 100644 index 0000000..b63bcc3 --- /dev/null +++ b/patches/fix-mastodon-light-highlight-color.patch @@ -0,0 +1,13 @@ +diff --git a/app/javascript/styles/mastodon-light/variables.scss b/app/javascript/styles/mastodon-light/variables.scss +index cae065878..29de2a9b3 100644 +--- a/app/javascript/styles/mastodon-light/variables.scss ++++ b/app/javascript/styles/mastodon-light/variables.scss +@@ -5,7 +5,7 @@ $white: #ffffff; + $classic-base-color: #282c37; + $classic-primary-color: #9baec8; + $classic-secondary-color: #d9e1e8; +-$classic-highlight-color: #6364ff; ++$classic-highlight-color: #5c90c7; + + // Differences + $success-green: lighten(#3c754d, 8%); diff --git a/patches/logo-symbol-wordmark.patch b/patches/logo-symbol-wordmark.patch new file mode 100644 index 0000000..05d4662 --- /dev/null +++ b/patches/logo-symbol-wordmark.patch @@ -0,0 +1,37 @@ +diff --git a/app/javascript/images/logo-symbol-wordmark.svg b/app/javascript/images/logo-symbol-wordmark.svg +index 7e7f7b087..7824ea4af 100644 +--- a/app/javascript/images/logo-symbol-wordmark.svg ++++ b/app/javascript/images/logo-symbol-wordmark.svg +@@ -1,11 +1,22 @@ +- +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ + diff --git a/patches/logo.patch b/patches/logo.patch new file mode 100644 index 0000000..3656049 --- /dev/null +++ b/patches/logo.patch @@ -0,0 +1,485 @@ +diff --git a/app/javascript/images/logo.svg b/app/javascript/images/logo.svg +index 11d0c30c5..e141dba08 100644 +--- a/app/javascript/images/logo.svg ++++ b/app/javascript/images/logo.svg +@@ -1,10 +1,471 @@ +- +- +- +- +- +- +- +- +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ + diff --git a/patches/mascot.patch b/patches/mascot.patch new file mode 100644 index 0000000..deb310f --- /dev/null +++ b/patches/mascot.patch @@ -0,0 +1,477 @@ +diff --git a/app/javascript/images/elephant_ui_plane.svg b/app/javascript/images/elephant_ui_plane.svg +index ca675c9eb..e141dba08 100644 +--- a/app/javascript/images/elephant_ui_plane.svg ++++ b/app/javascript/images/elephant_ui_plane.svg +@@ -1 +1,471 @@ +- ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ diff --git a/patches/max-toot-chars-api.patch b/patches/max-toot-chars-api.patch new file mode 100644 index 0000000..62f054c --- /dev/null +++ b/patches/max-toot-chars-api.patch @@ -0,0 +1,21 @@ +diff --git a/app/serializers/rest/instance_serializer.rb b/app/serializers/rest/instance_serializer.rb +index 5ae1099d0..c9c76c700 100644 +--- a/app/serializers/rest/instance_serializer.rb ++++ b/app/serializers/rest/instance_serializer.rb +@@ -11,11 +11,16 @@ class REST::InstanceSerializer < ActiveModel::Serializer + + attributes :domain, :title, :version, :source_url, :description, + :usage, :thumbnail, :languages, :configuration, ++ :max_toot_chars, + :registrations + + has_one :contact, serializer: ContactSerializer + has_many :rules, serializer: REST::RuleSerializer + ++ def max_toot_chars ++ StatusLengthValidator::MAX_CHARS ++ end ++ + def thumbnail + if object.thumbnail + { diff --git a/patches/simple-form.patch b/patches/simple-form.patch new file mode 100644 index 0000000..87bb010 --- /dev/null +++ b/patches/simple-form.patch @@ -0,0 +1,39 @@ +diff --git a/config/locales/simple_form.en.yml b/config/locales/simple_form.en.yml +index 6edf7b4e9..fe196a387 100644 +--- a/config/locales/simple_form.en.yml ++++ b/config/locales/simple_form.en.yml +@@ -99,7 +99,7 @@ en: + imports: + data: CSV file exported from another Mastodon server + invite_request: +- text: This will help us review your application ++ text: This will help us review your application. Make sure you read the rules before writing anything here + ip_block: + comment: Optional. Remember why you added this rule. + expires_in: IP addresses are a finite resource, they are sometimes shared and often change hands. For this reason, indefinite IP blocks are not recommended. +diff --git a/config/locales/simple_form.fr.yml b/config/locales/simple_form.fr.yml +index 3b2d30aae..fdc802eab 100644 +--- a/config/locales/simple_form.fr.yml ++++ b/config/locales/simple_form.fr.yml +@@ -99,7 +99,7 @@ fr: + imports: + data: Un fichier CSV généré par un autre serveur de Mastodon + invite_request: +- text: Cela nous aidera à considérer votre demande ++ text: Cela nous aidera à considérer votre demande. Assurez-vous de lire les règles avant d'écrire quoi que ce soit ici + ip_block: + comment: Optionnel. Pour ne pas oublier pourquoi vous avez ajouté cette règle. + expires_in: Les adresses IP sont une ressource finie, elles sont parfois partagées et changent souvent de mains. Pour cette raison, les blocages d’IP indéfiniment ne sont pas recommandés. +diff --git a/config/locales/simple_form.ru.yml b/config/locales/simple_form.ru.yml +index e95b22377..7854d633a 100644 +--- a/config/locales/simple_form.ru.yml ++++ b/config/locales/simple_form.ru.yml +@@ -82,7 +82,7 @@ ru: + imports: + data: Файл CSV, экспортированный с другого узла Mastodon. + invite_request: +- text: Это поможет нам рассмотреть вашу заявку ++ text: Это поможет нам рассмотреть вашу заявку. Перед тем, как писать что-либо здесь, обязательно прочтите правила + ip_block: + comment: Необязательно. Заметка на будущее, почему вы добавили это правило. + expires_in: IP адреса — весьма ограниченный ресурс, иногда они разделяются между абонентами и часто меняют владельца. По этой причине блокировки на неопределённые сроки не рекомендуются. diff --git a/patches/themes-config.patch b/patches/themes-config.patch new file mode 100644 index 0000000..163cf81 --- /dev/null +++ b/patches/themes-config.patch @@ -0,0 +1,11 @@ +diff --git a/config/themes.yml b/config/themes.yml +index 9c21c9459..49da04fde 100644 +--- a/config/themes.yml ++++ b/config/themes.yml +@@ -1,3 +1,6 @@ + default: styles/application.scss + contrast: styles/contrast.scss + mastodon-light: styles/mastodon-light.scss ++tango: styles/tango.scss ++black: styles/black.scss ++merveilles: styles/merveilles.scss diff --git a/secrets.nix.example b/secrets.nix.example new file mode 100644 index 0000000..8387b22 --- /dev/null +++ b/secrets.nix.example @@ -0,0 +1,36 @@ +{ + pubkeys = [ + "" + ]; + + smtpPassword = ""; + + vapidPublicKey = ""; + secretKeyBase = ""; + otpSecret = ""; + vapidPrivateKey = ""; + + AWS_ACCESS_KEY_ID = ""; + AWS_SECRET_ACCESS_KEY = ""; + + DEEPL_API_KEY = ""; + + letsencryptEmail = ""; + + ipv4 = { + addresses = [ + { address = ""; prefixLength = 26; } + ]; + routes = [ + { address = "0.0.0.0"; prefixLength = 0; via = ""; } + ]; + }; + ipv6 = { + addresses = [ + { address = ""; prefixLength = 64; } + ]; + routes = [ + { address = "::"; prefixLength = 0; via = "fe80::1"; } + ]; + }; +}