How setup iscsi

I couldn’t find satisfying documentation about how to get a iscsi drive running on nixos.

I tried to install open-iscsi and run iscsiadm but this does not work since nixos does not allow changes in /etc/iscsi/ it seems. I am new to nixos.

I have found some mentions about using the configuration.nix file but not how to do that exactly.

thanks in advance.

Ok I figured it out.

you need to enable iscsid in the conf and then you can also add the file system.

configuration.nix:

  services.openiscsi.enable = true;

# probably not needed 
  services.openiscsi.discoverPortal = "ip:3260";
# probably not needed 
  services.openiscsi.name = "iqn.2005-10.org.freenas.ctl:steam-library";

  environment.systemPackages = with pkgs; [
    openiscsi
  ];


  fileSystems."/run/media/user/SteamLibrary" = {
    device = "/dev/disk/by-uuid/uuidasdfasdfasdfasdf";
    fsType = "btrfs";
    options = ["nofail"
               "nofail"
               "auto"
               "users"
               "exec"
               "x-systemd.automount"
    ];
  };

you probably can setup the auto login in the configuration.nix too but I was happy to be able to use the iscsiadm after enableing openiscsi.

source:
https://nixos.org/manual/nixos/stable/options