diff options
author | Tobias Poschwatta <poschwatta@zib.de> | 2024-03-22 09:46:06 +0100 |
---|---|---|
committer | Tobias Poschwatta <poschwatta@zib.de> | 2024-03-25 12:22:48 +0100 |
commit | ee2b899ff708ba8d94567c3cea8a0e823d262513 (patch) | |
tree | cebff9672cea8f27419b8b906c1ae05fcd757dd5 /nixos/modules/tasks | |
parent | 3353792819e0e57c146977cbab6495aaa4f936e1 (diff) | |
download | nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.tar nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.tar.gz nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.tar.bz2 nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.tar.lz nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.tar.xz nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.tar.zst nixlib-ee2b899ff708ba8d94567c3cea8a0e823d262513.zip |
nixos/nfsd: settings for /etc/nfs.conf
services.nfs.settings is added for options that go into /etc/nfs.conf. There are services.nfs.server.extraNfsdConfig and services.nfs.extraConfig, but they have drawbacks. They overlap in scope (nfs.extraConfig can also add nfsd options). They require that one writes INI syntax. They often produce nfs.conf files with duplicate section names, which is confusing. This deprecates services.nfs.server.extraNfsdConfig and services.nfs.extraConfig. services.nfs.settings cannot be used together with services.nfs.server.extraNfsdConfig or services.nfs.extraConfig.
Diffstat (limited to 'nixos/modules/tasks')
-rw-r--r-- | nixos/modules/tasks/filesystems/nfs.nix | 65 |
1 files changed, 64 insertions, 1 deletions
diff --git a/nixos/modules/tasks/filesystems/nfs.nix b/nixos/modules/tasks/filesystems/nfs.nix index 462568b5db3e..a447eef37f9a 100644 --- a/nixos/modules/tasks/filesystems/nfs.nix +++ b/nixos/modules/tasks/filesystems/nfs.nix @@ -13,7 +13,46 @@ let format = pkgs.formats.ini {}; idmapdConfFile = format.generate "idmapd.conf" cfg.idmapd.settings; - nfsConfFile = pkgs.writeText "nfs.conf" cfg.extraConfig; + + # merge parameters from services.nfs.server + nfsConfSettings = + optionalAttrs (cfg.server.nproc != null) { + nfsd.threads = cfg.server.nproc; + } // optionalAttrs (cfg.server.hostName != null) { + nfsd.host= cfg.hostName; + } // optionalAttrs (cfg.server.mountdPort != null) { + mountd.port = cfg.server.mountdPort; + } // optionalAttrs (cfg.server.statdPort != null) { + statd.port = cfg.server.statdPort; + } // optionalAttrs (cfg.server.lockdPort != null) { + lockd.port = cfg.server.lockdPort; + lockd.udp-port = cfg.server.lockdPort; + }; + + nfsConfDeprecated = cfg.extraConfig + '' + [nfsd] + threads=${toString cfg.server.nproc} + ${optionalString (cfg.server.hostName != null) "host=${cfg.server.hostName}"} + ${cfg.server.extraNfsdConfig} + + [mountd] + ${optionalString (cfg.server.mountdPort != null) "port=${toString cfg.server.mountdPort}"} + + [statd] + ${optionalString (cfg.server.statdPort != null) "port=${toString cfg.server.statdPort}"} + + [lockd] + ${optionalString (cfg.server.lockdPort != null) '' + port=${toString cfg.server.lockdPort} + udp-port=${toString cfg.server.lockdPort} + ''} + ''; + + nfsConfFile = + if cfg.settings != {} + then format.generate "nfs.conf" (recursiveUpdate nfsConfSettings cfg.settings) + else pkgs.writeText "nfs.conf" nfsConfDeprecated; + requestKeyConfFile = pkgs.writeText "request-key.conf" '' create id_resolver * * ${pkgs.nfs-utils}/bin/nfsidmap -t 600 %k %d ''; @@ -46,6 +85,19 @@ in } ''; }; + settings = mkOption { + type = format.type; + default = {}; + description = lib.mdDoc '' + General configuration for NFS daemons and tools. + See nfs.conf(5) and related man pages for details. + ''; + example = literalExpression '' + { + mountd.manage-gids = true; + } + ''; + }; extraConfig = mkOption { type = types.lines; default = ""; @@ -60,6 +112,17 @@ in config = mkIf (config.boot.supportedFilesystems.nfs or config.boot.supportedFilesystems.nfs4 or false) { + warnings = + (optional (cfg.extraConfig != "") '' + `services.nfs.extraConfig` is deprecated. Use `services.nfs.settings` instead. + '') ++ (optional (cfg.server.extraNfsdConfig != "") '' + `services.nfs.server.extraNfsdConfig` is deprecated. Use `services.nfs.settings` instead. + ''); + assertions = [{ + assertion = cfg.settings != {} -> cfg.extraConfig == "" && cfg.server.extraNfsdConfig == ""; + message = "`services.nfs.settings` cannot be used together with `services.nfs.extraConfig` and `services.nfs.server.extraNfsdConfig`."; + }]; + services.rpcbind.enable = true; services.nfs.idmapd.settings = { |