-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Showing
5 changed files
with
117 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,85 @@ | ||
{ | ||
config, | ||
epnixLib, | ||
lib, | ||
pkgs, | ||
... | ||
}: let | ||
cfg = config.services.phoebus-scan-server; | ||
buildConfig = settings: with lib; concatLines (mapAttrsToList (k: v: "<${k}>${builtins.toString v}</${k}>") settings); | ||
mainConfig = buildConfig cfg.settings; | ||
pvConfig = with lib; concatLines (map (pv: "<pv>${buildConfig pv}</pv>") cfg.pvs); | ||
|
||
rawConfigFile = pkgs.writeText "scan_config_raw.xml" '' | ||
<?xml version="1.0"?> | ||
<!-- Generated by NixOS/EPNix (services.phoebus-scan-server) --> | ||
<scan_config> | ||
<!-- Set by services.phoebus-scan-server.settings: --> | ||
${mainConfig} | ||
<!-- Set by services.phoebus-scan-server.pvs: --> | ||
${pvConfig} | ||
</scan_config> | ||
''; | ||
|
||
configFile = pkgs.runCommand "scan_config.xml" {nativeBuildInputs = [pkgs.libxml2];} '' | ||
xmllint --format ${rawConfigFile} > $out | ||
''; | ||
in { | ||
options.services.phoebus-scan-server = { | ||
enable = lib.mkEnableOption "the Phoebus scan server"; | ||
|
||
settings = lib.mkOption { | ||
description = '' | ||
Configuration for Phoebus scan server | ||
Will be converted to an XML file | ||
PVs are not specified here but in services.phoebus-scan-server.pvs | ||
''; | ||
|
||
default = {}; | ||
type = lib.types.submodule { | ||
freeformType = with lib.types; attrsOf (oneOf [str int]); | ||
|
||
options.port = lib.mkOption { | ||
type = lib.types.port; | ||
|
||
default = 4810; | ||
}; | ||
}; | ||
}; | ||
|
||
pvs = lib.mkOption { | ||
default = []; | ||
type = lib.types.listOf (lib.types.submodule { | ||
freeformType = with lib.types; attrsOf str; | ||
}); | ||
}; | ||
|
||
openFirewall = lib.mkOption { | ||
description = '' | ||
Open the firewall for the Phoebus Scan Server. | ||
Warning: this opens the firewall on all network interfaces. | ||
''; | ||
type = lib.types.bool; | ||
default = false; | ||
}; | ||
}; | ||
|
||
config = lib.mkIf cfg.enable { | ||
systemd.services.phoebus-scan-server = { | ||
description = "Phoebus Scan Server"; | ||
|
||
wantedBy = ["multi-user.target"]; | ||
|
||
serviceConfig = { | ||
ExecStart = "${lib.getExe pkgs.epnix.phoebus-scan-server} -config ${configFile} -noshell"; | ||
}; | ||
}; | ||
|
||
networking.firewall.allowedTCPPorts = lib.mkIf cfg.openFirewall [cfg.settings.port]; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
{ | ||
lib, | ||
epnixLib, | ||
... | ||
}: { | ||
name = "phoebus-scan-server-simple-check"; | ||
meta.maintainers = with epnixLib.maintainers; [synthetica]; | ||
|
||
nodes = { | ||
server = { | ||
services.phoebus-scan-server = { | ||
enable = true; | ||
openFirewall = true; | ||
}; | ||
}; | ||
|
||
client = {}; | ||
}; | ||
|
||
testScript = '' | ||
start_all() | ||
server.wait_for_unit('phoebus-scan-server.service') | ||
print(server.succeed('systemctl status phoebus-scan-server')) | ||
server.wait_for_open_port(4810) | ||
info = client.succeed('curl http://server:4810/server/info') | ||
print('Server claims following info:') | ||
print(info) | ||
''; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters