liminix

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README | LICENSE

service.nix (1309B)


      1 {
      2   liminix,
      3   chrony,
      4   lib,
      5   writeText,
      6 }:
      7 params:
      8 let
      9   name = "ntp"; # bad name, needs to be unique
     10   inherit (liminix.services) longrun;
     11   inherit (lib) concatStringsSep mapAttrsToList;
     12   configFile =
     13     p:
     14     (mapAttrsToList (name: opts: "server ${name} ${concatStringsSep "" opts}") p.servers)
     15     ++ (mapAttrsToList (name: opts: "pool ${name} ${concatStringsSep "" opts}") p.pools)
     16     ++ (mapAttrsToList (name: opts: "peer ${name} ${concatStringsSep "" opts}") p.peers)
     17     ++ lib.optional (p.user != "root") "user ${p.user}"
     18     ++ (lib.optional (
     19       p.makestep != null
     20     ) "makestep ${toString p.makestep.threshold} ${toString p.makestep.limit}")
     21     ++ (map (n: "allow ${n}") p.allow)
     22     ++ (lib.optional (p.bindaddress != null) "bindaddress ${p.bindaddress}")
     23     ++ (lib.optional (p.binddevice != null) "binddevice ${p.binddevice}")
     24     ++ (lib.optional (p.dumpdir != null) "dumpdir ${p.dumpdir}")
     25     ++ [
     26       "bindcmdaddress /" # disable unix socket
     27       "pidfile /run/${name}.pid"
     28     ]
     29     ++ [ p.extraConfig ];
     30 
     31   config = writeText "chrony.conf" (concatStringsSep "\n" (configFile params));
     32 in
     33 longrun {
     34   inherit name;
     35   notification-fd = 10;
     36   run = ''
     37     ( ${chrony}/bin/chronyc waitsync ; echo > /proc/self/fd/10 ) &
     38     exec ${chrony}/bin/chronyd -f ${config} -d
     39   '';
     40 }