at 25.11-pre 1.4 kB view raw
1{ 2 config, 3 lib, 4 pkgs, 5 ... 6}: 7 8with lib; 9 10let 11 cfg = config.services.target; 12in 13{ 14 ###### interface 15 options = { 16 services.target = with types; { 17 enable = mkEnableOption "the kernel's LIO iscsi target"; 18 19 config = mkOption { 20 type = attrs; 21 default = { }; 22 description = '' 23 Content of /etc/target/saveconfig.json 24 This file is normally read and written by targetcli 25 ''; 26 }; 27 }; 28 }; 29 30 ###### implementation 31 config = mkIf cfg.enable { 32 environment.etc."target/saveconfig.json" = { 33 text = builtins.toJSON cfg.config; 34 mode = "0600"; 35 }; 36 37 environment.systemPackages = with pkgs; [ targetcli-fb ]; 38 39 boot.kernelModules = [ 40 "configfs" 41 "target_core_mod" 42 "iscsi_target_mod" 43 ]; 44 45 systemd.services.iscsi-target = { 46 enable = true; 47 after = [ 48 "network.target" 49 "local-fs.target" 50 ]; 51 requires = [ "sys-kernel-config.mount" ]; 52 wantedBy = [ "multi-user.target" ]; 53 serviceConfig = { 54 Type = "oneshot"; 55 ExecStart = "${lib.getExe pkgs.python3Packages.rtslib-fb} restore"; 56 ExecStop = "${lib.getExe pkgs.python3Packages.rtslib-fb} clear"; 57 RemainAfterExit = "yes"; 58 }; 59 }; 60 61 systemd.tmpfiles.rules = [ 62 "d /etc/target 0700 root root - -" 63 ]; 64 }; 65}