erpnext-nix/README.md

120 lines
3.7 KiB
Markdown
Raw Permalink Normal View History

2023-07-15 14:32:18 +00:00
# ERPNext on NixOS
2023-06-12 13:28:17 +00:00
### Cachix
Using the https://pub-solar.cachix.org binary cache:
```
cachix use pub-solar
```
Or manually add the following lines to your `~/.config/nix/nix.conf`:
```
substituters = https://cache.nixos.org/ https://pub-solar.cachix.org
trusted-public-keys = cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= pub-solar.cachix.org-1:ZicXIxKgdxMtgSJECWR8iihZxHRvu8ObL4n2cuBmtos=
```
Pushing to the https://pub-solar.cachix.org binary cache (in this example, we push the
package `run-erpnext` and its dependencies):
```
nix develop
nix build --json .#run-erpnext \
| jq -r '.[].outputs | to_entries[].value' \
| cachix push pub-solar
```
### Updating `bench`, `erpnext`, `frappe` versions and hashes
Versions and hashes are in `srcs/pin.nix`. To quickly update those to the
latest version, run:
```
cd srcs
./update.sh
# If you need specific versions, specify them as arguments
./update.sh <bench_version> <erpnext_version> <frappe_version>
```
2023-06-12 13:28:17 +00:00
### NixOS VM
2023-07-17 19:06:45 +00:00
Initial setup:
2023-06-12 13:28:17 +00:00
```
2023-07-15 14:32:18 +00:00
# Build the test VM
2023-06-12 13:28:17 +00:00
nix build '.#nixosConfigurations.test-vm.config.system.build.vm'
2023-07-15 14:32:18 +00:00
# Start the VM, to generate SSH host key files required for secrets
2023-06-12 13:28:17 +00:00
./result/bin/run-nixos-vm
2023-07-17 19:06:45 +00:00
# In another terminal, get the ed25519 SSH hostkey, then stop the VM with CTRL-c
SSH_HOST_KEY=$(ssh-keyscan -p 2222 127.0.0.1 | grep '\[127.0.0.1\]:2222 ssh-ed25519' | awk '{print $2 " " $3}')
2023-07-15 14:32:18 +00:00
2023-07-17 19:06:45 +00:00
# Edit secrets.nix and add the SSH hostkey to machine 'test-vm', starting with 'ssh-ed25519 ...'
sed --in-place \
"s|test-vm = .*|test-vm = \"$SSH_HOST_KEY host@test-vm\";|" \
2023-07-17 19:06:45 +00:00
secrets/secrets.nix
2023-07-15 14:32:18 +00:00
# Rekey the secrets with agenix
2023-07-17 19:06:45 +00:00
cd secrets && agenix --rekey && cd ..
2023-07-15 14:32:18 +00:00
2023-07-17 19:06:45 +00:00
# Build the test VM again
2023-07-15 14:32:18 +00:00
nix build '.#nixosConfigurations.test-vm.config.system.build.vm'
2023-07-17 19:06:45 +00:00
# Start the VM once more
2023-07-15 14:32:18 +00:00
./result/bin/run-nixos-vm
# Access the VM via SSH, use an empty password (Enter) to login
ssh root@localhost -p 2222
2023-06-12 13:28:17 +00:00
# Watch erpnext startup:
2023-07-15 14:32:18 +00:00
# The initial startup can take a few minutes
journalctl -fu erpnext-web.service
2023-07-17 19:06:45 +00:00
# Open https://localhost:8081 in your browser and follow the setup wizard
2023-06-12 13:28:17 +00:00
# User: Administrator
# Password: admin
2023-07-17 19:06:45 +00:00
```
After the initial setup, make changes, build and run the VM again to test the changes.
```
# Build the test VM
nix build '.#nixosConfigurations.test-vm.config.system.build.vm'
# Start the VM
./result/bin/run-nixos-vm
```
2023-07-15 14:32:18 +00:00
2023-07-17 19:06:45 +00:00
Useful for debugging, you can delete a special file in the VM to force the
ERPNext init script to run again. It will then try to initialize the DB again
and create a new site directory.
```
ssh root@localhost -p 2222
rm /var/lib/erpnext/.db-created
systemctl restart erpnext-web
```
To reset the VM's data and start fresh, run:
```
2023-07-15 14:32:18 +00:00
rm nixos.qcow2
2023-06-12 13:28:17 +00:00
```
2023-07-17 19:06:45 +00:00
Note that this will re-generate SSH host keys and you will need to do the
initial setup again.
2023-06-12 13:28:17 +00:00
### Docker
2023-05-30 18:06:34 +00:00
```
docker run -d --name erpnext-redis-socketio -p 12311:6379 redis:latest
docker run -d --name erpnext-redis-queue -p 6379:6379 redis:latest
docker run -d --name erpnext-db -p 3306:3306 -e MARIADB_ROOT_PASSWORD=password -e MARIADB_DATABASE=erpnext -e MARIADB_USER=erpnext -e MARIADB_PASSWORD=erpnext mariadb:latest --collation-server=utf8mb4_unicode_ci
2023-06-12 13:28:17 +00:00
nix build .#run-erpnext
./result/bin/run-erpnext
2023-05-30 18:06:34 +00:00
# new terminal
nix shell nixpkgs#nginx
nginx -c /tmp/erpnext/nginx-erpnext.conf -g "daemon off;"
# http://localhost:8081
# User: Administrator
# Password: admin
```
2023-06-12 13:28:17 +00:00
### Links:
- https://erpnext.com
- https://docs.erpnext.com/docs/v14/user/manual/en/setting-up
- https://discuss.frappe.io/t/installing-the-docker-image-on-a-local-machine-without-letsencrypt-so-we-can-access-it-with-http-localhost/87585/7
- https://github.com/frappe/frappe_docker/blob/main/images/production/Containerfile
- https://github.com/frappe/bench
- https://github.com/frappe/erpnext
- https://github.com/frappe/frappe