Development
Everyday commands
The bench wrapper that redirects the commands needing frappe-nix handling, and the scripts behind it, from bench provision to bench-update.
On this page
The shell ships an umbrella bench wrapper. It shadows the virtualenv's bench (devenv wraps scripts with lib.hiPrioSet, so it wins on PATH) and transparently redirects the subcommands that need frappe-nix handling. You run normal bench commands and the right thing happens on a read-only Nix store, in a uv workspace, with git submodules. bench ui opens the menu.
What the wrapper redirects
| You run | Redirected to | Why |
|---|---|---|
bench update … | bench-update | Vanilla update pip-installs and assumes upstream remotes. |
bench build … | bench-build | Brings node_modules back in step with the apps first. |
bench setup requirements … | bench-setup-requirements | Verifies and repairs node_modules and the yarn cache, installs what is missing, checks the Python requirements are locked. See The development shell. |
bench get-app [--branch <B>] <URL_OR_ALIAS> | bench-get-app | A git submodule and a uv workspace member instead of pip. |
bench new-app | bench-new-app | Scaffold plus uv workspace, skipping the failing pip step. |
bench remove-app [--force] [--no-backup] | bench-remove-app | Submodule, .gitmodules and uv workspace instead of apps.txt and pip. |
bench rename-app [--no-pull] <OLD> <NEW> | bench-rename-app | Moves the submodule, its clone and the workspace member instead of removing and re-adding them. |
bench restore [<FILE>] | bench-restore | Injects the MariaDB root credentials. With no file, fetches the latest production backup. |
bench provision [ADMIN_PASSWORD] | frappe-nix's own | Creates $FRAPPE_SITE and installs every app from sites/apps.txt. Not an upstream command. See below. |
bench ui | the menu | Opens the dev shell's menu. Not an upstream command. |
bench install-app, no arguments | the store | At a terminal in a bench, opens the menu's store alone to pick apps from. With an app it is the real bench's. |
bench new-site | the real bench | Injects --db-socket and --db-root-username root, so site creation is non-interactive. |
bench migrate, console, clear-cache | bench-* | Inject --site $FRAPPE_SITE. |
everything else (serve, install-app APP, uninstall-app, --help, …) | the real bench | Unchanged. |
Two caveats follow from this:
Redirected commands follow the frappe-nix scripts' flags, not vanilla bench's.
bench updatetakes--pull,--migrate,--buildor--node-locks, not--reset.Interception is subcommand-first, so
bench --site X migrate, with a global option before the subcommand, passes straight through to the real bench.
Recursion is avoided with a _FRAPPE_BENCH_RAW environment guard. The specialized scripts export it and the wrapper checks it, so a script's own nested bench … calls reach the real CLI, whether you run bench update or bench-update directly. To reach the real command on purpose, use _FRAPPE_BENCH_RAW=1 bench update --reset.
The wrapper wins only while it is first on PATH. source env/bin/activate, or an editor that activates ./env in the terminals it opens, puts the virtualenv's own bin/ ahead of it. frappe_benchcli (lib/benchcli), grafted into the dev virtualenv, covers that: every command in the table above that the wrapper hands to a bench-* script (update, build, get-app, new-app, remove-app, rename-app, restore, migrate, console, clear-cache and setup requirements) is handed over from the virtualenv's bench too, to the same script with the same arguments, saying so on stderr. _FRAPPE_BENCH_RAW=1 bypasses it as it does the wrapper, and outside the dev shell, where those scripts are not on PATH, it refuses with the reason instead of running the stock command.
Left as the virtualenv's bench always did are the commands for which the wrapper runs no script: new-site, which it only adds flags to, install-app, whose menu is a terminal convenience, and ui and provision, which upstream does not have. The stock remove-app is why the list is not shorter. It archives apps/<app> to archived/apps/ and rewrites sites/apps.txt, and leaves the submodule, its .gitmodules section and the uv workspace entry behind. A check in nix flake check compares the two lists in both directions, so a command added to the wrapper without being added to frappe_benchcli fails it.
The real bench update stays reachable, so the shell keeps its first step working. bench update starts with bench.patches.run(), which executes every entry in the patches.txt that frappe-bench ships and that the bench root's patches.txt does not record as done. bench deleted the v3 and v4 patch modules in 2022 but still lists them, so a bench root with no record dies immediately on ModuleNotFoundError: No module named 'bench.patches.v3'. It stays dead, because the failed run rewrites the root file as one empty byte. bench init avoids this by copying the shipped list in verbatim. frappe-nix never runs bench init, and the file is gitignored, so enterShell reconciles it instead, on every shell entry, non-destructively, and silently unless it changes something. See lib/bench-patches.nix for why every patch is recorded as done, not only the two that cannot import.
The scripts
These back the wrapper and are also callable directly.
| Script | Description |
|---|---|
reconcile-apps [SITE] | Install whatever sites/apps.txt names that the site does not have installed yet. Idempotent. Also runs automatically; see Installed-app drift. |
bench-update [--pull|--migrate|--build|--node-locks] | The submodule-aware replacement for bench update. See below. |
bench-migrate, bench-build, bench-clear-cache, bench-console | Thin bench wrappers that honor $FRAPPE_SITE. With offlineMigrate.enable, bench-migrate runs bench-offline-migrate first and does not migrate if it fails. |
bench-offline-migrate [--plan|--dry-run] [--threshold <ROWS>] [-- <PT_ARGS>] | Alter the large tables the next migrate would alter, online. --plan changes nothing and needs no percona-toolkit. See Migrate large tables online. |
bench-restore [<FILE>|--at <STAMP>|--list] | Restore from a SQL backup, or from the latest one in the object store. See Restore a production backup. |
setup-backup-access | Prompt for the object-store credentials, test them against the bucket, and write backup-access.age. |
edit-secret | Decrypt a secret into $EDITOR and re-encrypt it to the declared recipients. Reads stdin when it is not a terminal, so a secret can be piped in. |
rekey-secrets | Re-encrypt every secret after changing recipients. |
check-secrets [<NAME>] | Verify the .age files match the declared recipients. With a name, explain why you cannot decrypt one. |
bench-get-app [--branch <B>] <URL_OR_ALIAS> | Add an app as a git submodule and register it. See below. |
bench-new-app | Scaffold a new app as a local app (committed source, no nested git) and register it the same way. |
bench-remove-app [--force] [--no-backup] | The inverse of bench-get-app. See below. |
bench-rename-app [--url <U>] [--branch <B>] [--no-pull] <OLD> <NEW> | The bench's half of renaming an app. See below. |
relock [--uv-only|--node-locks [<TARGET>…]] [<UV_LOCK_FLAGS>…] | Re-lock what the bench commits: uv.lock, then the fallback locks in node-locks/. The same program as nix run .#relock. See Dependencies and locks. |
update-deps | relock's Python half, then uv sync, yarn install in every app, and the fallback locks in node-locks/. Exits 1 if any step failed. |
bench provision
bench provision creates the site named by FRAPPE_SITE and installs every app sites/apps.txt lists, in that order. The Administrator password is the first argument, or admin. Put -- before a password that starts with a dash. --help prints its usage.
It runs
bench new-site --force, which drops an existing database for that site. To install an app added after the site exists, runreconcile-appsinstead.When
bench new-siteasks for the MariaDB root password, leave it blank and press Enter.It stops at the first
bench new-siteorinstall-appthat fails, with that command's exit status. A missingFRAPPE_SITEorFRAPPE_DB_SOCKETis exit 1, and a second argument is exit 2, before anything runs.It ends with the site's URL, on the port the running bench leased, or on
webserver_portfromsites/common_site_config.jsonwhen the bench is down.
provision-site was its name before frappe-nix 1.2, and an alias through 1.x. It went in frappe-nix 2.0.0.
bench-update
bench-update is the submodule-aware replacement for bench update:
--pullfetches each submodule's.gitmodulesbranch from the remote that carries its declared URL, becauseoriginis often a developer's fork.It refuses to discard local commits. A shallow clone whose pin and tip share no history at all, the shape a depth-limited fetch leaves behind and what git shows as a phantom "1 ahead", is deepened back to the pin's date and re-checked first, since that is never a local commit.
It clears the one kind of local change that is only tool output: an uncommitted
yarn.lockorpackage-lock.jsonthat the pull would overwrite (itspackage.jsonunedited), or an untracked one that upstream adds. It says which. Every other edit is carried across.When git still refuses, it skips only that app, shows git's reason and lists the apps not updated when it finishes. The rest of the pull, the registry, migrate and build still run.
It checks out a registered submodule that has no checkout (a fresh clone's, a deinitialized one's) before pulling it with the rest, and skips local apps and reports stray repos.
It then regenerates
sites/apps.jsonfor the new pins, the fallback locks innode-locks/for the apps without ayarn.lockwhosepackage.jsonmoved, and re-locks the workspace (uv lock --upgrade-package frappe-runtime) when apyproject.tomldid. The flag re-reads the runtime's dependency ranges, which plainuv lockleaves at the revision first locked.--node-locks [<TARGET>…]regeneratesnode-locks/for every app and nested frontend without ayarn.lockof its own. A named target gets a lock forced over theyarn.lockit ships.
In app mode only --migrate and --build are available.
bench-get-app
bench-get-app adds an app as a git submodule and registers it in the uv workspace and in sites/apps.{txt,json}.
helpdeskresolves tofrappe/helpdesk.owner/repoand full URLs also work.The branch, from
--branchor else the remote's default, is recorded in.gitmodules, which is whatbench-update --pullfollows.The directory is named for the Frappe app, the package holding
hooks.py, not for the repository as stockbench get-appdoes.frappe/flow_clientinstalls asapps/flow, since frappe importsflow.hooks. The name is read from a throwaway clone of the remote, with no checkout and no file contents, before anything in the bench is touched. A repository with nohooks.py, or several packages and none named for it, keeps the repository's name, with a warning.
bench-remove-app
bench-remove-app is the inverse, for the bench as a whole:
It deinitializes the submodule and drops it from
.gitmodules, staging only that removal so other uncommitted.gitmodulesedits stay as they were.It unregisters the app from the uv workspace and
sites/apps.{txt,json}, dropsnode-locks/andsites/assets/, and runsuv lock.A local app is moved to
.frappe-nix-backup/<APP>-<STAMP>unless you pass--no-backup. A submodule is not backed up, sincebench-get-appre-adds it.It refuses while any site still has the app installed, or cannot say whether it does, and while the submodule has uncommitted changes.
--forceskips both checks.
Taking an app out of one site is still the real bench --site <SITE> uninstall-app <APP>. With appsReconcile.enable on, though, the next devenv up reinstalls anything sites/apps.txt still lists.
bench-rename-app
bench-rename-app is the bench's half of renaming an app. Renaming an app has three: the package in the app's repository and the sites that have it installed are frappe-rename-app's, and a git pull of the renamed repository does none of this one. The pull leaves the old directory behind as an untracked repository and the new path empty, and the registry skips an app whose package is not named for its directory.
bench-rename-app esign esign_webformsIt moves the checkout, its clone under
.git/modulesand its.git/configsection, so nothing is downloaded again andnode_modulesand local history come along. Removing the app and adding it again does neither.It points
.gitmodulesat the renamed repository (the URL withesignreplaced byesign_webforms, or--url) and the branch (kept, or--branch), staging only that change next to the gitlink, so other uncommitted.gitmodulesedits stay as they were.git mvrefuses outright while.gitmoduleshas an unstaged edit.It fetches the branch's tip from the new URL and checks it out, which is what carries the renamed package.
--no-pullrenames the checkout where it is, and keeps the pin the bench recorded.It renames the uv workspace member and its source, regenerates
sites/apps.{txt,json}, dropsnode-locks/<OLD>andsites/assets/<OLD>, and runsuv lock.It changes nothing until the tip has been fetched and shown to hold
<NEW>/hooks.py, so a failed fetch, a repository whose package is not renamed yet, a checkout with uncommitted changes, or history that does not contain the checkout leaves the bench as it was.
It does not touch a site. The dev site still records the old name, so it ends by printing the frappe-nix.renamedApps entry that has devenv up rename it before anything installs. A vendored (local) app is moved with git add, with no repository to retarget.
update-deps
update-deps re-locks and reinstalls: uv lock --upgrade-package frappe-runtime and the managed build-dependency block, uv sync, yarn install in every app with a package.json, then the fallback locks. A failed uv lock stops it. A failed uv sync or yarn install does not stop the other apps, but the command exits 1 and names what failed. To re-lock without reinstalling, run relock.
In a bench the Node step is yarn install --pure-lockfile. It installs from package.json but never rewrites an app's own yarn.lock, which belongs to the app's repository. To update one on purpose, run yarn install in that app. An app's postinstall can still rewrite a nested frontend's lock here, which bench-update --pull discards when the pull would overwrite it. In app mode the lock is yours and is written as before.