nix-config/modules/nixos-modules/server/qbittorent/storage.nix

62 lines
1.9 KiB
Nix

{
lib,
config,
...
}: let
qbittorent_profile_directory = "/var/lib/qBittorrent/";
in {
options.services.qbittorrent.impermanence.enable = lib.mkOption {
type = lib.types.bool;
default = config.services.qbittorrent.enable && config.storage.impermanence.enable;
};
config = lib.mkIf config.services.qbittorrent.enable (lib.mkMerge [
(lib.mkIf config.storage.zfs.enable (lib.mkMerge [
{
assertions = [
{
assertion = config.services.qbittorrent.profileDir == qbittorent_profile_directory;
message = "qbittorrent data directory does not match persistence";
}
];
}
(lib.mkIf (!config.services.qbittorrent.impermanence.enable) {
# TODO: placeholder to configure a unique dataset for this service
})
(
lib.mkIf config.services.qbittorrent.impermanence.enable
{
storage.impermanence.datasets = {
"persist/system/root" = {
directories."${qbittorent_profile_directory}" = {
owner.name = "qbittorrent";
group.name = "qbittorrent";
};
};
"persist/system/qbittorrent" = {
directories."${config.services.qbittorrent.mediaDir}" = {
owner.name = "qbittorrent";
group.name = "qbittorrent";
owner.permissions = {
read = true;
write = true;
execute = true;
};
group.permissions = {
read = true;
write = true;
execute = true;
};
other.permissions = {
read = true;
write = false;
execute = true;
};
};
};
};
}
)
]))
]);
}