1 # Configuration for the xfs_quota command
3 { config, lib, pkgs, ... }:
7 cfg = config.programs.xfs_quota;
9 limitOptions = opts: builtins.concatStringsSep " " [
10 (lib.optionalString (opts.sizeSoftLimit != null) "bsoft=${opts.sizeSoftLimit}")
11 (lib.optionalString (opts.sizeHardLimit != null) "bhard=${opts.sizeHardLimit}")
22 programs.xfs_quota = {
23 projects = lib.mkOption {
25 type = lib.types.attrsOf (lib.types.submodule {
29 description = "Project ID.";
32 fileSystem = lib.mkOption {
34 description = "XFS filesystem hosting the xfs_quota project.";
40 description = "Project directory.";
43 sizeSoftLimit = lib.mkOption {
44 type = lib.types.nullOr lib.types.str;
47 description = "Soft limit of the project size";
50 sizeHardLimit = lib.mkOption {
51 type = lib.types.nullOr lib.types.str;
54 description = "Hard limit of the project size.";
59 description = "Setup of xfs_quota projects. Make sure the filesystem is mounted with the pquota option.";
64 path = "/xfsprojects/projname";
65 sizeHardLimit = "50g";
76 config = lib.mkIf (cfg.projects != {}) {
78 environment.etc.projects.source = pkgs.writeText "etc-project"
79 (builtins.concatStringsSep "\n" (lib.mapAttrsToList
80 (name: opts: "${builtins.toString opts.id}:${opts.path}") cfg.projects));
82 environment.etc.projid.source = pkgs.writeText "etc-projid"
83 (builtins.concatStringsSep "\n" (lib.mapAttrsToList
84 (name: opts: "${name}:${builtins.toString opts.id}") cfg.projects));
86 systemd.services = lib.mapAttrs' (name: opts:
87 lib.nameValuePair "xfs_quota-${name}" {
88 description = "Setup xfs_quota for project ${name}";
90 ${pkgs.xfsprogs.bin}/bin/xfs_quota -x -c 'project -s ${name}' ${opts.fileSystem}
91 ${pkgs.xfsprogs.bin}/bin/xfs_quota -x -c 'limit -p ${limitOptions opts} ${name}' ${opts.fileSystem}
94 wantedBy = [ "multi-user.target" ];
95 after = [ ((builtins.replaceStrings [ "/" ] [ "-" ] opts.fileSystem) + ".mount") ];
97 restartTriggers = [ config.environment.etc.projects.source ];
101 RemainAfterExit = true;