Documentationcurrent version
Help us improve the docs by fixing typos and proposing enhancements.


Action "file.types.systemd.timesyncd"


Overwrite /usr/lib/systemd/timesyncd.conf.d/10_timesyncd.conf in /mnt to set a list of NTP servers by using an array and a single fallback server by using a string.

const {$status} = await nikita.file.types.systemd.timesyncd({
  target: "/usr/lib/systemd/timesyncd.conf.d/10_timesyncd.conf",
  rootdir: "/mnt",
    NTP: ["", "", ""]
    FallbackNTP: ""
})`File was overwritten: ${$status}`)

Write to the default target file (/etc/systemd/timesyncd.conf). Set a single NTP server using a string and also modify the value of RootDistanceMaxSec. Note: with merge set to true, this wont overwrite the target file, only specified values will be updated.

const {$status} = await nikita.file.types.systemd.timesyncd({
    NTP: ""
    RootDistanceMaxSec: 5
  merge: true
})`File was written: ${$status}`)

Schema definitions

definitions =
    type: 'object'
        type: 'object'
        description: '''
        The configuration object
        type: 'boolean'
        description: '''
        Merge the original content with the provided content.
        type: 'boolean'
        description: '''
        Defaults to true. If set to true the following command will be
        executed `systemctl daemon-reload && systemctl restart
        systemd-timesyncd` after having wrote the configuration file.
        type: 'string'
        description: '''
        Path to the mount point corresponding to the root directory, optional.
        type: 'string'
        default: '/etc/systemd/timesyncd.conf'
        description: '''
        File to write.

This action uses file.ini internally, therefore it honors all arguments it provides. backup is true by default and separator is overridden by "=".


The timesyncd configuration file requires all its fields to be under a single section called "Time". Thus, everything in content will be automatically put under a "Time" key so that the user doesn't have to do it manually.

handler = ({config}) ->
  # Configs = "#{path.join config.rootdir,}" if config.rootdir
  if Array.isArray config.content.NTP
    config.content.NTP = config.content.NTP.join " "
  if Array.isArray config.content.FallbackNTP
    config.content.FallbackNTP = config.content.FallbackNTP.join " "
  # Write configuration
  {$status} = await @file.ini
    separator: "="
    content: 'Time': config.content
    merge: config.merge
  await @execute
    $if: ->
      if config.reload?
      then config.reload
      else $status
    sudo: true
    command: """
    systemctl daemon-reload
    systemctl restart systemd-timesyncd
    trap: true


module.exports =
  handler: handler
    definitions: definitions


path = require 'path'
Edit on GitHub

Nikita is an open source project hosted on GitHub and developed by Adaltas.