diff --git a/ioc/modules/nixos-integration.nix b/ioc/modules/nixos-integration.nix index 871c368..8669242 100644 --- a/ioc/modules/nixos-integration.nix +++ b/ioc/modules/nixos-integration.nix @@ -5,96 +5,115 @@ pkgs, ... }: let - cfg = config.epnix.nixos; + globalConfig = config; iocTop = "${config.epnix.outputs.build}"; in { options.epnix.nixos = { - service = { - app = lib.mkOption { - type = lib.types.str; - example = "my_exec"; - description = '' - Name of the app to start the IOC with. - ''; + services = lib.mkOption { + description = '' + Services for which to create a systemd service config. + ''; + example = { + ioc = { + app = "examples"; + ioc = "iocExamples"; + }; }; + type = lib.types.attrsOf (lib.types.submodule ({config, ...}: { + options = { + app = lib.mkOption { + type = lib.types.str; + example = "my_exec"; + description = '' + Name of the app to start the IOC with. + ''; + }; - ioc = lib.mkOption { - type = lib.types.str; - example = "iocMyDevice"; - description = '' - Name of the directory under `iocBoot` containing the start commands. - ''; - }; + ioc = lib.mkOption { + type = lib.types.str; + example = "iocMyDevice"; + description = '' + Name of the directory under `iocBoot` containing the start commands. + ''; + }; - startCommandsFile = lib.mkOption { - default = "st.cmd"; - example = "other_st.cmd"; - type = lib.types.str; - description = '' - Name of the file containing the EPICS start commands. - ''; - }; + startCommandsFile = lib.mkOption { + default = "st.cmd"; + example = "other_st.cmd"; + type = lib.types.str; + description = '' + Name of the file containing the EPICS start commands. + ''; + }; - config = lib.mkOption { - type = lib.types.attrs; - readOnly = true; - description = '' - Resulting configuration for the systemd service. - ''; - }; + config = lib.mkOption { + type = lib.types.attrs; + readOnly = true; + description = '' + Resulting configuration for the systemd service. + ''; + }; - procServ = { - port = lib.mkOption { - default = 2000; - type = lib.types.port; - description = '' - Port where the procServ utility will listen. - ''; - }; + procServ = { + port = lib.mkOption { + default = 2000; + type = lib.types.port; + description = '' + Port where the procServ utility will listen. + ''; + }; - options = lib.mkOption { - default = {}; - example = { - allow = true; - info-file = "/var/run/ioc/procServ_info"; + options = lib.mkOption { + default = {}; + example = { + allow = true; + info-file = "/var/run/ioc/procServ_info"; + }; + type = with lib.types; attrsOf (oneOf [str int bool (listOf str)]); + description = '' + Extra command-line options to pass to procServ. + + Note: using `lib.mkForce` will override the default options needed + for the systemd service to work. If you wish to do this, you will + need to specify needed arguments like `foreground` and `chdir`. + ''; + }; }; - type = with lib.types; attrsOf (oneOf [str int bool (listOf str)]); - description = '' - Extra command-line options to pass to procServ. + }; - Note: using `lib.mkForce` will override the default options needed - for the systemd service to work. If you wish to do this, you will - need to specify needed arguments like `foreground` and `chdir`. - ''; + config.procServ.options = { + foreground = true; + oneshot = true; + logfile = "-"; + holdoff = 0; + chdir = "${iocTop}/iocBoot/${config.ioc}"; }; - }; - }; - }; - config.epnix.nixos.service.procServ.options = { - foreground = true; - oneshot = true; - logfile = "-"; - chdir = "${iocTop}/iocBoot/${cfg.service.ioc}"; - }; + config.config = { + wantedBy = ["multi-user.target"]; - config.epnix.nixos.service.config = { - wantedBy = ["multi-user.target"]; - after = ["network.target"]; + # When initializing the IOC, PV Access looks for network interfaces that + # have IP addresses. "network.target" may be too early, especially for + # systems with DHCP. + wants = ["network-online.target"]; + after = ["network-online.target"]; - description = "EPICS IOC ${config.epnix.meta.name}"; + description = "EPICS IOC ${globalConfig.epnix.meta.name}"; - serviceConfig = { - ExecStart = let - procServ = "${pkgs.epnix.procServ}/bin/procServ"; - arch = epnix.lib.toEpicsArch config.epnix.outputs.build.stdenv.hostPlatform; - in '' - ${procServ} ${lib.cli.toGNUCommandLineShell {} cfg.service.procServ.options} \ - ${toString cfg.service.procServ.port} \ - ${iocTop}/bin/${arch}/${cfg.service.app} ${cfg.service.startCommandsFile} - ''; - Restart = "on-failure"; + serviceConfig = { + ExecStart = let + procServ = "${pkgs.epnix.procServ}/bin/procServ"; + arch = epnix.lib.toEpicsArch globalConfig.epnix.outputs.build.stdenv.hostPlatform; + in '' + ${procServ} ${lib.cli.toGNUCommandLineShell {} config.procServ.options} \ + ${toString config.procServ.port} \ + ${iocTop}/bin/${arch}/${config.app} ${config.startCommandsFile} + ''; + Restart = "on-failure"; + }; + }; + })); }; }; } diff --git a/ioc/tests/support/StreamDevice/simple/default.nix b/ioc/tests/support/StreamDevice/simple/default.nix index 92bb744..dc2ddcc 100644 --- a/ioc/tests/support/StreamDevice/simple/default.nix +++ b/ioc/tests/support/StreamDevice/simple/default.nix @@ -11,7 +11,7 @@ epnixConfig.imports = [./top/epnix.nix]; }; - service = result.config.epnix.nixos.service.config; + service = result.config.epnix.nixos.services.ioc.config; ioc = result.outputs.build; in diff --git a/ioc/tests/support/StreamDevice/simple/top/epnix.nix b/ioc/tests/support/StreamDevice/simple/top/epnix.nix index e5b948f..565a1dd 100644 --- a/ioc/tests/support/StreamDevice/simple/top/epnix.nix +++ b/ioc/tests/support/StreamDevice/simple/top/epnix.nix @@ -5,7 +5,9 @@ support.modules = with pkgs.epnix.support; [StreamDevice epics-systemd]; - nixos.service.app = "simple"; - nixos.service.ioc = "iocsimple"; + nixos.services.ioc = { + app = "simple"; + ioc = "iocsimple"; + }; }; } diff --git a/ioc/tests/support/autosave/simple/autosaveSimpleTestTop/epnix.nix b/ioc/tests/support/autosave/simple/autosaveSimpleTestTop/epnix.nix index 0244c6c..88ef485 100644 --- a/ioc/tests/support/autosave/simple/autosaveSimpleTestTop/epnix.nix +++ b/ioc/tests/support/autosave/simple/autosaveSimpleTestTop/epnix.nix @@ -5,7 +5,9 @@ support.modules = with pkgs.epnix.support; [autosave]; - nixos.service.app = "simple"; - nixos.service.ioc = "iocSimple"; + nixos.services.ioc = { + app = "simple"; + ioc = "iocSimple"; + }; }; } diff --git a/ioc/tests/support/autosave/simple/default.nix b/ioc/tests/support/autosave/simple/default.nix index 3a901c9..286baaa 100644 --- a/ioc/tests/support/autosave/simple/default.nix +++ b/ioc/tests/support/autosave/simple/default.nix @@ -7,7 +7,7 @@ epnixConfig.imports = [./autosaveSimpleTestTop/epnix.nix]; }; - service = result.config.epnix.nixos.service.config; + service = result.config.epnix.nixos.services.ioc.config; ioc = result.outputs.build; in diff --git a/ioc/tests/support/seq/simple/default.nix b/ioc/tests/support/seq/simple/default.nix index ec7d2bd..f9eaa28 100644 --- a/ioc/tests/support/seq/simple/default.nix +++ b/ioc/tests/support/seq/simple/default.nix @@ -7,7 +7,7 @@ epnixConfig.imports = [./top/epnix.nix]; }; - service = result.config.epnix.nixos.service.config; + service = result.config.epnix.nixos.services.ioc.config; ioc = result.outputs.build; in diff --git a/ioc/tests/support/seq/simple/top/epnix.nix b/ioc/tests/support/seq/simple/top/epnix.nix index a7b8cd0..1b5bfb2 100644 --- a/ioc/tests/support/seq/simple/top/epnix.nix +++ b/ioc/tests/support/seq/simple/top/epnix.nix @@ -5,7 +5,9 @@ support.modules = with pkgs.epnix.support; [seq]; - nixos.service.app = "simple"; - nixos.service.ioc = "iocsimple"; + nixos.services.ioc = { + app = "simple"; + ioc = "iocsimple"; + }; }; }