2015-08-19 14:05:25 +00:00
|
|
|
# Configuration for the xfs_quota command
|
|
|
|
|
|
|
|
{ config, lib, pkgs, ... }:
|
|
|
|
|
|
|
|
let
|
|
|
|
|
|
|
|
cfg = config.programs.xfs_quota;
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
limitOptions = opts: builtins.concatStringsSep " " [
|
|
|
|
(lib.optionalString (opts.sizeSoftLimit != null) "bsoft=${opts.sizeSoftLimit}")
|
|
|
|
(lib.optionalString (opts.sizeHardLimit != null) "bhard=${opts.sizeHardLimit}")
|
2015-08-19 14:05:25 +00:00
|
|
|
];
|
|
|
|
|
|
|
|
in
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
###### interface
|
|
|
|
|
|
|
|
options = {
|
|
|
|
|
|
|
|
programs.xfs_quota = {
|
2024-04-17 11:37:58 +00:00
|
|
|
projects = lib.mkOption {
|
2015-08-19 16:03:42 +00:00
|
|
|
default = {};
|
2024-04-17 11:37:58 +00:00
|
|
|
type = lib.types.attrsOf (lib.types.submodule {
|
2015-08-19 14:05:25 +00:00
|
|
|
options = {
|
2024-04-17 11:37:58 +00:00
|
|
|
id = lib.mkOption {
|
|
|
|
type = lib.types.int;
|
2015-08-19 14:05:25 +00:00
|
|
|
description = "Project ID.";
|
|
|
|
};
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
fileSystem = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2015-08-19 14:05:25 +00:00
|
|
|
description = "XFS filesystem hosting the xfs_quota project.";
|
|
|
|
default = "/";
|
|
|
|
};
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
path = lib.mkOption {
|
|
|
|
type = lib.types.str;
|
2015-08-19 14:05:25 +00:00
|
|
|
description = "Project directory.";
|
|
|
|
};
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
sizeSoftLimit = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2015-08-19 14:05:25 +00:00
|
|
|
default = null;
|
|
|
|
example = "30g";
|
|
|
|
description = "Soft limit of the project size";
|
|
|
|
};
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
sizeHardLimit = lib.mkOption {
|
|
|
|
type = lib.types.nullOr lib.types.str;
|
2015-08-19 14:05:25 +00:00
|
|
|
default = null;
|
|
|
|
example = "50g";
|
|
|
|
description = "Hard limit of the project size.";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
|
|
|
description = "Setup of xfs_quota projects. Make sure the filesystem is mounted with the pquota option.";
|
|
|
|
|
|
|
|
example = {
|
2019-08-13 21:52:01 +00:00
|
|
|
projname = {
|
2015-08-19 14:05:25 +00:00
|
|
|
id = 50;
|
|
|
|
path = "/xfsprojects/projname";
|
|
|
|
sizeHardLimit = "50g";
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
###### implementation
|
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
config = lib.mkIf (cfg.projects != {}) {
|
2015-08-19 14:05:25 +00:00
|
|
|
|
|
|
|
environment.etc.projects.source = pkgs.writeText "etc-project"
|
2024-04-17 11:37:58 +00:00
|
|
|
(builtins.concatStringsSep "\n" (lib.mapAttrsToList
|
|
|
|
(name: opts: "${builtins.toString opts.id}:${opts.path}") cfg.projects));
|
2015-08-19 14:05:25 +00:00
|
|
|
|
|
|
|
environment.etc.projid.source = pkgs.writeText "etc-projid"
|
2024-04-17 11:37:58 +00:00
|
|
|
(builtins.concatStringsSep "\n" (lib.mapAttrsToList
|
|
|
|
(name: opts: "${name}:${builtins.toString opts.id}") cfg.projects));
|
2015-08-19 14:05:25 +00:00
|
|
|
|
2024-04-17 11:37:58 +00:00
|
|
|
systemd.services = lib.mapAttrs' (name: opts:
|
|
|
|
lib.nameValuePair "xfs_quota-${name}" {
|
2015-08-19 14:05:25 +00:00
|
|
|
description = "Setup xfs_quota for project ${name}";
|
|
|
|
script = ''
|
2016-02-01 18:46:23 +00:00
|
|
|
${pkgs.xfsprogs.bin}/bin/xfs_quota -x -c 'project -s ${name}' ${opts.fileSystem}
|
|
|
|
${pkgs.xfsprogs.bin}/bin/xfs_quota -x -c 'limit -p ${limitOptions opts} ${name}' ${opts.fileSystem}
|
2015-08-19 14:05:25 +00:00
|
|
|
'';
|
|
|
|
|
|
|
|
wantedBy = [ "multi-user.target" ];
|
2024-04-17 11:37:58 +00:00
|
|
|
after = [ ((builtins.replaceStrings [ "/" ] [ "-" ] opts.fileSystem) + ".mount") ];
|
2015-08-19 14:05:25 +00:00
|
|
|
|
2015-08-19 18:04:08 +00:00
|
|
|
restartTriggers = [ config.environment.etc.projects.source ];
|
2015-08-19 14:05:25 +00:00
|
|
|
|
|
|
|
serviceConfig = {
|
|
|
|
Type = "oneshot";
|
|
|
|
RemainAfterExit = true;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
) cfg.projects;
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
}
|