Notes Setting Up on Syncthing in NixOS

Table of Contents

So I recently got around to trying out NixOS. Part of that experience was setting up Syncthing, which I’ve used on the past on my machines and mobile phone to sync files related to note-taking.1

1 I use Emacs’s org-agenda to manage todos, and I’ve set up Orgzly Revived for basic creation and editing of org todos on my phone. 

It was a bit confusing since I had to fill-in-the-blanks for a few steps. Here, I write about a bit of the blanks I had to fill in myself, stuff that was not clear from the existing docs and forum posts I discovered.

The configuration

Below is the final NixOS configuration I have (with IDs elided for privacy) alongside commentary via comments:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
systemd.services.syncthing.environment.STNODEFAULTFOLDER = "true"; # Don't create default ~/Sync folder.  See https://wiki.nixos.org/wiki/Syncthing
services.syncthing = {
  enable = true;
  openDefaultPorts = true;
  # I change the address SyncThing uses (which is also how you access the
  # browser UI).  This is to avoid conflicts with the other SyncThing instances
  # I have on the same machine.  Namely, from different WSL2 instances.
  guiAddress = "127.0.0.1:8385";
  user = "krisbalintona";
  group = "users";
  configDir = "/home/krisbalintona/.config/syncthing";
  # Override all settings set from the GUI.  This is necessary if I don't want
  # to have changes made from the GUI apply.
  overrideDevices = true;
  overrideFolders = true;
  # Settings: this is where you set up devices and folders
  settings = {
    devices = {
      "G14 2024 Arch" = {       # Name of SyncThing instance on other machine
        id = "OQHSZRL-L2TT7IC-7USSLNU-ST7JYML-FOO-BAR"; # Elided for privacy
      };
      "OnePlus 7 Pro" = {       # Name of SyncThing instance on mobile device
        id = "OVGYOBT-JPFQJKE-6CKRY7J-JULRCWK-FOO-BAR"; # Elided for privacy
      };
    };

    folders = {
      "k4vqh-foo" = {           # The ID of a folder you'd like to sync
        label = "Agenda";       # Optional device-specific folder name
        path = "/home/krisbalintona/Documents/org-database/agenda/";
        # Share with these devices
        devices = [
          "G14 2024 Arch WSL2"
          "OnePlus 7 Pro"
        ];
      };
      "qtuzy-foo" = {           # The ID of a folder you'd like to sync
        label = "Notes";        # Optional device-specific folder name
        path = "/home/krisbalintona/Documents/org-database/notes";
        # Share with these devices
        devices = [
          "G14 2024 Arch"
          "OnePlus 7 Pro"
        ];
      };
    };
  };
};

It was pretty straightforward to figure out the general settings for Syncthing by referencing NixOS Search. The tricky part was the “devices” and “folders” section. What should I put there? Below are the important bits.

Devices

  • “Devices” are Machines/devices you’d like Syncthing to be aware of.
  • Each machine has an ID.
  • Each machine can optionally have a “label” (probably a human-readable name, like “Home computer”).

Looking at the relevant portion of my configuration:

1
2
3
4
5
6
7
8
devices = {
  "G14 2024 Arch" = {  # Name of SyncThing instance on other machine
    id = "OQHSZRL-L2TT7IC-7USSLNU-ST7JYML-FOO-BAR"; # Elided for privacy
  };
  "OnePlus 7 Pro" = {       # Name of SyncThing instance on mobile device
    id = "OVGYOBT-JPFQJKE-6CKRY7J-JULRCWK-FOO-BAR"; # Elided for privacy
  };
};

This tells Syncthing that I have two devices:

  1. One labeled “G14 2024 Arch” with an ID of "OQHSZRL-L2TT7IC-7USSLNU-ST7JYML-FOO-BAR".
  2. Another labeled “OnePlus 7 Pro” with an ID of "OVGYOBT-JPFQJKE-6CKRY7J-JULRCWK-FOO-BAR".

Now that Syncthing is aware of these devices, I can reference them by their label later in the folders section to specify which folders should be shared to which devices.

Folders

  • Folders are the directories you’d like Syncthing to be aware of.
  • Each folder has an ID.2

    2 You can see the ID of shared folders in the Syncthing GUI by expanding the collapsed info section a folder under the folders section of the GUI’s homepage. 

  • Each folder may optionally have a label (probably a human-readable name, like “Agenda”). This is basically a nickname you give to the folder specific to the current device.
  • Folders are only shared to devices specified for each folder.

Looking at the relevant portion of my configuration:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
folders = {
  "k4vqh-foo" = {               # The ID of a folder you'd like to sync
    label = "Agenda";           # Optional device-specific folder name
    path = "/home/krisbalintona/Documents/org-database/agenda/";
    # Share with these devices
    devices = [
      "G14 2024 Arch WSL2"
      "OnePlus 7 Pro"
    ];
  };
  "qtuzy-foo" = {               # The ID of a folder you'd like to sync
    label = "Notes";            # Optional device-specific folder name
    path = "/home/krisbalintona/Documents/org-database/notes";
    # Share with these devices
    devices = [
      "G14 2024 Arch"
      "OnePlus 7 Pro"
    ];
  };
};

This tells Syncthing that I want to share two folders:

  1. Share folder "k4vqh-foo", whose label is “Agenda,” with two devices: the one labeled “G14 2024 Arch WSL2” and another labeled “OnePlus 7 Pro.”
  2. Share folder "qtuzy-foo", whose label is “Notes,” with two devices: the one labeled “G14 2024 Arch WSL2” and another labeled “OnePlus 7 Pro.”

It is important that the “devices” section be specified, otherwise Syncthing will not sync those folders to other devices.

Closing remarks

And with that, I was done!

In sum:

  • Devices
    • “Devices” are Machines/devices you’d like Syncthing to be aware of.
    • Each machine has an ID.
    • Each machine can optionally have a “label” (probably a human-readable name, like “Home computer”).
  • Folders
    • Folders are the directories you’d like Syncthing to be aware of.
    • Each folder has an ID.
    • Each folder may optionally have a label (probably a human-readable name, like “Agenda”). This is basically a nickname you give to the folder specific to the current device.
    • Folders are only shared to devices specified for each folder.

Simple, but it wasn’t obvious from the resources I encountered online, so I had to do some tinkering to figure it out myself.

For those who heavily customize Syncthing, there are other NixOS options available to tweak. You can find them in the NixOS Search for options. Additionally, if you are trying to migrate an existing Syncthing configuration to Nix, then you can check out your config file at ~/.config/syncthing/config.xml. With this, you can see the value of every Syncthing setting (although the file will, of course, be in JSON format).

Other resources

Syncthing - NixOS Wiki
General resource; good starting point.
Vimjoyer - YouTube
A fantastic visual resource of making full use of Nix and NixOS. Has some beginner-friendly videos, but most videos are for intermediate or advanced users, ones looking to explore the ecosystem, full potential of Nix, and already having a familiarity with navigating Nix.