1 { config, lib, pkgs, ... }: with lib;
3 cfg = config.services.openiscsi;
6 options.services.openiscsi = with types; {
7 enable = mkEnableOption (lib.mdDoc "the openiscsi iscsi daemon");
8 enableAutoLoginOut = mkEnableOption (lib.mdDoc ''
9 automatic login and logout of all automatic targets.
10 You probably do not want this.
12 discoverPortal = mkOption {
15 description = lib.mdDoc "Portal to discover targets on";
19 description = lib.mdDoc "Name of this iscsi initiator";
20 example = "iqn.2020-08.org.linux-iscsi.initiatorhost:example";
24 description = lib.mdDoc "openiscsi package to use";
25 default = pkgs.openiscsi;
26 defaultText = literalExpression "pkgs.openiscsi";
29 extraConfig = mkOption {
32 description = lib.mdDoc "Lines to append to default iscsid.conf";
35 extraConfigFile = mkOption {
36 description = lib.mdDoc ''
37 Append an additional file's contents to /etc/iscsid.conf. Use a non-store path
38 and store passwords in this file.
45 config = mkIf cfg.enable {
46 environment.etc."iscsi/iscsid.conf.fragment".source = pkgs.runCommand "iscsid.conf" {} ''
47 cat "${cfg.package}/etc/iscsi/iscsid.conf" > $out
50 ${optionalString cfg.enableAutoLoginOut "node.startup = automatic"}
53 environment.etc."iscsi/initiatorname.iscsi".text = "InitiatorName=${cfg.name}";
55 system.activationScripts.iscsid = let
56 extraCfgDumper = optionalString (cfg.extraConfigFile != null) ''
57 if [ -f "${cfg.extraConfigFile}" ]; then
58 printf "\n# The following is from ${cfg.extraConfigFile}:\n"
59 cat "${cfg.extraConfigFile}"
61 echo "Warning: services.openiscsi.extraConfigFile ${cfg.extraConfigFile} does not exist!" >&2
66 cat ${config.environment.etc."iscsi/iscsid.conf.fragment".source}
68 ) > /etc/iscsi/iscsid.conf
71 systemd.packages = [ cfg.package ];
73 systemd.services."iscsid".wantedBy = [ "multi-user.target" ];
74 systemd.sockets."iscsid".wantedBy = [ "sockets.target" ];
76 systemd.services."iscsi" = mkIf cfg.enableAutoLoginOut {
77 wantedBy = [ "remote-fs.target" ];
78 serviceConfig.ExecStartPre = mkIf (cfg.discoverPortal != null) "${cfg.package}/bin/iscsiadm --mode discoverydb --type sendtargets --portal ${escapeShellArg cfg.discoverPortal} --discover";
81 environment.systemPackages = [ cfg.package ];
82 boot.kernelModules = [ "iscsi_tcp" ];