Open blaggacao opened 1 year ago
@blaggacao Did you find a way to init a bench branch on nixos. The crobtab thing is driving me crazy. Here is the flake.nix I am using for dev shell -
{
description = "Development environment for Bench installation with cron support";
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
config.allowUnfree = true;
};
python3 = pkgs.python3;
in
{
devShells.default = pkgs.mkShell {
buildInputs = with pkgs; [
coreutils
gitMinimal
redis
nodejs
mariadb
postgresql
yarn
cronie
wkhtmltopdf
nginx
xvfb-run
fontconfig
curl
uv
zsh
sudo
] ++ (with python3.pkgs; [
pip
supervisor
psutil
click
gitpython
python-crontab
requests
semantic-version
setuptools
tomli
honcho
staticjinja
]);
nativeBuildInputs = with python3.pkgs; [
hatchling
];
shellHook = ''
export SHELL=${pkgs.zsh}/bin/zsh
# Setup virtual environment using uv
if [ ! -d ".venv" ]; then
uv venv
fi
source .venv/bin/activate
# Install frappe-bench
uv pip install frappe-bench
echo "Bench development environment activated!"
echo "Node.js version: $(node --version)"
echo "Run 'bench init <directory-name>' to create a new Bench instance."
# Create a directory for the PID file if it doesn't exist
mkdir -p /run/crond
# Start crond in the background with a custom PID file location
${pkgs.cronie}/bin/crond -n -p /run/crond/crond.pid &
# Notify about cron jobs
echo "Cron daemon started. To add jobs for root, use 'sudo crontab -e'."
# Start Zsh
exec zsh
'';
};
}
);
}
@vasujain275 https://github.com/blaggacao/frappix
@blaggacao Thanks alottt man, its a life saver ❤️❤️
Sets up the Environment ...
(by leveraging
PATH
)... and calls python to setup import paths
(by leveraging python's
site.addsitedir()
)... before it calls the bench cli
Since all paths in
/nix/*
are reproducible and automatically fetched from cache.nixos.org, and provided that I didn't miss any intricacies while reverse-engineering the runtime deps from ansible roles or thepyproject.toml
, we have a complete (non-root) bench environment (excluding services).Since reverse engineering that stuff from all over the place is hard and likely also a significant chore for the different target OS systems, I get the impression that it might be worth it to dig a little deeper on the capabilities of this system since it looks like it can cut (really: abstract) a lot of maintenance complexity with quite impressive results.
Specifically, after analyzing the code, it could replace
bench install
and parts ofbench setup
with minimal declarative data input to thenix
binary, that roughly looks like this: