add rustypaste module
This commit is contained in:
parent
1a6d282046
commit
eb3d5353a2
8 changed files with 301 additions and 2 deletions
|
|
@ -20,6 +20,10 @@
|
|||
};
|
||||
users.deploy.enable = true;
|
||||
programs = {
|
||||
rustypaste = {
|
||||
enable = true;
|
||||
url = "https://paste.youthlic.fun";
|
||||
};
|
||||
openssh.enable = true;
|
||||
tailscale.enable = true;
|
||||
conduwuit = {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
{ config, lib, ... }:
|
||||
{
|
||||
imports = [
|
||||
./rustypaste
|
||||
./mautrix-telegram.nix
|
||||
./caddy.nix
|
||||
./dae
|
||||
|
|
|
|||
147
nixos/modules/programs/rustypaste/default.nix
Normal file
147
nixos/modules/programs/rustypaste/default.nix
Normal file
|
|
@ -0,0 +1,147 @@
|
|||
{ lib, config, ... }:
|
||||
let
|
||||
cfg = config.youthlic.programs.rustypaste;
|
||||
in
|
||||
{
|
||||
imports = [
|
||||
./template.nix
|
||||
];
|
||||
|
||||
options = {
|
||||
youthlic.programs.rustypaste = {
|
||||
enable = lib.mkEnableOption "rustypaste";
|
||||
listen = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
example = "0.0.0.0";
|
||||
default = "127.0.0.1";
|
||||
};
|
||||
url = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.nonEmptyStr;
|
||||
example = "https://paste.example.com";
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
};
|
||||
config = lib.mkMerge [
|
||||
(lib.mkIf cfg.enable {
|
||||
sops.secrets = {
|
||||
"rustypaste/auth" = {
|
||||
group = "rustypaste";
|
||||
mode = "0440";
|
||||
};
|
||||
"rustypaste/delete" = {
|
||||
group = "rustypaste";
|
||||
mode = "0440";
|
||||
};
|
||||
};
|
||||
services.rustypaste = {
|
||||
enable = true;
|
||||
port = 8483;
|
||||
group = "rustypaste";
|
||||
settings = {
|
||||
config = {
|
||||
refresh_rate = "1s";
|
||||
};
|
||||
server = {
|
||||
address = "${cfg.listen}:8483";
|
||||
url = lib.mkIf (cfg.url != null) cfg.url;
|
||||
upload_path = "/var/lib/rustypaste/";
|
||||
max_content_length = "10GB";
|
||||
timeout = "30s";
|
||||
expose_version = true;
|
||||
expose_list = true;
|
||||
handle_spaces = "encode";
|
||||
};
|
||||
paste = {
|
||||
duplicate_files = true;
|
||||
default_expiry = "3h";
|
||||
delete_expired_files = {
|
||||
enabled = true;
|
||||
interval = "3h";
|
||||
};
|
||||
random_url = {
|
||||
type = "petname";
|
||||
words = 2;
|
||||
separator = "-";
|
||||
};
|
||||
default_extension = "txt";
|
||||
main_blacklist = [
|
||||
"application/x-dosexec"
|
||||
"application/java-archive"
|
||||
"application/java-vm"
|
||||
];
|
||||
mine_override = [
|
||||
{
|
||||
mime = "image/jpeg";
|
||||
regex = "^.*\\.jpg$";
|
||||
}
|
||||
{
|
||||
mime = "image/png";
|
||||
regex = "^.*\\.png$";
|
||||
}
|
||||
{
|
||||
mime = "image/svg+xml";
|
||||
regex = "^.*\\.svg$";
|
||||
}
|
||||
{
|
||||
mime = "video/webm";
|
||||
regex = "^.*\\.webm$";
|
||||
}
|
||||
{
|
||||
mime = "video/x-matroska";
|
||||
regex = "^.*\\.mkv$";
|
||||
}
|
||||
{
|
||||
mime = "application/octet-stream";
|
||||
regex = "^.*\\.bin$";
|
||||
}
|
||||
{
|
||||
mime = "text/plain";
|
||||
regex = "^.*\\.(log|txt|diff|sh|rs|toml|py|json|yaml|yml|ts|js|go|c|C|c++|cpp|cxx)$";
|
||||
}
|
||||
];
|
||||
};
|
||||
landing_page = {
|
||||
content_type = "text/plain; charset=utf-8";
|
||||
text = ''
|
||||
┬─┐┬ ┬┌─┐┌┬┐┬ ┬┌─┐┌─┐┌─┐┌┬┐┌─┐
|
||||
├┬┘│ │└─┐ │ └┬┘├─┘├─┤└─┐ │ ├┤
|
||||
┴└─└─┘└─┘ ┴ ┴ ┴ ┴ ┴└─┘ ┴ └─┘
|
||||
|
||||
Submit files via HTTP POST here:
|
||||
curl -F 'file=@example.txt' <server>
|
||||
This will return the URL of the uploaded file.
|
||||
|
||||
The server administrator might remove any pastes that they do not personally
|
||||
want to host.
|
||||
|
||||
If you are the server administrator and want to change this page, just go
|
||||
into your config file and change it! If you change the expiry time, it is
|
||||
recommended that you do.
|
||||
|
||||
By default, pastes expire every hour. The server admin may or may not have
|
||||
changed this.
|
||||
|
||||
Check out the GitHub repository at https://github.com/orhun/rustypaste
|
||||
Command line tool is available at https://github.com/orhun/rustypaste-cli
|
||||
'';
|
||||
};
|
||||
};
|
||||
env = {
|
||||
AUTH_TOKENS_FILE = "${config.sops.secrets."rustypaste/auth".path}";
|
||||
DELETE_TOKENS_FILE = "${config.sops.secrets."rustypaste/delete".path}";
|
||||
};
|
||||
openFirewall = true;
|
||||
};
|
||||
})
|
||||
(lib.mkIf (cfg.enable && config.youthlic.programs.caddy.enable) {
|
||||
services.caddy.virtualHosts = {
|
||||
"paste.${config.youthlic.programs.caddy.baseDomain}" = {
|
||||
extraConfig = ''
|
||||
reverse_proxy 127.0.0.1:8483
|
||||
'';
|
||||
};
|
||||
};
|
||||
})
|
||||
];
|
||||
}
|
||||
102
nixos/modules/programs/rustypaste/template.nix
Normal file
102
nixos/modules/programs/rustypaste/template.nix
Normal file
|
|
@ -0,0 +1,102 @@
|
|||
{
|
||||
pkgs,
|
||||
lib,
|
||||
config,
|
||||
...
|
||||
}:
|
||||
let
|
||||
cfg = config.services.rustypaste;
|
||||
settingsFormat = pkgs.formats.toml { };
|
||||
configFile = settingsFormat.generate "rustypaste-config.toml" cfg.settings;
|
||||
in
|
||||
{
|
||||
options = {
|
||||
services.rustypaste = {
|
||||
enable = lib.mkEnableOption "rustypaste";
|
||||
package = lib.mkPackageOption pkgs "rustypaste" { };
|
||||
settings = lib.mkOption {
|
||||
type = settingsFormat.type;
|
||||
default = { };
|
||||
description = ''
|
||||
Rustypaste configuration
|
||||
'';
|
||||
};
|
||||
port = lib.mkOption {
|
||||
type = lib.types.port;
|
||||
default = 8000;
|
||||
example = 32456;
|
||||
};
|
||||
group = lib.mkOption {
|
||||
type = lib.types.nonEmptyStr;
|
||||
example = "rustypaste";
|
||||
default = "rustypaste";
|
||||
};
|
||||
env = {
|
||||
AUTH_TOKENS_FILE = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
};
|
||||
DELETE_TOKENS_FILE = lib.mkOption {
|
||||
type = lib.types.nullOr lib.types.path;
|
||||
default = null;
|
||||
};
|
||||
};
|
||||
openFirewall = lib.mkEnableOption "open port for rustypaste";
|
||||
};
|
||||
};
|
||||
config = lib.mkIf cfg.enable {
|
||||
environment.systemPackages = [
|
||||
cfg.package
|
||||
];
|
||||
networking.firewall = lib.mkIf cfg.openFirewall {
|
||||
allowedTCPPorts = [
|
||||
cfg.port
|
||||
];
|
||||
allowedUDPPorts = [
|
||||
cfg.port
|
||||
];
|
||||
};
|
||||
users = {
|
||||
users.rustypaste = {
|
||||
group = cfg.group;
|
||||
home = "/var/lib/rustypaste";
|
||||
isSystemUser = true;
|
||||
};
|
||||
groups = lib.optionalAttrs (cfg.group == "rustypaste") {
|
||||
rustypaste = { };
|
||||
};
|
||||
};
|
||||
systemd.services.rustypaste = {
|
||||
description = ''
|
||||
rustypaste Service
|
||||
'';
|
||||
documentation = [
|
||||
"https://github.com/orhun/rustypaste"
|
||||
];
|
||||
after = [
|
||||
"network.target"
|
||||
];
|
||||
wantedBy = [
|
||||
"multi-user.target"
|
||||
];
|
||||
environment = {
|
||||
CONFIG = "${configFile}";
|
||||
AUTH_TOKENS_FILE = lib.mkIf (cfg.env.AUTH_TOKENS_FILE != null) cfg.env.AUTH_TOKENS_FILE;
|
||||
DELETE_TOKENS_FILE = lib.mkIf (cfg.env.DELETE_TOKENS_FILE != null) cfg.env.DELETE_TOKENS_FILE;
|
||||
};
|
||||
serviceConfig = {
|
||||
Type = "simple";
|
||||
Restart = "on-failure";
|
||||
Home = "/var/lib/rustypaste";
|
||||
ReadWritePaths = [ "/var/lib/rustypaste" ];
|
||||
StateDirectory = [ "rustypaste" ];
|
||||
ExecStart = ''
|
||||
${lib.getExe cfg.package}
|
||||
'';
|
||||
Group = cfg.group;
|
||||
User = "rustypaste";
|
||||
RestartPreventExitStatus = 1;
|
||||
};
|
||||
};
|
||||
};
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue