Using Dropbox on Nixos


#1

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.


#2

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";
    };
  };
}

#3

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: https://github.com/dropbox/nautilus-dropbox


#4

Brilliant!

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


#5

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…


#6

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;
    };
  };
}

#7

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


#8

Thanks for sharing, i’ve added your code to the nixos wiki: https://nixos.wiki/wiki/Dropbox


#9

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?


#10

@mrtn22 Install the dropbox package after you have enabled unfree packages https://nixos.wiki/wiki/FAQ#How_can_I_install_a_proprietary_or_unfree_package.3F. And then start the dropbox command.


#11

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


#12

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.


#13

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


#14

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?


#15

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


#16

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?