From 3123d313c16120ad7d1f10ae9c73c79b7aac904f Mon Sep 17 00:00:00 2001 From: Martin Date: Tue, 31 Mar 2026 12:10:00 +0200 Subject: [PATCH] fix(nfs): support comma-separated networks in allowed_network field --- nfs/README.md | 94 ++++++++++++++++++++++++++++++++++++++++++------- nfs/config.json | 2 +- nfs/run.sh | 8 ++++- 3 files changed, 90 insertions(+), 14 deletions(-) diff --git a/nfs/README.md b/nfs/README.md index 7bb4f99..17702bb 100644 --- a/nfs/README.md +++ b/nfs/README.md @@ -1,24 +1,94 @@ # Home Assistant Add-on: NFS Server -This add-on exposes the Home Assistant media folder via NFS. +![Supports amd64 Architecture][amd64-shield] +![Supports aarch64 Architecture][aarch64-shield] +![Supports armv7 Architecture][armv7-shield] + +This add-on provides a **user-space NFS server** based on unfs3, perfect for: + +- Mounting Home Assistant folders on other machines on your network +- Sharing media, config, or backup folders over NFS + +It is designed to be **lightweight and kernel-independent**, running entirely in user-space without requiring NFS kernel modules. ## Configuration -The following configuration options are available: +```yaml +shares: + - folder: media + allowed_network: 192.168.1.0/24 + read_only: false +``` -- `allowed_network`: The network allowed to access the NFS share (e.g., `192.168.1.0/24`). Defaults to `0.0.0.0/0` (everyone). It is highly recommended to restrict this to your local network. +### Parameters -## How to use +| Variable | Default | Description | +|-----------------------------|---------------------|--------------------------------------------------------------------| +| `shares[].folder` | `media` | HA folder to export (`media`, `share`, `config`, `backup`) | +| `shares[].allowed_network` | `192.168.1.0/24` | Network(s) allowed to access the share. Comma-separated for multiple (e.g. `192.168.1.0/24, 10.0.0.0/8`) | +| `shares[].read_only` | `false` | Whether the share is read-only | -1. Start the add-on. -2. On your client machine, mount the NFS share. The NFS share will be the IP of your Home Assistant instance, and the exported path is `/media`. +You can define multiple shares: - Example on a Linux client: - ```bash - mkdir /mnt/hass-media - mount -t nfs :/media /mnt/hass-media - ``` +```yaml +shares: + - folder: media + allowed_network: 192.168.1.0/24 + read_only: false + - folder: share + allowed_network: 192.168.1.0/24 + read_only: false + - folder: config + allowed_network: 192.168.1.10/32 + read_only: true +``` + +## Installation + +1. Go to Home Assistant → **Supervisor → Add-on Store** +2. Add this repository (Settings → Repositories → `https://github.com/martemme/HomeAssistantAddons`) +3. Install the add-on, configure your shares and start it + +## Usage + +Once started, mount a share from a client machine. + +Example on Linux: +```bash +mkdir /mnt/hass-media +mount -t nfs :/media /mnt/hass-media +``` + +Example on macOS: +```bash +mkdir /mnt/hass-media +mount -t nfs -o resvport :/media /mnt/hass-media +``` + +## Requirements + +- Home Assistant OS or Supervised +- Supported architecture: `amd64`, `aarch64`, `armv7` +- NFS kernel modules are **not** required (uses unfs3 user-space server) ## Notes -This addon requires `host_network` and `SYS_ADMIN` privileges to run. +> ⚠️ Always restrict `allowed_network` to your local subnet. Avoid using `0.0.0.0/0` in production. + +## Changelog & Releases + +Releases are based on [Semantic Versioning][semver], and use the format +of `MAJOR.MINOR.PATCH`. In a nutshell, the version will be incremented +based on the following: + +- `MAJOR`: Incompatible or major changes. +- `MINOR`: Backwards-compatible new features and enhancements. +- `PATCH`: Backwards-compatible bugfixes and package updates. + +--- +Made with ❤️ for automation and resilience. + +[semver]: http://semver.org/spec/v2.0.0.html +[aarch64-shield]: https://img.shields.io/badge/aarch64-yes-green.svg +[amd64-shield]: https://img.shields.io/badge/amd64-yes-green.svg +[armv7-shield]: https://img.shields.io/badge/armv7-yes-green.svg diff --git a/nfs/config.json b/nfs/config.json index 5c2de36..7ebd317 100644 --- a/nfs/config.json +++ b/nfs/config.json @@ -1,6 +1,6 @@ { "name": "NFS Server", - "version": "1.0.6", + "version": "1.0.7", "slug": "nfs_server", "description": "Expose Home Assistant media folder via NFS.", "arch": [ diff --git a/nfs/run.sh b/nfs/run.sh index 8ef8b9a..e4815bf 100644 --- a/nfs/run.sh +++ b/nfs/run.sh @@ -24,7 +24,13 @@ else fi bashio::log.info "Exporting ${MOUNT_PATH} to ${NETWORK} (${OPTIONS})..." - echo "${MOUNT_PATH} ${NETWORK}(${OPTIONS})" >> /etc/exports + EXPORT_LINE="${MOUNT_PATH}" + IFS=',' read -ra NETWORKS <<< "${NETWORK}" + for net in "${NETWORKS[@]}"; do + net=$(echo "${net}" | tr -d ' ') + EXPORT_LINE="${EXPORT_LINE} ${net}(${OPTIONS})" + done + echo "${EXPORT_LINE}" >> /etc/exports done fi