forked from DGNum/liminix
convert ntp to serviceDefn
This commit is contained in:
parent
93e04bb834
commit
2414dd4b55
4 changed files with 49 additions and 52 deletions
|
@ -90,7 +90,7 @@ in rec {
|
||||||
];
|
];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.ntp = svc.ntp {
|
services.ntp = svc.ntp.build {
|
||||||
pools = { "pool.ntp.org" = ["iburst"]; };
|
pools = { "pool.ntp.org" = ["iburst"]; };
|
||||||
makestep = { threshold = 1.0; limit = 3; };
|
makestep = { threshold = 1.0; limit = 3; };
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,14 +1,56 @@
|
||||||
{ lib, pkgs, config, ...}:
|
{ lib, pkgs, config, ...}:
|
||||||
let
|
let
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
|
inherit (pkgs) liminix;
|
||||||
|
serverOpts = types.listOf types.str;
|
||||||
in {
|
in {
|
||||||
options = {
|
options = {
|
||||||
system.service.ntp = mkOption {
|
system.service.ntp = mkOption {
|
||||||
type = types.functionTo types.package;
|
type = liminix.lib.types.serviceDefn;
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
config = {
|
config = {
|
||||||
system.service.ntp = pkgs.callPackage ./service.nix {};
|
system.service.ntp = liminix.callService ./service.nix {
|
||||||
|
user = mkOption {
|
||||||
|
type = types.str;
|
||||||
|
default = "ntp";
|
||||||
|
};
|
||||||
|
servers = mkOption { type = types.attrsOf serverOpts; default = {}; };
|
||||||
|
pools = mkOption { type = types.attrsOf serverOpts; default = {}; };
|
||||||
|
peers = mkOption { type = types.attrsOf serverOpts; default = {}; };
|
||||||
|
makestep = mkOption {
|
||||||
|
default = null;
|
||||||
|
type = types.nullOr
|
||||||
|
(types.submodule {
|
||||||
|
options = {
|
||||||
|
threshold = mkOption { type = types.number; default = null;};
|
||||||
|
limit = mkOption { type = types.number; };
|
||||||
|
};
|
||||||
|
});
|
||||||
|
};
|
||||||
|
allow = mkOption {
|
||||||
|
description = "subnets from which NTP clients are allowed to access the server";
|
||||||
|
type = types.listOf types.str;
|
||||||
|
default = [];
|
||||||
|
};
|
||||||
|
bindaddress = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
binddevice = mkOption {
|
||||||
|
type = types.nullOr types.str;
|
||||||
|
default = null;
|
||||||
|
};
|
||||||
|
dumpdir = mkOption {
|
||||||
|
internal = true;
|
||||||
|
type = types.path;
|
||||||
|
default = "/run/chrony";
|
||||||
|
};
|
||||||
|
extraConfig = mkOption {
|
||||||
|
type = types.lines;
|
||||||
|
default = "";
|
||||||
|
};
|
||||||
|
};
|
||||||
users.ntp = {
|
users.ntp = {
|
||||||
uid = 52; gid= 52; gecos = "Unprivileged NTP user";
|
uid = 52; gid= 52; gecos = "Unprivileged NTP user";
|
||||||
dir = "/run/ntp";
|
dir = "/run/ntp";
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
, lib
|
, lib
|
||||||
, writeText
|
, writeText
|
||||||
}:
|
}:
|
||||||
|
params:
|
||||||
let
|
let
|
||||||
inherit (liminix.services) longrun;
|
inherit (liminix.services) longrun;
|
||||||
inherit (lib) concatStringsSep mapAttrsToList;
|
inherit (lib) concatStringsSep mapAttrsToList;
|
||||||
|
@ -12,50 +13,7 @@ let
|
||||||
inherit (lib) mkOption types;
|
inherit (lib) mkOption types;
|
||||||
|
|
||||||
serverOpts = types.listOf types.str;
|
serverOpts = types.listOf types.str;
|
||||||
t = {
|
|
||||||
user = mkOption {
|
|
||||||
type = types.str;
|
|
||||||
default = "ntp";
|
|
||||||
};
|
|
||||||
servers = mkOption { type = types.attrsOf serverOpts; default = {}; };
|
|
||||||
pools = mkOption { type = types.attrsOf serverOpts; default = {}; };
|
|
||||||
peers = mkOption { type = types.attrsOf serverOpts; default = {}; };
|
|
||||||
makestep = mkOption {
|
|
||||||
default = null;
|
|
||||||
type = types.nullOr
|
|
||||||
(types.submodule {
|
|
||||||
options = {
|
|
||||||
threshold = mkOption { type = types.number; default = null;};
|
|
||||||
limit = mkOption { type = types.number; };
|
|
||||||
};
|
|
||||||
});
|
|
||||||
};
|
|
||||||
allow = mkOption {
|
|
||||||
description = "subnets from which NTP clients are allowed to access the server";
|
|
||||||
type = types.listOf types.str;
|
|
||||||
default = [];
|
|
||||||
};
|
|
||||||
bindaddress = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
binddevice = mkOption {
|
|
||||||
type = types.nullOr types.str;
|
|
||||||
default = null;
|
|
||||||
};
|
|
||||||
dumpdir = mkOption {
|
|
||||||
internal = true;
|
|
||||||
type = types.path;
|
|
||||||
default = "/run/chrony";
|
|
||||||
};
|
|
||||||
extraConfig = mkOption {
|
|
||||||
type = types.lines;
|
|
||||||
default = "";
|
|
||||||
};
|
|
||||||
};
|
|
||||||
configFile = p:
|
configFile = p:
|
||||||
assert (builtins.trace p.makestep true);
|
|
||||||
|
|
||||||
(mapAttrsToList (name: opts: "server ${name} ${concatStringsSep "" opts}")
|
(mapAttrsToList (name: opts: "server ${name} ${concatStringsSep "" opts}")
|
||||||
p.servers)
|
p.servers)
|
||||||
++
|
++
|
||||||
|
@ -71,12 +29,9 @@ let
|
||||||
++ (lib.optional (p.binddevice != null) "binddevice ${p.binddevice}")
|
++ (lib.optional (p.binddevice != null) "binddevice ${p.binddevice}")
|
||||||
++ (lib.optional (p.dumpdir != null) "dumpdir ${p.dumpdir}")
|
++ (lib.optional (p.dumpdir != null) "dumpdir ${p.dumpdir}")
|
||||||
++ [p.extraConfig];
|
++ [p.extraConfig];
|
||||||
in
|
|
||||||
params:
|
|
||||||
let
|
|
||||||
config = writeText "chrony.conf"
|
config = writeText "chrony.conf"
|
||||||
(concatStringsSep "\n"
|
(concatStringsSep "\n" (configFile params));
|
||||||
(configFile (typeChecked "" t params)));
|
|
||||||
in longrun {
|
in longrun {
|
||||||
name = "ntp"; # bad name, needs to be unique
|
name = "ntp"; # bad name, needs to be unique
|
||||||
run = "${chrony}/bin/chronyd -f ${config} -d";
|
run = "${chrony}/bin/chronyd -f ${config} -d";
|
||||||
|
|
|
@ -37,7 +37,7 @@ in rec {
|
||||||
dependencies = [iface];
|
dependencies = [iface];
|
||||||
};
|
};
|
||||||
|
|
||||||
services.ntp = config.system.service.ntp {
|
services.ntp = config.system.service.ntp.build {
|
||||||
pools = { "pool.ntp.org" = ["iburst"] ; };
|
pools = { "pool.ntp.org" = ["iburst"] ; };
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue