nixpkgs/nixos/modules/programs/xfs_quota.nix
Silvan Mosberger 4f0dadbf38 treewide: format all inactive Nix files
After final improvements to the official formatter implementation,
this commit now performs the first treewide reformat of Nix files using it.
This is part of the implementation of RFC 166.

Only "inactive" files are reformatted, meaning only files that
aren't being touched by any PR with activity in the past 2 months.
This is to avoid conflicts for PRs that might soon be merged.
Later we can do a full treewide reformat to get the rest,
which should not cause as many conflicts.

A CI check has already been running for some time to ensure that new and
already-formatted files are formatted, so the files being reformatted here
should also stay formatted.

This commit was automatically created and can be verified using

    nix-build a08b3a4d19.tar.gz \
      --argstr baseRev b32a094368
    result/bin/apply-formatting $NIXPKGS_PATH
2024-12-10 20:26:33 +01:00

121 lines
3.1 KiB
Nix

# Configuration for the xfs_quota command
{
config,
lib,
pkgs,
...
}:
let
cfg = config.programs.xfs_quota;
limitOptions =
opts:
builtins.concatStringsSep " " [
(lib.optionalString (opts.sizeSoftLimit != null) "bsoft=${opts.sizeSoftLimit}")
(lib.optionalString (opts.sizeHardLimit != null) "bhard=${opts.sizeHardLimit}")
];
in
{
###### interface
options = {
programs.xfs_quota = {
projects = lib.mkOption {
default = { };
type = lib.types.attrsOf (
lib.types.submodule {
options = {
id = lib.mkOption {
type = lib.types.int;
description = "Project ID.";
};
fileSystem = lib.mkOption {
type = lib.types.str;
description = "XFS filesystem hosting the xfs_quota project.";
default = "/";
};
path = lib.mkOption {
type = lib.types.str;
description = "Project directory.";
};
sizeSoftLimit = lib.mkOption {
type = lib.types.nullOr lib.types.str;
default = null;
example = "30g";
description = "Soft limit of the project size";
};
sizeHardLimit = lib.mkOption {
type = lib.types.nullOr lib.types.str;
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 = {
projname = {
id = 50;
path = "/xfsprojects/projname";
sizeHardLimit = "50g";
};
};
};
};
};
###### implementation
config = lib.mkIf (cfg.projects != { }) {
environment.etc.projects.source = pkgs.writeText "etc-project" (
builtins.concatStringsSep "\n" (
lib.mapAttrsToList (name: opts: "${builtins.toString opts.id}:${opts.path}") cfg.projects
)
);
environment.etc.projid.source = pkgs.writeText "etc-projid" (
builtins.concatStringsSep "\n" (
lib.mapAttrsToList (name: opts: "${name}:${builtins.toString opts.id}") cfg.projects
)
);
systemd.services = lib.mapAttrs' (
name: opts:
lib.nameValuePair "xfs_quota-${name}" {
description = "Setup xfs_quota for project ${name}";
script = ''
${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}
'';
wantedBy = [ "multi-user.target" ];
after = [ ((builtins.replaceStrings [ "/" ] [ "-" ] opts.fileSystem) + ".mount") ];
restartTriggers = [ config.environment.etc.projects.source ];
serviceConfig = {
Type = "oneshot";
RemainAfterExit = true;
};
}
) cfg.projects;
};
}