nixfiles/hosts/koi/containers/puffer.nix

211 lines
5.4 KiB
Nix
Raw Normal View History

2024-01-09 08:34:03 +03:00
{ abs, lib, config, pkgs, ... }@inputs:
2024-01-08 07:49:51 +03:00
let
2024-01-09 08:34:03 +03:00
containers = import (abs "lib/containers.nix") inputs;
avahi = import (abs "lib/avahi.nix") inputs;
systemd = import (abs "lib/systemd.nix") inputs;
sftpgo = import (abs "services/sftpgo.nix") inputs;
secrets = import (abs "lib/secrets.nix");
sftpKey = secrets.mount config "sftpgo-ed25519";
sambaConfig = {
imports = [
(systemd.mkOneshot {
name = "smb-guest-setup";
# for whatever reason smbd refuses to write unless we set the password
script = "${pkgs.samba}/bin/smbpasswd -a smb-guest -n";
})
];
2024-01-08 07:49:51 +03:00
services.samba = {
enable = true;
openFirewall = true;
securityType = "user";
extraConfig = ''
workgroup = WORKGROUP
server string = puffer
netbios name = puffer
security = user
hosts allow = 10.0.0.0/8
hosts deny = 0.0.0.0/0
guest account = smb-guest
map to guest = bad user
inherit permissions = yes
# Performance
socket options = TCP_NODELAY IPTOS_LOWDELAY SO_RCVBUF=131072 SO_SNDBUF=131072
read raw = yes
write raw = yes
server signing = no
strict locking = no
min receivefile size = 16384
use sendfile = Yes
aio read size = 16384
aio write size = 16384
# Fruit global config
fruit:aapl = yes
fruit:nfs_aces = no
fruit:copyfile = no
fruit:model = MacSamba
'';
shares =
let
publicShare = {
browseable = "yes";
"read only" = "no";
"guest ok" = "yes";
"create mask" = "2775";
"directory mask" = "2775";
"force user" = "smb-guest";
"force group" = "puffer";
};
in
{
Downloads = {
path = "/mnt/puffer/Downloads";
browseable = "yes";
"read only" = "yes";
"guest ok" = "yes";
};
Public = publicShare // {
path = "/mnt/puffer/Public";
};
# its ok for this to be local-public, since Time Machine
# backups are to be encrypted anyway
# (and also im too lazy to set up users here)
Backups = publicShare // {
path = "/mnt/puffer/Backups";
# whatever this means
"vfs objects" = "catia fruit streams_xattr";
"fruit:time machine" = "yes";
"fruit:time machine max size" = "100G";
};
};
};
2024-01-09 08:34:03 +03:00
};
2024-01-08 07:49:51 +03:00
2024-01-09 08:34:03 +03:00
avahiConfig = avahi.setup {
name = "puffer";
services = [
{ type = "_smb._tcp"; port = 445; }
# cancer stuff for macs to see this disk as a time machine-compatible disk
[
{ type = "_adisk._tcp"; port = 9; }
{ txt-record = "sys=waMa=0,adVF=0x100"; }
{ txt-record = "dk0=adVN=Puffer TimeMachine,adVF=0x82"; }
]
{ type = "_device-info._tcp"; port = 0; txt-record = "model=TimeCapsule8,119"; }
2024-01-08 07:49:51 +03:00
];
2024-01-09 08:34:03 +03:00
};
2024-01-08 07:49:51 +03:00
2024-01-09 08:34:03 +03:00
sftpgoConfig = sftpgo.setup {
package = pkgs.callPackage (abs "packages/sftpgo.nix") {
tags = [ "nogcs" "nos3" "noazblob" "nobolt" "nomysql" "nopgsql" "nometrics" "bundle" ];
2024-01-08 07:49:51 +03:00
};
2024-01-09 08:34:03 +03:00
config = {
sftpd = {
bindings = [
{ port = 22; }
];
host_keys = [ "id_ed25519" ];
};
};
keys.ed25519 = sftpKey.path;
users.guest = {
2024-01-09 10:06:17 +03:00
# bcrypt-hashed 0
2024-01-09 08:34:03 +03:00
password = "$2a$10$IcGdNtx10ycmPRD6lA4c0uNfRXTEchFRzCZEDkngTjzForn6pd0Wa";
};
2024-01-08 07:49:51 +03:00
2024-01-09 08:34:03 +03:00
folders.Public.path = "/mnt/puffer/Public";
2024-08-03 07:09:55 +03:00
folders.Downloads.path = "/mnt/puffer/Downloads";
2024-01-09 08:34:03 +03:00
usersFolders = [
{ username = "guest"; folder = "Public"; }
2024-08-03 07:09:55 +03:00
{ username = "guest"; folder = "Downloads"; }
2024-01-09 08:34:03 +03:00
];
2024-01-08 07:49:51 +03:00
};
2024-01-09 08:34:03 +03:00
container = containers.mkNixosContainer {
name = "puffer";
ip = "10.42.0.5";
private = false;
config = { ... }: {
imports = [
sambaConfig
avahiConfig
sftpgoConfig
];
2024-03-17 05:59:15 +03:00
environment.systemPackages = with pkgs; [
uxplay
];
2024-01-09 08:34:03 +03:00
users.groups.puffer = { };
users.users.smb-guest = {
isNormalUser = true;
description = "Guest account for Samba";
extraGroups = [ "puffer" ];
createHome = false;
shell = pkgs.shadow;
};
systemd.tmpfiles.rules = [
"d /mnt/puffer/Public 0755 smb-guest puffer - -"
"d /mnt/puffer/Backups 0755 smb-guest puffer - -"
];
2024-03-17 05:59:15 +03:00
networking.firewall.allowedTCPPorts = [ 22 7000 7001 7002 ];
networking.firewall.allowedUDPPorts = [ 22 7000 7001 7002 ];
2024-01-08 07:49:51 +03:00
};
2024-01-09 08:34:03 +03:00
mounts = {
"/mnt/puffer" = {
hostPath = "/mnt/puffer";
isReadOnly = false;
};
} // (sftpKey.mounts);
2024-01-08 07:49:51 +03:00
};
2024-01-09 08:34:03 +03:00
in
{
imports = [
(secrets.declare [ "sftpgo-ed25519" ])
container
];
2024-08-29 16:04:06 +03:00
services.nginx.virtualHosts."puffer.stupid.fish" = {
forceSSL = true;
useACMEHost = "stupid.fish";
locations."/public/" = {
extraConfig = ''
alias /mnt/puffer/Public/;
autoindex on;
'';
};
locations."/downloads/" = {
extraConfig = ''
alias /mnt/puffer/Downloads/;
autoindex on;
'';
};
locations."= /" = {
extraConfig = ''
add_header 'Content-Type' 'text/html; charset=utf-8';
return 200 '<html><body><h1>🐡 puffer</h1><a href="/public/">public</a><br><a href="/downloads/">downloads</a></body></html>';
'';
};
};
2024-01-08 07:49:51 +03:00
}