1 # Configuration for the xfs_quota command
3 { config, lib, pkgs, ... }:
9 cfg = config.programs.xfs_quota;
11 limitOptions = opts: concatStringsSep " " [
12 (optionalString (opts.sizeSoftLimit != null) "bsoft=${opts.sizeSoftLimit}")
13 (optionalString (opts.sizeHardLimit != null) "bhard=${opts.sizeHardLimit}")
24 programs.xfs_quota = {
27 type = types.attrsOf (types.submodule {
31 description = lib.mdDoc "Project ID.";
34 fileSystem = mkOption {
36 description = lib.mdDoc "XFS filesystem hosting the xfs_quota project.";
42 description = lib.mdDoc "Project directory.";
45 sizeSoftLimit = mkOption {
46 type = types.nullOr types.str;
49 description = lib.mdDoc "Soft limit of the project size";
52 sizeHardLimit = mkOption {
53 type = types.nullOr types.str;
56 description = lib.mdDoc "Hard limit of the project size.";
61 description = lib.mdDoc "Setup of xfs_quota projects. Make sure the filesystem is mounted with the pquota option.";
66 path = "/xfsprojects/projname";
67 sizeHardLimit = "50g";
78 config = mkIf (cfg.projects != {}) {
80 environment.etc.projects.source = pkgs.writeText "etc-project"
81 (concatStringsSep "\n" (mapAttrsToList
82 (name: opts: "${toString opts.id}:${opts.path}") cfg.projects));
84 environment.etc.projid.source = pkgs.writeText "etc-projid"
85 (concatStringsSep "\n" (mapAttrsToList
86 (name: opts: "${name}:${toString opts.id}") cfg.projects));
88 systemd.services = mapAttrs' (name: opts:
89 nameValuePair "xfs_quota-${name}" {
90 description = "Setup xfs_quota for project ${name}";
92 ${pkgs.xfsprogs.bin}/bin/xfs_quota -x -c 'project -s ${name}' ${opts.fileSystem}
93 ${pkgs.xfsprogs.bin}/bin/xfs_quota -x -c 'limit -p ${limitOptions opts} ${name}' ${opts.fileSystem}
96 wantedBy = [ "multi-user.target" ];
97 after = [ ((replaceChars [ "/" ] [ "-" ] opts.fileSystem) + ".mount") ];
99 restartTriggers = [ config.environment.etc.projects.source ];
103 RemainAfterExit = true;