From c2da1d7b53b14f98712cecaf3b7e920655d06487 Mon Sep 17 00:00:00 2001 From: ajs124 Date: Tue, 9 Mar 2021 13:15:07 -0500 Subject: [PATCH] nixos: iscsi/target: init module Co-authored-by: Graham Christensen --- nixos/modules/module-list.nix | 1 + .../services/networking/iscsi/target.nix | 53 +++++++++++++++++++ 2 files changed, 54 insertions(+) create mode 100644 nixos/modules/services/networking/iscsi/target.nix diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix index eaf046b160f1..e4dc87bb17d9 100644 --- a/nixos/modules/module-list.nix +++ b/nixos/modules/module-list.nix @@ -691,6 +691,7 @@ ./services/networking/iodine.nix ./services/networking/iperf3.nix ./services/networking/ircd-hybrid/default.nix + ./services/networking/iscsi/target.nix ./services/networking/iwd.nix ./services/networking/jicofo.nix ./services/networking/jitsi-videobridge.nix diff --git a/nixos/modules/services/networking/iscsi/target.nix b/nixos/modules/services/networking/iscsi/target.nix new file mode 100644 index 000000000000..8a10e7d346ae --- /dev/null +++ b/nixos/modules/services/networking/iscsi/target.nix @@ -0,0 +1,53 @@ +{ config, lib, pkgs, ... }: + +with lib; + +let + cfg = config.services.target; +in +{ + ###### interface + options = { + services.target = with types; { + enable = mkEnableOption "the kernel's LIO iscsi target"; + + config = mkOption { + type = attrs; + default = {}; + description = '' + Content of /etc/target/saveconfig.json + This file is normally read and written by targetcli + ''; + }; + }; + }; + + ###### implementation + config = mkIf cfg.enable { + environment.etc."target/saveconfig.json" = { + text = builtins.toJSON cfg.config; + mode = "0600"; + }; + + environment.systemPackages = with pkgs; [ targetcli ]; + + boot.kernelModules = [ "configfs" "target_core_mod" "iscsi_target_mod" ]; + + systemd.services.iscsi-target = { + enable = true; + after = [ "network.target" "local-fs.target" ]; + requires = [ "sys-kernel-config.mount" ]; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "oneshot"; + ExecStart = "${pkgs.python3.pkgs.rtslib}/bin/targetctl restore"; + ExecStop = "${pkgs.python3.pkgs.rtslib}/bin/targetctl clear"; + RemainAfterExit = "yes"; + }; + }; + + systemd.tmpfiles.rules = [ + "d /etc/target 0700 root root - -" + ]; + }; +}