Files
baby-nas/AGENTS.md
T
darroyo 4ae7335b31 feat: import existing smb.conf and /etc/exports on first boot
Adds auto-detection of pre-existing Samba shares and NFS exports when
nasctl is installed on a host that already has these configs.

New package internal/importer parses smb.conf (INI-style) and
/etc/exports (line-based) and imports them into SQLite.

Imported shares/exports are marked dirty so the user must review
and apply manually before any file is overwritten.

Backup: before the first Apply, each module backs up the original
config to <path>.nasctl.bak.<timestamp> (one time only).

New CLI flag --import-on-boot / NASCTL_IMPORT_ON_BOOT env var
(default false, opt-in).

New API endpoints:
  GET  /api/import/status
  POST /api/import/samba
  POST /api/import/nfs

New DB methods ReplaceSambaShares/ReplaceNFSExports (transactional
replace-all), guarded by import.samba.done / import.nfs.done
settings flags.
2026-07-05 21:45:25 -04:00

2.0 KiB

nasctl — Agent Guidance

Build

make build      # frontend (Vite builds to internal/web/dist) + Go binary → bin/nasctl
make build-go   # Go only (requires internal/web/dist to exist)
make run        # dev run: uses .data/, NASCTL_EXEC_SYSTEM=false

The Vite config (web/vite.config.ts) outputs directly to internal/web/dist for Go embedding. Do not change outDir.

Testing

make test       # go test ./...

No separate frontend test command; no lint/typecheck Makefile targets.

Project Structure

  • cmd/nasctl/main.go — entrypoint, CLI flags
  • internal/web/ — HTTP server, handlers, embed.go (frontend assets)
  • internal/db/ — SQLite models and queries
  • internal/modules/samba/, nfs/, users/ — config generators and system executors
  • internal/engine/apply.go — dirty→apply orchestration
  • web/ — React frontend source (Vite + Tailwind + TypeScript)

Key Runtime Behaviors

  • Changes (shares, exports, users) are staged in SQLite and marked dirty; they require POST /api/apply to take effect.
  • NASCTL_EXEC_SYSTEM=false (default in dev via make run) prevents real system changes: no service reloads, no useradd, no smbpasswd.
  • In production, set NASCTL_EXEC_SYSTEM=true and ensure NASCTL_ALLOWED_ROOTS restricts share/export paths.

Environment Variables

Variable Dev default Production default
NASCTL_ADDR :8080 :8080
NASCTL_DB ./.data/nasctl.db /var/lib/nasctl/nasctl.db
NASCTL_SMB_CONF ./.data/smb.conf /etc/samba/smb.conf
NASCTL_EXPORTS ./.data/exports /etc/exports
NASCTL_EXEC_SYSTEM false true
NASCTL_ALLOWED_ROOTS (empty) (empty = any absolute path)
NASCTL_IMPORT_ON_BOOT false true to import existing smb.conf and /etc/exports on first boot

Frontend Dev

cd web && npm run dev   # Vite on :5173, proxies /api to :8080

Requires web/node_modules (run cd web && npm install first).