61 lines
		
	
	
	
		
			1.5 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			61 lines
		
	
	
	
		
			1.5 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.host.impermanence.enable;
 | 
						|
    };
 | 
						|
  };
 | 
						|
 | 
						|
  config = lib.mkIf config.services.qbittorrent.impermanence.enable {
 | 
						|
    fileSystems."/persist/system/qbittorrent".neededForBoot = true;
 | 
						|
 | 
						|
    host.storage.pool.extraDatasets = {
 | 
						|
      # sops age key needs to be available to pre persist for user generation
 | 
						|
      "persist/system/qbittorrent" = {
 | 
						|
        type = "zfs_fs";
 | 
						|
        mountpoint = "/persist/system/qbittorrent";
 | 
						|
        options = {
 | 
						|
          canmount = "on";
 | 
						|
        };
 | 
						|
      };
 | 
						|
    };
 | 
						|
 | 
						|
    assertions = [
 | 
						|
      {
 | 
						|
        assertion = config.services.qbittorrent.profileDir == qbittorent_profile_directory;
 | 
						|
        message = "qbittorrent data directory does not match persistence";
 | 
						|
      }
 | 
						|
    ];
 | 
						|
 | 
						|
    environment.persistence = {
 | 
						|
      "/persist/system/root" = {
 | 
						|
        directories = [
 | 
						|
          {
 | 
						|
            directory = qbittorent_profile_directory;
 | 
						|
            user = "qbittorrent";
 | 
						|
            group = "qbittorrent";
 | 
						|
          }
 | 
						|
        ];
 | 
						|
      };
 | 
						|
 | 
						|
      "/persist/system/qbittorrent" = {
 | 
						|
        enable = true;
 | 
						|
        hideMounts = true;
 | 
						|
        directories = [
 | 
						|
          {
 | 
						|
            directory = config.services.qbittorrent.mediaDir;
 | 
						|
            user = "qbittorrent";
 | 
						|
            group = "qbittorrent";
 | 
						|
            mode = "1775";
 | 
						|
          }
 | 
						|
        ];
 | 
						|
      };
 | 
						|
    };
 | 
						|
  };
 | 
						|
}
 |