Using Dropbox on Nixos

As I’m moving my setup to Nixos, I’m trying to make Dropbox work like on my other computers.

Basically, I’d need Dropbox to start at launch, and integrate with my file manager (which, in my case is Gnome Files, aka Nautilus). There is no Dropbox module that I could find. So the only thing I’ve done so far is adding dropbox to my environment.systemPackages.

This, to be honest, doesn’t work terribly well (I can start dropbox from, say, the command line, but since it doesn’t integrate to my desktop or file manager, I have no way of checking the synchronisation status, and I’m not quite sure this is working properly).

That’s about the state of my knowledge and understanding at this point.

So I’d like to know if the Nixos community has found best practices or neat tricks to make Dropbox pleasant to use on Nixos. I use Gnome, but I’m interested in answers for other setups as well.

1 Like

I use it quite rarely so just run nix run nixpkgs.dropbox -c dropbox in a Terminal whenever needed. If you want Dropbox to start on user login, something like that should work (not tested):

{ pkgs, config }:
{
  systemd.user.services.dropbox = {
    restartIfChanged = true;
    enable = true;
    serviceConfig = {
      ExecStart = "${pkgs.dropbox}/bin/dropbox";
      PassEnvironment = "DISPLAY";
    };
  };
}

Dropbox has been packaged for caja, which is mate’s nautilus. https://github.com/NixOS/nixpkgs/blob/master/pkgs/desktops/mate/caja-dropbox/default.nix

Probably the same thing has been not done yet for nautilus.
The package would be here: GitHub - dropbox/nautilus-dropbox: Dropbox Integration for Nautilus

Brilliant!

This looks almost too easy to be real. But I’ll try to see what I can do with this.

As I am really new to Nixos: could you please give people like me some more information, how you did this?
Would be really kind, since I’m lost how to get my dropbox running on Nixos…

Sure, this is how I use it:

{ config, lib, pkgs, ... }:

{
  environment.systemPackages = with pkgs; [
    # dropbox - we don't need this in the environment. systemd unit pulls it in
    dropbox-cli
  ];

  networking.firewall = {
    allowedTCPPorts = [ 17500 ];
    allowedUDPPorts = [ 17500 ];
  };

  systemd.user.services.dropbox = {
    description = "Dropbox";
    after = [ "xembedsniproxy.service" ];
    wants = [ "xembedsniproxy.service" ];
    wantedBy = [ "graphical-session.target" ];
    environment = {
      QT_PLUGIN_PATH = "/run/current-system/sw/" + pkgs.qt5.qtbase.qtPluginPrefix;
      QML2_IMPORT_PATH = "/run/current-system/sw/" + pkgs.qt5.qtbase.qtQmlPrefix;
    };
    serviceConfig = {
      ExecStart = "${pkgs.dropbox.out}/bin/dropbox";
      ExecReload = "${pkgs.coreutils.out}/bin/kill -HUP $MAINPID";
      KillMode = "control-group"; # upstream recommends process
      Restart = "on-failure";
      PrivateTmp = true;
      ProtectSystem = "full";
      Nice = 10;
    };
  };
}
4 Likes

Let me know if you need any of the parts explained.

Thanks for sharing, i’ve added your code to the nixos wiki: Dropbox - NixOS Wiki

1 Like

Thanks a lot, Peter! I couldn’t hav come up with this for a pretty long time…

And here comes the real newbie follow-up question. I almost hesitate to ask, but let it be:
Dropbox provides .deb and .rpm packages for Linux on their donwload page. Since Nixos works differently - how would I go on with the installation?
Maybe there is some help in the manuals or wiki I’ve not found yet?

@mrtn22 Install the dropbox package after you have enabled unfree packages FAQ - NixOS Wiki. And then start the dropbox command.

1 Like

It’s also possible to install dropbox using flatpak. Not very nixy I guess, but works.

And that’s really the thing - you shouldn’t have to. We need to collectively get a lot better at making things work out of the box. I shouldn’t have sat on this without either updating the nixos module or at the very least document it.

2 Likes

Wow! nix-env -qaP really opened a completely new world to me.
Thanks a lot!

After reading this I tried to set up dropbox as a systemd user service however this seems to hang on the part where it opens firefox (not visible) to register the deamon with dropbox.

So I opened a nix-shell with the deamon and ran it to do the initial configuration in hopes of the systemd service then just using those generated config files. But it seems this is not the case. At least the PID of the deamon is not set in the respective file and the cli tool says that dropbox isn’t running.

So how do you configure the deamon for use with a systemd user service?

It launches firefox for me to do the login with the config above.

Apart from the KDE specific stuff I use a nearly identical config (without the KDE stuff given that I dont use a desktop environment but standalone Xmonad) but it doesn’t open firefox for me (at least not visible anywhere).

   dropbox = {
      description = "Dropbox";
      enable = true;
      serviceConfig = {
        ExecStart = "${pkgs.dropbox.out}/bin/dropbox";
        ExecReload = "${pkgs.coreutils.out}/bin/kill -HUP $MAINPID";
        KillMode = "control-group"; # upstream recommends process
        Restart = "on-failure";
        PrivateTmp = true;
        ProtectSystem = "full";
        Nice = 10;
      };
    };

I also tried to include the passing of the DISPLAY variable proposed by zimbatm above but that didn’t change things.

Given that the dropbox config exists in my home directory my understanding is that the firefox step should be skipped anyway, right?

The dropbox-cli package is actually nautilus-dropbox, see dropbox-cli: Fix and add Nautilus extension by jtojnar · Pull Request #60752 · NixOS/nixpkgs · GitHub

There is also https://github.com/NixOS/nixpkgs/blob/964934097737c1757e26889712333571f23a6343/pkgs/applications/networking/maestral/default.nix which is very nice and lightweight.

We currently have 0.4.2 in unstable with a PR open for 0.4.4 that needs a little work before it can be merged, so I would suggest either waiting for 0.4.4 or at least manually use 0.4.3 as 0.4.2 has some issues.

Would it feasible to have a nixos module for dropbox?

What do these mean in the dropbox service?