2023-06-03 17:31:46 +00:00
|
|
|
{ pkgs, lib, config, modulesPath, ... }:
|
|
|
|
{
|
|
|
|
imports = [
|
|
|
|
"${modulesPath}/profiles/minimal.nix"
|
|
|
|
"${modulesPath}/profiles/qemu-guest.nix"
|
|
|
|
"${modulesPath}/virtualisation/qemu-vm.nix"
|
|
|
|
];
|
|
|
|
|
2023-06-18 18:32:14 +00:00
|
|
|
config =
|
|
|
|
let
|
|
|
|
penv = pkgs.python3.buildEnv.override {
|
|
|
|
extraLibs = [
|
|
|
|
pkgs.python3.pkgs.frappe
|
|
|
|
pkgs.python3.pkgs.erpnext
|
|
|
|
pkgs.python3.pkgs.bench
|
|
|
|
];
|
|
|
|
};
|
|
|
|
appsFile = pkgs.writeText "erpnext-apps.txt" ''
|
|
|
|
frappe
|
|
|
|
erpnext
|
|
|
|
'';
|
|
|
|
# In a module, this could be provided by a use as a file as it could
|
|
|
|
# contain secrets and we don't want this in the nix-store. But here it
|
|
|
|
# is OK.
|
|
|
|
commonSiteConfig = pkgs.writeText "erpnext-common_site_config.json" ''
|
|
|
|
{
|
|
|
|
"db_host": "localhost",
|
|
|
|
"db_port": 3306,
|
|
|
|
"db_name": "erpnext" ,
|
|
|
|
"db_password": "erpnext" ,
|
|
|
|
"redis_cache": "redis://localhost:6379",
|
|
|
|
"redis_queue": "redis://localhost:6379",
|
|
|
|
"redis_socketio": "redis://localhost:12311",
|
|
|
|
"socketio_port": 3000
|
|
|
|
}
|
|
|
|
'';
|
|
|
|
defaultServiceConfig = {
|
|
|
|
User = "erpnext";
|
|
|
|
NoNewPrivileges = true;
|
|
|
|
Type = "simple";
|
|
|
|
BindReadOnlyPaths = [
|
|
|
|
"/etc/hosts:/etc/hosts"
|
|
|
|
"${pkgs.frappe-app}:${pkgs.frappe-app}"
|
|
|
|
"${pkgs.frappe-app}/share/apps/frappe:/var/lib/erpnext/bench/apps/frappe"
|
|
|
|
"${pkgs.erpnext-app}:${pkgs.erpnext-app}"
|
|
|
|
"${pkgs.erpnext-app}/share/apps/erpnext:/var/lib/erpnext/bench/apps/erpnext"
|
|
|
|
"${pkgs.frappe-erpnext-assets}/share/sites/assets:/var/lib/erpnext/bench/sites/assets"
|
|
|
|
"${appsFile}:/var/lib/erpnext/bench/sites/apps.txt"
|
|
|
|
"${commonSiteConfig}:/var/lib/erpnext/bench/sites/common_site_config.json"
|
|
|
|
"${penv}:/var/lib/erpnext/bench/env"
|
|
|
|
];
|
|
|
|
BindPaths = [
|
|
|
|
"/var/lib/erpnext:/var/lib/erpnext"
|
|
|
|
];
|
|
|
|
WorkingDirectory = "/var/lib/erpnext/bench";
|
|
|
|
};
|
|
|
|
in
|
|
|
|
{
|
2023-06-03 17:31:46 +00:00
|
|
|
services.qemuGuest.enable = true;
|
2023-06-05 17:28:33 +00:00
|
|
|
system.stateVersion = "23.05";
|
2023-06-03 17:31:46 +00:00
|
|
|
|
|
|
|
fileSystems."/" = {
|
|
|
|
device = "/dev/disk/by-label/nixos";
|
|
|
|
fsType = "ext4";
|
|
|
|
autoResize = true;
|
|
|
|
};
|
|
|
|
|
|
|
|
boot = {
|
|
|
|
growPartition = true;
|
|
|
|
loader.timeout = 5;
|
|
|
|
};
|
|
|
|
|
|
|
|
virtualisation = {
|
|
|
|
diskSize = 8000; # MB
|
|
|
|
memorySize = 2048; # MB
|
|
|
|
|
|
|
|
# We don't want to use tmpfs, otherwise the nix store's size will be bounded
|
|
|
|
# by a fraction of available RAM.
|
|
|
|
writableStoreUseTmpfs = false;
|
2023-06-05 17:28:33 +00:00
|
|
|
|
|
|
|
forwardPorts = [{
|
|
|
|
guest.port = 22;
|
|
|
|
host.port = 2222;
|
|
|
|
} {
|
|
|
|
guest.port = 9090;
|
|
|
|
host.port = 9090;
|
2023-06-06 04:19:10 +00:00
|
|
|
} {
|
|
|
|
guest.port = 8081;
|
|
|
|
host.port = 8081;
|
2023-06-05 17:28:33 +00:00
|
|
|
}];
|
2023-06-03 17:31:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
# So that we can ssh into the VM, see e.g.
|
|
|
|
# http://blog.patapon.info/nixos-local-vm/#accessing-the-vm-with-ssh
|
|
|
|
services.openssh.enable = true;
|
|
|
|
services.openssh.settings.PermitRootLogin = "yes";
|
|
|
|
# Give root an empty password to ssh in.
|
|
|
|
users.extraUsers.root.password = "";
|
2023-06-05 17:28:33 +00:00
|
|
|
users.users.root.openssh.authorizedKeys.keys = [
|
|
|
|
"ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIMNeQYLFauAbzDyIbKC86NUh9yZfiyBm/BtIdkcpZnSU"
|
|
|
|
];
|
2023-06-03 17:31:46 +00:00
|
|
|
users.mutableUsers = false;
|
2023-06-05 17:28:33 +00:00
|
|
|
networking.firewall.enable = false;
|
2023-06-03 17:31:46 +00:00
|
|
|
|
|
|
|
environment.systemPackages = with pkgs; [
|
|
|
|
git
|
|
|
|
htop
|
|
|
|
neovim
|
|
|
|
];
|
|
|
|
|
|
|
|
services.mysql = {
|
|
|
|
enable = true;
|
|
|
|
package = pkgs.mariadb;
|
2023-06-05 17:28:33 +00:00
|
|
|
ensureUsers = [{
|
|
|
|
name = "root";
|
|
|
|
ensurePermissions = {
|
|
|
|
"*.*" = "ALL PRIVILEGES";
|
|
|
|
};
|
|
|
|
}];
|
|
|
|
ensureDatabases = [ "root" ];
|
2023-06-03 17:31:46 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
services.redis.servers = {
|
|
|
|
# Queue, naming it "" makes it use default values.
|
|
|
|
"".enable = true;
|
|
|
|
|
|
|
|
socketio = {
|
|
|
|
enable = true;
|
|
|
|
port = 12311;
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
users.users.erpnext = {
|
|
|
|
description = "User to run erpnext";
|
|
|
|
group = "erpnext";
|
|
|
|
isSystemUser = true;
|
2023-06-05 17:28:33 +00:00
|
|
|
home = "/var/lib/erpnext";
|
|
|
|
createHome = true;
|
2023-06-03 17:31:46 +00:00
|
|
|
};
|
2023-06-18 18:32:14 +00:00
|
|
|
users.groups.erpnext = {};
|
2023-06-03 17:31:46 +00:00
|
|
|
|
2023-06-18 18:32:14 +00:00
|
|
|
systemd.services.erpnext-setup-mysql = {
|
2023-06-05 17:28:33 +00:00
|
|
|
enable = true;
|
2023-06-18 18:32:14 +00:00
|
|
|
before = [ "erpnext-web.service" ];
|
2023-06-05 17:28:33 +00:00
|
|
|
after = [ "mysql.service" ];
|
2023-06-18 18:32:14 +00:00
|
|
|
wantedBy = [ "erpnext-web.service" ];
|
|
|
|
partOf = [ "erpnext-web.service" ];
|
2023-06-05 17:28:33 +00:00
|
|
|
script = ''
|
|
|
|
${pkgs.mariadb-client}/bin/mysql -e "SET PASSWORD FOR 'root'@'localhost' = PASSWORD('password')";
|
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
RemainAfterExit = true;
|
|
|
|
Type = "oneshot";
|
2023-06-05 17:19:43 +00:00
|
|
|
};
|
2023-06-05 17:28:33 +00:00
|
|
|
};
|
|
|
|
|
2023-06-18 18:32:14 +00:00
|
|
|
systemd.services.erpnext-ensure-bench-dir = {
|
2023-06-05 17:19:43 +00:00
|
|
|
enable = true;
|
2023-06-18 18:32:14 +00:00
|
|
|
before = [ "erpnext-web.service" ];
|
|
|
|
wantedBy = [ "erpnext-web.service" ];
|
|
|
|
partOf = [ "erpnext-web.service" ];
|
2023-06-05 17:28:33 +00:00
|
|
|
script = ''
|
2023-06-07 19:58:05 +00:00
|
|
|
for subdir in apps sites config/pids logs; do
|
|
|
|
mkdir -p /var/lib/erpnext/bench/$subdir
|
|
|
|
done
|
2023-06-05 17:28:33 +00:00
|
|
|
'';
|
|
|
|
serviceConfig = {
|
|
|
|
RemainAfterExit = true;
|
|
|
|
Type = "oneshot";
|
|
|
|
User = "erpnext";
|
|
|
|
};
|
|
|
|
};
|
2023-06-05 17:19:43 +00:00
|
|
|
|
2023-06-18 18:32:14 +00:00
|
|
|
systemd.services.erpnext-nodejs-socketio = {
|
2023-06-06 04:19:10 +00:00
|
|
|
enable = true;
|
2023-06-18 18:32:14 +00:00
|
|
|
before = [ "erpnext-web.service" ];
|
|
|
|
wantedBy = [ "erpnext-web.service" ];
|
|
|
|
partOf = [ "erpnext-web.service" ];
|
|
|
|
description = "ERPNext Node.js HTTP server for socket.io ";
|
|
|
|
confinement = {
|
|
|
|
enable = true;
|
|
|
|
packages = [ pkgs.nodejs ];
|
|
|
|
};
|
|
|
|
serviceConfig = defaultServiceConfig // {
|
|
|
|
ExecStart = ''
|
|
|
|
${pkgs.nodejs}/bin/node /var/lib/erpnext/bench/apps/frappe/socketio.js
|
|
|
|
'';
|
|
|
|
};
|
2023-06-06 04:19:10 +00:00
|
|
|
};
|
|
|
|
|
2023-06-18 18:32:14 +00:00
|
|
|
services.caddy = {
|
|
|
|
enable = true;
|
|
|
|
email = "admins@pub.solar";
|
|
|
|
globalConfig = ''
|
|
|
|
local_certs
|
|
|
|
'';
|
|
|
|
virtualHosts = {
|
|
|
|
"localhost:8081" = {
|
|
|
|
extraConfig = ''
|
|
|
|
handle /assets/* {
|
|
|
|
root * ${pkgs.frappe-erpnext-assets}/share/sites
|
|
|
|
file_server
|
|
|
|
}
|
|
|
|
handle /socket.io/* {
|
|
|
|
reverse_proxy :3000
|
|
|
|
}
|
2023-06-05 17:19:43 +00:00
|
|
|
|
2023-06-18 18:32:14 +00:00
|
|
|
reverse_proxy :9090
|
2023-06-05 17:28:33 +00:00
|
|
|
'';
|
|
|
|
};
|
2023-06-18 18:32:14 +00:00
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
systemd.services.erpnext-web = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "mysql.service" "redis.service" "redis-socketio.service" ];
|
|
|
|
description = "ERPNext web server";
|
|
|
|
confinement = {
|
|
|
|
enable = true;
|
|
|
|
packages = [ pkgs.mariadb-client penv ];
|
|
|
|
};
|
|
|
|
serviceConfig = defaultServiceConfig // {
|
|
|
|
TimeoutStartSec = "300s";
|
|
|
|
ExecStartPre = pkgs.writeScript "erpnext-server.worker-init" ''
|
|
|
|
#!/bin/sh
|
|
|
|
export PYTHON_PATH=${penv}/${pkgs.python3.sitePackages}
|
|
|
|
export PATH="${pkgs.mariadb-client}/bin:${pkgs.nodejs}/bin:${penv}/bin:$PATH"
|
|
|
|
|
|
|
|
# Upstream initializes the DB with this command
|
|
|
|
bench new-site localhost --mariadb-root-password password --admin-password admin --install-app erpnext || true
|
|
|
|
'';
|
|
|
|
ExecStart = ''
|
|
|
|
${penv}/bin/gunicorn \
|
|
|
|
--chdir="/var/lib/erpnext/bench/sites" \
|
|
|
|
--bind=0.0.0.0:9090 \
|
|
|
|
--threads=4 \
|
|
|
|
--workers=2 \
|
|
|
|
--worker-class=gthread \
|
|
|
|
--worker-tmp-dir=/dev/shm \
|
|
|
|
--timeout=120 \
|
|
|
|
--preload \
|
|
|
|
frappe.app:application
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.erpnext-queue-short = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "mysql.service" "redis.service" "redis-socketio.service" ];
|
|
|
|
description = "ERPNext short queue server";
|
|
|
|
confinement = {
|
|
|
|
enable = true;
|
|
|
|
packages = [ penv ];
|
|
|
|
};
|
|
|
|
serviceConfig = defaultServiceConfig // {
|
|
|
|
ExecStart = ''
|
|
|
|
${penv}/bin/bench worker --queue short
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.erpnext-queue-default = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "mysql.service" "redis.service" "redis-socketio.service" ];
|
|
|
|
description = "ERPNext default queue server";
|
|
|
|
confinement = {
|
|
|
|
enable = true;
|
|
|
|
packages = [ penv ];
|
|
|
|
};
|
|
|
|
serviceConfig = defaultServiceConfig // {
|
|
|
|
ExecStart = ''
|
|
|
|
${penv}/bin/bench worker --queue default
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.erpnext-queue-long = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "mysql.service" "redis.service" "redis-socketio.service" ];
|
|
|
|
description = "ERPNext long queue server";
|
|
|
|
confinement = {
|
|
|
|
enable = true;
|
|
|
|
packages = [ penv ];
|
|
|
|
};
|
|
|
|
serviceConfig = defaultServiceConfig // {
|
|
|
|
ExecStart = ''
|
|
|
|
${penv}/bin/bench worker --queue long
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
|
|
|
systemd.services.erpnext-scheduler = {
|
|
|
|
enable = true;
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
|
|
|
after = [ "mysql.service" "redis.service" "redis-socketio.service" ];
|
|
|
|
description = "ERPNext scheduler server";
|
|
|
|
confinement = {
|
|
|
|
enable = true;
|
|
|
|
packages = [ penv ];
|
|
|
|
};
|
|
|
|
serviceConfig = defaultServiceConfig // {
|
|
|
|
ExecStart = ''
|
|
|
|
${penv}/bin/bench schedule
|
|
|
|
'';
|
|
|
|
};
|
|
|
|
};
|
2023-06-03 17:31:46 +00:00
|
|
|
};
|
|
|
|
}
|