forked from axeman/erpnext-nix
WIP: Create a vm with systemd services to run erpnext
This commit is contained in:
parent
779d1ad5d9
commit
2bcd75eb09
50
flake.nix
50
flake.nix
|
@ -9,29 +9,35 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = {nixpkgs, flake-utils, pip2nix, ...}:
|
outputs = {nixpkgs, flake-utils, pip2nix, ...}:
|
||||||
flake-utils.lib.eachDefaultSystem (system:
|
let
|
||||||
let
|
pkgs = system: import nixpkgs {
|
||||||
pkgs = import nixpkgs {
|
inherit system;
|
||||||
inherit system;
|
overlays = [
|
||||||
overlays = [
|
(import ./python-overlay.nix)
|
||||||
(import ./python-overlay.nix)
|
(import ./overlay.nix)
|
||||||
(import ./overlay.nix)
|
];
|
||||||
|
};
|
||||||
|
packages = flake-utils.lib.eachDefaultSystem (system: rec {
|
||||||
|
devEnv = pkgs.buildEnv {
|
||||||
|
name = "erpnext-nix-dev-env";
|
||||||
|
paths = [
|
||||||
|
pkgs.dasel
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
in rec {
|
inherit pkgs;
|
||||||
packages = {
|
run-erpnext = pkgs.run-erpnext;
|
||||||
devEnv = pkgs.buildEnv {
|
pip2nix = import "${pip2nix}/default.nix" { inherit pkgs; pythonPackages = "python310Packages"; };
|
||||||
name = "erpnext-nix-dev-env";
|
erpnext = pkgs.python3.pkgs.erpnext;
|
||||||
paths = [
|
bench = pkgs.python3.pkgs.bench;
|
||||||
pkgs.dasel
|
pythonPkgs = pkgs.python3.pkgs;
|
||||||
];
|
});
|
||||||
};
|
nixosConfigurations = {
|
||||||
inherit pkgs;
|
test-vm = nixpkgs.lib.nixosSystem {
|
||||||
run-erpnext = pkgs.run-erpnext;
|
pkgs = pkgs "x86_64-linux";
|
||||||
pip2nix = import "${pip2nix}/default.nix" { inherit pkgs; pythonPackages = "python310Packages"; };
|
system = "x86_64-linux";
|
||||||
erpnext = pkgs.python3.pkgs.erpnext;
|
modules = [./test-vm/configuration.nix];
|
||||||
bench = pkgs.python3.pkgs.bench;
|
|
||||||
pythonPkgs = pkgs.python3.pkgs;
|
|
||||||
};
|
};
|
||||||
});
|
};
|
||||||
|
in {inherit packages nixosConfigurations;};
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
132
test-vm/configuration.nix
Normal file
132
test-vm/configuration.nix
Normal file
|
@ -0,0 +1,132 @@
|
||||||
|
{ pkgs, lib, config, modulesPath, ... }:
|
||||||
|
with lib;
|
||||||
|
{
|
||||||
|
imports = [
|
||||||
|
"${modulesPath}/profiles/minimal.nix"
|
||||||
|
"${modulesPath}/profiles/qemu-guest.nix"
|
||||||
|
"${modulesPath}/virtualisation/qemu-vm.nix"
|
||||||
|
];
|
||||||
|
|
||||||
|
config = {
|
||||||
|
services.qemuGuest.enable = true;
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
# 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 = "";
|
||||||
|
users.mutableUsers = false;
|
||||||
|
|
||||||
|
environment.systemPackages = with pkgs; [
|
||||||
|
git
|
||||||
|
htop
|
||||||
|
neovim
|
||||||
|
];
|
||||||
|
|
||||||
|
services.mysql = {
|
||||||
|
enable = true;
|
||||||
|
package = pkgs.mariadb;
|
||||||
|
};
|
||||||
|
|
||||||
|
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;
|
||||||
|
};
|
||||||
|
|
||||||
|
systemd.services.erpnext =
|
||||||
|
let
|
||||||
|
penv = python3.buildEnv.override {
|
||||||
|
extraLibs = [
|
||||||
|
python3.pkgs.frappe
|
||||||
|
python3.pkgs.erpnext
|
||||||
|
python3.pkgs.bench
|
||||||
|
];
|
||||||
|
};
|
||||||
|
in
|
||||||
|
{
|
||||||
|
enable = true;
|
||||||
|
wantedBy = [ "multi-user.target" ];
|
||||||
|
after = [ "mysql.service" "redis.service" "redis-socketio.service" ];
|
||||||
|
description = "ERPNext";
|
||||||
|
confinement = {
|
||||||
|
enable = true;
|
||||||
|
packages = [ ];
|
||||||
|
};
|
||||||
|
script = ''
|
||||||
|
export PYTHON_PATH=${penv}/${python3.sitePackages}
|
||||||
|
|
||||||
|
cat > /frappe-bench/sites/apps.txt <<EOF
|
||||||
|
frappe
|
||||||
|
erpnext
|
||||||
|
EOF
|
||||||
|
|
||||||
|
cat >/frape-bench/sites/common_site_config.json <<EOF
|
||||||
|
{
|
||||||
|
"db_host": "localhost",
|
||||||
|
"db_port": 3306,
|
||||||
|
"db_name": "erpnext" ,
|
||||||
|
"db_password": "erpnext" ,
|
||||||
|
"redis_cache": "redis://localhost:6379?db=0",
|
||||||
|
"redis_queue": "redis://localhost:6379?db=1",
|
||||||
|
"redis_socketio": "redis://localhost:6379?db=2",
|
||||||
|
"socketio_port": 3000
|
||||||
|
}
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# Upstream initializes the DB with this command
|
||||||
|
# TODO: Make this idempotent
|
||||||
|
cd /frappe-bench/sites
|
||||||
|
bench new-site localhost --mariadb-root-password password --admin-password admin
|
||||||
|
bench --site localhost install-app erpnext
|
||||||
|
|
||||||
|
echo "Workdir: $tmp"
|
||||||
|
# TODO: Run these as systemd units
|
||||||
|
node $tmp/apps/frappe/socketio.js &
|
||||||
|
gunicorn --chdir="$tmp/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
|
||||||
|
'';
|
||||||
|
serviceConfig = {
|
||||||
|
User = "erpnext";
|
||||||
|
NoNewPrivileges = true;
|
||||||
|
Type = "simple";
|
||||||
|
BindReadOnlyPaths = [
|
||||||
|
"${frappe-app}/share/apps/frappe:/frappe-bench/apps/frappe"
|
||||||
|
"${erpnext-app}/share/apps/erpnext:/frappe-bench/apps/erpnext"
|
||||||
|
"${frappe-erpnext-assets}/share/sites/assets:/frappe-bench/sites/assets"
|
||||||
|
# "${penv}:/frappe-bench/env"
|
||||||
|
];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue