User Home Size Restriction

Make XFS drives Mounted with Quota Support
master
David Crompton 2023-07-27 14:53:50 -04:00
parent d743b61df9
commit a8c9100849
6 changed files with 64 additions and 0 deletions

View File

@ -8,8 +8,12 @@
imports =
[
./hardware-configuration.nix
# Set of Modules Defining System Configuration
./modules.nix
# Set of System Wide Available Packages
./packages.nix
# Set of Users on This System
./users.nix
];
# Use the systemd-boot EFI boot loader.

View File

@ -29,6 +29,7 @@
fileSystems."/" =
{ device = "/dev/disk/by-uuid/4aa8d42a-e8c3-4b60-bc69-2d0333886c55";
fsType = "xfs";
options = [ "defaults" "pquota" ];
};
fileSystems."/boot" =
@ -39,6 +40,7 @@
fileSystems."/storage" =
{ device = "/dev/disk/by-uuid/eb2170c8-236a-40d4-baa8-07ad4981a442";
fsType = "xfs";
options = [ "defaults" "pquota" ];
};
swapDevices = [ ];

View File

@ -0,0 +1,5 @@
{ ... }: {
imports = [
./modules/userHomeSize.nix
];
}

View File

@ -0,0 +1,39 @@
{ config, lib, pkgs, ... }: with lib; let
userOpts = { name, config, ... }: {
options = {
homeSize = mkOption {
type = types.nullOr types.str;
description = "Size of user's home directory";
default = null;
};
homeProjectId = mkOption {
type = types.nullOr types.int;
description = "What project does this user's home directory belong to";
default = null;
};
};
config = {
};
};
in {
options = {
users.users = mkOption {
type = with types; attrsOf (submodule userOpts);
};
};
config = let
users' = lib.attrsets.filterAttrs (userName: user: user.homeSize != null) config.users.users;
in mkIf (users' != {}) {
programs.xfs_quota.projects = mapAttrs (userName: user: let
in {
id = user.homeProjectId;
fileSystem = "/";
path = user.home;
sizeSoftLimit = user.homeSize;
sizeHardLimit = user.homeSize;
}) users';
};
}

View File

@ -0,0 +1,5 @@
{ ... }: {
imports = [
./users/david.nix
];
}

View File

@ -0,0 +1,9 @@
{ pkgs, ... }: {
users.users.david = {
isNormalUser = true;
extraGroups = [ "wheel" ];
packages = with pkgs; [
];
};
users.userHomes.david = {};
}