From 7053e317be40117eb5b44087b2cad49131fa5625 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Robert=20Sch=C3=BCtz?= Date: Sat, 4 Jul 2026 22:52:45 -0700 Subject: [PATCH] nixos/nfsd: allow exports to be an attrset This is in the spirit of RFC 42. --- .../services/network-filesystems/nfsd.nix | 24 ++++++++++++++++++- nixos/tests/nfs/kerberos.nix | 13 +++++++--- nixos/tests/nfs/simple.nix | 13 +++++++--- 3 files changed, 43 insertions(+), 7 deletions(-) diff --git a/nixos/modules/services/network-filesystems/nfsd.nix b/nixos/modules/services/network-filesystems/nfsd.nix index 9d3c3f9e4188..38986dcd85f8 100644 --- a/nixos/modules/services/network-filesystems/nfsd.nix +++ b/nixos/modules/services/network-filesystems/nfsd.nix @@ -6,6 +6,14 @@ }: let + attrsToExports = lib.concatMapAttrsStringSep "\n" ( + exportPoint: clientsAndOptions: + exportPoint + + lib.concatMapAttrsStringSep "" ( + client: options: " ${client}(${lib.concatStringsSep "," options})" + ) clientsAndOptions + ); + cfg = config.services.nfs.server; exports = pkgs.writeText "exports" cfg.exports; @@ -48,12 +56,26 @@ in }; exports = lib.mkOption { - type = lib.types.lines; + type = with lib.types; coercedTo (attrsOf (attrsOf (listOf str))) attrsToExports lines; default = ""; description = '' Contents of the /etc/exports file. See {manpage}`exports(5)` for the format. ''; + example = { + "/usr" = { + "*.local.domain" = [ "ro" ]; + "@trusted" = [ "rw" ]; + }; + "/home/joe" = { + "pc001" = [ + "rw" + "all_squash" + "anonuid=150" + "anongid=100" + ]; + }; + }; }; hostName = lib.mkOption { diff --git a/nixos/tests/nfs/kerberos.nix b/nixos/tests/nfs/kerberos.nix index f9720cfb87e2..ae787f8b7436 100644 --- a/nixos/tests/nfs/kerberos.nix +++ b/nixos/tests/nfs/kerberos.nix @@ -83,9 +83,16 @@ import ../make-test-python.nix ( services.nfs.server.enable = true; services.nfs.server.createMountPoints = true; - services.nfs.server.exports = '' - /data *(rw,no_root_squash,fsid=0,sec=krb5p) - ''; + services.nfs.server.exports = { + "/data" = { + "*" = [ + "rw" + "no_root_squash" + "fsid=0" + "sec=krb5p" + ]; + }; + }; }; }; diff --git a/nixos/tests/nfs/simple.nix b/nixos/tests/nfs/simple.nix index 3f2b8d3bbb1c..eebcb36cc0a5 100644 --- a/nixos/tests/nfs/simple.nix +++ b/nixos/tests/nfs/simple.nix @@ -37,9 +37,16 @@ import ../make-test-python.nix ( { ... }: { services.nfs.server.enable = true; - services.nfs.server.exports = '' - /data 192.168.1.0/255.255.255.0(rw,no_root_squash,no_subtree_check,fsid=0) - ''; + services.nfs.server.exports = { + "/data" = { + "192.168.1.0/255.255.255.0" = [ + "rw" + "no_root_squash" + "no_subtree_check" + "fsid=0" + ]; + }; + }; services.nfs.server.createMountPoints = true; networking.firewall.enable = false; # FIXME: figure out what ports need to be allowed };