Skip to content

Commit

Permalink
Added coffeepaste package, options, and to fermi configuration
Browse files Browse the repository at this point in the history
  • Loading branch information
aftix committed May 18, 2024
1 parent 8c803e9 commit 1c5f5b1
Show file tree
Hide file tree
Showing 8 changed files with 226 additions and 6 deletions.
17 changes: 17 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

5 changes: 5 additions & 0 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,11 @@
url = "github:Alexays/Waybar";
inputs.nixpkgs.follows = "nixpkgs";
};

coffeepaste = {
url = "sourcehut:~mort/coffeepaste";
flake = false;
};
};

outputs = {
Expand Down
138 changes: 138 additions & 0 deletions host/common/coffeepaste.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,138 @@
{
config,
lib,
pkgs,
inputs,
...
}: let
inherit (lib) mkDefault;
inherit (lib.options) mkOption mkEnableOption;
cfg = config.services.coffeepaste;

configFile = (pkgs.formats.toml {}).generate "config.toml" {
inherit (cfg) url max_file_size expiration_days;
listen = "${cfg.listenAddr}:${builtins.toString cfg.listenPort}";
data = "${cfg.dataDir}/data";
};
in {
options.services.coffeepaste = {
enable = mkEnableOption "coffeepaste";

user = mkOption {
default = "coffeepaste";
type = lib.types.str;
};

group = mkOption {
default = "coffeepaste";
type = lib.types.str;
};

url = mkOption {
default = "https://example.com";
type = lib.types.str;
};

listenAddr = mkOption {
default = "[::1]";
type = lib.types.str;
};
listenPort = mkOption {
default = 8080;
type = lib.types.ints.unsigned;
};

dataDir = mkOption {
default = "/var/lib/coffeepaste";
type = lib.types.path;
};

max_file_size = mkOption {
default = 15000000;
type = lib.types.ints.unsigned;
};

expiration_days = mkOption {
default = 30;
type = lib.types.ints.unsigned;
};
};

config = lib.mkIf cfg.enable {
nixpkgs.overlays = [
(final: _: {
coffeepaste = final.rustPlatform.buildRustPackage rec {
pname = "coffeepaste";
version = "1.5.1";

src = inputs.coffeepaste;
cargoLock.lockFile = "${src}/Cargo.lock";

nativeBuildInputs = with pkgs; [
pkg-config
];
buildInputs = with pkgs; [
glib
gexiv2
];

postInstall = ''
mkdir -p "$out/share"
cp ${configFile} "$out/share/config.toml"
'';

meta = with pkgs.lib; {
description = "A neat pastebin";
homepage = "https://git.sr.ht/~mort/coffeepaste";
license = licenses.agpl3Only;
maintainers = [
{
name = "aftix";
email = "[email protected]";
github = "aftix";
}
];
};
};
})
];

users = {
users.${cfg.user} = {
isSystemUser = mkDefault true;
group = mkDefault cfg.group;
shell = mkDefault "/run/current-system/sw/bin/nologin";
};
groups.${cfg.group} = {};
};

systemd = {
tmpfiles.rules = [
"d ${cfg.dataDir} 0750 ${cfg.user} ${cfg.group} -"
"d ${cfg.dataDir}/data 0750 ${cfg.user} ${cfg.group} -"
];

services.coffeepaste = {
wants = ["network.target"];
after = ["network.target"];
wantedBy = ["multi-user.target"];
unitConfig.Description = "A neat pastebin";

serviceConfig = {
User = cfg.user;
Group = cfg.group;
WorkingDirectory = cfg.dataDir;
ProtectSystem = "strict";
PrivateTmp = true;
PrivateDevices = true;
ProtectHome = "read-only";
NoNewPrivileges = true;
ReadWritePaths = cfg.dataDir;
MemoryDenyWriteExecute = true;
};
script = "${pkgs.coffeepaste}/bin/coffeepaste";
preStart = "cp ${pkgs.coffeepaste}/share/config.toml ${cfg.dataDir}/config.toml";
};
};
};
}
1 change: 1 addition & 0 deletions host/common/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ in {
imports = [
./apparmor.nix
./channels.nix
./coffeepaste.nix
./nh.nix
./root.nix
./sleep.nix
Expand Down
1 change: 1 addition & 0 deletions host/fermi.nix
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ in {

services = {
openssh.settings.AllowUsers = ["aftix"];
coffeepaste.enable = true;
};

users = {
Expand Down
61 changes: 61 additions & 0 deletions host/opt/www/coffeepaste.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
{
lib,
config,
...
}: let
inherit (lib) mkIf mkDefault;
cfg = config.my.www;
in {
options.my.www.coffeepasteSubdomain = lib.options.mkOption {
default = "file";
type = lib.types.str;
};

config = mkIf config.services.coffeepaste.enable {
security.acme.certs.${cfg.hostname}.extraDomainNames = [
"${cfg.coffeepasteSubdomain}.${cfg.hostname}"
"www.${cfg.coffeepasteSubdomain}.${cfg.hostname}"
];

services = {
coffeepaste = {
user = mkDefault cfg.user;
group = mkDefault cfg.group;
url = mkDefault "https://${cfg.coffeepasteSubdomain}.${cfg.hostname}";
};

nginx.virtualHosts."${cfg.coffeepasteSubdomain}.${cfg.hostname}" = {
serverName = "${cfg.coffeepasteSubdomain}.${cfg.hostname} www.${cfg.coffeepasteSubdomain}.${cfg.hostname}";
kTLS = true;
forceSSL = true;
useACMEHost = cfg.hostname;

extraConfig = ''
error_page 599 = @putrequest;
if ($request_method = 'PUT') {
return 599;
}
'';

locations = {
"/" = {
proxyPass = "http://localhost:${builtins.toString config.services.coffeepaste.listenPort}";
extraConfig = ''
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
};

"@putrequest" = {
proxyPass = "http://localhost:${builtins.toString config.services.coffeepaste.listenPort}";
extraConfig = ''
limit_req zone=put_request_by_addr burst=10;
proxy_set_header X-Real-IP $remote_addr;
proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
'';
};
};
};
};
};
}
7 changes: 2 additions & 5 deletions host/opt/www/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
in {
imports = [
./blog.nix
./coffeepaste.nix
./searx.nix
./znc.nix
];
Expand Down Expand Up @@ -115,11 +116,7 @@ in {

certs.${cfg.hostname} = {
inherit (cfg) group;
extraDomainNames = [
"www.${cfg.hostname}"
"auth.${cfg.hostname}"
"www.auth.${cfg.hostname}"
];
extraDomainNames = ["www.${cfg.hostname}"];
};
};
};
Expand Down
2 changes: 1 addition & 1 deletion host/opt/www/searx.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ in {
systemd.tmpfiles.rules = let
inherit (config.services.searx.uwsgiConfig) immediate-uid immediate-gid;
in [
"d ${builtins.baseNameOf socket} 0775 ${immediate-uid} ${immediate-gid} -"
"d ${builtins.dirOf socket} 0775 ${immediate-uid} ${immediate-gid} -"
];

environment.etc."nginx/uwsgi_params".text = ''
Expand Down

0 comments on commit 1c5f5b1

Please sign in to comment.