at master 1.1 kB view raw
1let 2 # arbitrary address 3 ipAddr = "192.168.42.42"; 4in 5{ lib, ... }: 6{ 7 name = "apcupsd"; 8 meta.maintainers = with lib.maintainers; [ bjornfor ]; 9 10 nodes = { 11 machine = { 12 services.apcupsd = { 13 enable = true; 14 configText = '' 15 UPSTYPE usb 16 BATTERYLEVEL 42 17 # Configure NISIP so that the only way apcaccess can work is to read 18 # this config. 19 NISIP ${ipAddr} 20 ''; 21 }; 22 networking.interfaces.eth1 = { 23 ipv4.addresses = [ 24 { 25 address = ipAddr; 26 prefixLength = 24; 27 } 28 ]; 29 }; 30 }; 31 }; 32 33 # Check that the service starts, that the CLI (apcaccess) works and that it 34 # uses the config (ipAddr) defined in the service config. 35 testScript = '' 36 start_all() 37 machine.wait_for_unit("apcupsd.service") 38 machine.wait_for_open_port(3551, "${ipAddr}") 39 res = machine.succeed("apcaccess") 40 expect_line="MBATTCHG : 42 Percent" 41 assert "MBATTCHG : 42 Percent" in res, f"expected apcaccess output to contain '{expect_line}' but got '{res}'" 42 machine.shutdown() 43 ''; 44}