73 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
			
		
		
	
	
			73 lines
		
	
	
	
		
			1.9 KiB
		
	
	
	
		
			Nix
		
	
	
	
	
	
{
 | 
						|
  lib,
 | 
						|
  config,
 | 
						|
  ...
 | 
						|
}: let
 | 
						|
  jellyfin_data_directory = "/var/lib/jellyfin";
 | 
						|
  jellyfin_cache_directory = "/var/cache/jellyfin";
 | 
						|
in {
 | 
						|
  options.services.jellyfin = {
 | 
						|
    impermanence.enable = lib.mkOption {
 | 
						|
      type = lib.types.bool;
 | 
						|
      default = config.services.jellyfin.enable && config.host.impermanence.enable;
 | 
						|
    };
 | 
						|
  };
 | 
						|
 | 
						|
  config = lib.mkIf config.services.jellyfin.impermanence.enable {
 | 
						|
    fileSystems."/persist/system/jellyfin".neededForBoot = true;
 | 
						|
 | 
						|
    host.storage.pool.extraDatasets = {
 | 
						|
      # sops age key needs to be available to pre persist for user generation
 | 
						|
      "persist/system/jellyfin" = {
 | 
						|
        type = "zfs_fs";
 | 
						|
        mountpoint = "/persist/system/jellyfin";
 | 
						|
        options = {
 | 
						|
          atime = "off";
 | 
						|
          relatime = "off";
 | 
						|
          canmount = "on";
 | 
						|
        };
 | 
						|
      };
 | 
						|
    };
 | 
						|
 | 
						|
    assertions = [
 | 
						|
      {
 | 
						|
        assertion = config.services.jellyfin.dataDir == jellyfin_data_directory;
 | 
						|
        message = "jellyfin data directory does not match persistence";
 | 
						|
      }
 | 
						|
      {
 | 
						|
        assertion = config.services.jellyfin.cacheDir == jellyfin_cache_directory;
 | 
						|
        message = "jellyfin cache directory does not match persistence";
 | 
						|
      }
 | 
						|
    ];
 | 
						|
 | 
						|
    environment.persistence = {
 | 
						|
      "/persist/system/root" = {
 | 
						|
        directories = [
 | 
						|
          {
 | 
						|
            directory = jellyfin_data_directory;
 | 
						|
            user = "jellyfin";
 | 
						|
            group = "jellyfin";
 | 
						|
          }
 | 
						|
          {
 | 
						|
            directory = jellyfin_cache_directory;
 | 
						|
            user = "jellyfin";
 | 
						|
            group = "jellyfin";
 | 
						|
          }
 | 
						|
        ];
 | 
						|
      };
 | 
						|
 | 
						|
      "/persist/system/jellyfin" = {
 | 
						|
        enable = true;
 | 
						|
        hideMounts = true;
 | 
						|
        directories = [
 | 
						|
          {
 | 
						|
            directory = config.services.jellyfin.media_directory;
 | 
						|
            user = "jellyfin";
 | 
						|
            group = "jellyfin_media";
 | 
						|
            mode = "1770";
 | 
						|
          }
 | 
						|
        ];
 | 
						|
      };
 | 
						|
    };
 | 
						|
  };
 | 
						|
}
 |