liminix

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

service.nix (1220B)


      1 {
      2   liminix
      3 , chrony
      4 , serviceFns
      5 , lib
      6 , writeText
      7 }:
      8 params:
      9 let
     10   inherit (liminix.services) longrun;
     11   inherit (lib) concatStringsSep mapAttrsToList;
     12   inherit (liminix.lib) typeChecked;
     13   inherit (lib) mkOption types;
     14 
     15   serverOpts = types.listOf types.str;
     16   configFile = p:
     17     (mapAttrsToList (name: opts: "server ${name} ${concatStringsSep "" opts}")
     18       p.servers)
     19     ++
     20     (mapAttrsToList (name: opts: "pool ${name} ${concatStringsSep "" opts}")
     21       p.pools)
     22     ++
     23     (mapAttrsToList (name: opts: "peer ${name} ${concatStringsSep "" opts}")
     24       p.peers)
     25     ++ lib.optional (p.user != null) "user ${p.user}"
     26     ++ (lib.optional (p.makestep != null) "makestep ${toString p.makestep.threshold} ${toString p.makestep.limit}")
     27     ++ (map (n: "allow ${n}") p.allow)
     28     ++ (lib.optional (p.bindaddress != null) "bindaddress ${p.bindaddress}")
     29     ++ (lib.optional (p.binddevice != null) "binddevice ${p.binddevice}")
     30     ++ (lib.optional (p.dumpdir != null) "dumpdir ${p.dumpdir}")
     31     ++ [p.extraConfig];
     32 
     33   config = writeText "chrony.conf"
     34     (concatStringsSep "\n" (configFile params));
     35 in longrun {
     36   name = "ntp"; # bad name, needs to be unique
     37   run = "${chrony}/bin/chronyd -f ${config} -d";
     38 }