1{ config, pkgs, lib, ... }: 2 3with lib; 4 5let 6 cfg = config.services.cadvisor; 7 8in { 9 options = { 10 services.cadvisor = { 11 enable = mkOption { 12 default = false; 13 type = types.bool; 14 description = "Whether to enable cadvisor service."; 15 }; 16 17 listenAddress = mkOption { 18 default = "127.0.0.1"; 19 type = types.str; 20 description = "Cadvisor listening host"; 21 }; 22 23 port = mkOption { 24 default = 8080; 25 type = types.int; 26 description = "Cadvisor listening port"; 27 }; 28 29 storageDriver = mkOption { 30 default = null; 31 type = types.nullOr types.str; 32 example = "influxdb"; 33 description = "Cadvisor storage driver."; 34 }; 35 36 storageDriverHost = mkOption { 37 default = "localhost:8086"; 38 type = types.str; 39 description = "Cadvisor storage driver host."; 40 }; 41 42 storageDriverDb = mkOption { 43 default = "root"; 44 type = types.str; 45 description = "Cadvisord storage driver database name."; 46 }; 47 48 storageDriverUser = mkOption { 49 default = "root"; 50 type = types.str; 51 description = "Cadvisor storage driver username."; 52 }; 53 54 storageDriverPassword = mkOption { 55 default = "root"; 56 type = types.str; 57 description = "Cadvisor storage driver password."; 58 }; 59 60 storageDriverSecure = mkOption { 61 default = false; 62 type = types.bool; 63 description = "Cadvisor storage driver, enable secure communication."; 64 }; 65 }; 66 }; 67 68 config = mkIf cfg.enable { 69 systemd.services.cadvisor = { 70 wantedBy = [ "multi-user.target" ]; 71 after = [ "network.target" "docker.service" "influxdb.service" ]; 72 73 postStart = mkBefore '' 74 until ${pkgs.curl}/bin/curl -s -o /dev/null 'http://${cfg.listenAddress}:${toString cfg.port}/containers/'; do 75 sleep 1; 76 done 77 ''; 78 79 serviceConfig = { 80 ExecStart = ''${pkgs.cadvisor}/bin/cadvisor \ 81 -logtostderr=true \ 82 -listen_ip=${cfg.listenAddress} \ 83 -port=${toString cfg.port} \ 84 ${optionalString (cfg.storageDriver != null) '' 85 -storage_driver ${cfg.storageDriver} \ 86 -storage_driver_user ${cfg.storageDriverHost} \ 87 -storage_driver_db ${cfg.storageDriverDb} \ 88 -storage_driver_user ${cfg.storageDriverUser} \ 89 -storage_driver_password ${cfg.storageDriverPassword} \ 90 ${optionalString cfg.storageDriverSecure "-storage_driver_secure"} 91 ''} 92 ''; 93 }; 94 }; 95 96 virtualisation.docker.enable = mkDefault true; 97 }; 98}