NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
17.95k stars 13.97k forks source link

dropbox: No module named 'gi' #235345

Open brianmay opened 1 year ago

brianmay commented 1 year ago

Describe the bug

Dropbox fails to install in new 23.05 install.

Steps To Reproduce

$ dropbox start -i
Starting Dropbox...dropbox: locating interpreter
dropbox: logging to /tmp/dropbox-antifreeze-CAYLlO
dropbox: initializing
dropbox: initializing python 3.7.9
dropbox: setting program path '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/dropbox'
dropbox: setting python path '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447:/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/python-packages.zip'
dropbox: python initialized
dropbox: running dropbox
dropbox: setting args
dropbox: enabling allocator metrics
dropbox: applying overrides
dropbox: running main script
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/cryptography.hazmat.bindings._constant_time.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/cryptography.hazmat.bindings._openssl.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/cryptography.hazmat.bindings._padding.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/psutil._psutil_linux.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/psutil._psutil_posix.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/apex._apex.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/tornado.speedups.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/wrapt._wrappers.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/PyQt5.QtWidgets.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/PyQt5.QtCore.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/PyQt5.QtGui.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/PyQt5.QtNetwork.cpython-37m-x86_64-linux-gnu.so'
dropbox: load fq extension '/home/brian/.dropbox-dist/dropbox-lnx.x86_64-111.3.447/PyQt5.QtDBus.cpython-37m-x86_64-linux-gnu.so'

Traceback (most recent call last):
  File "/home/brian/.nix-profile/bin/dropbox", line 1452, in start
    download()
  File "/home/brian/.nix-profile/bin/dropbox", line 294, in download
    import gi
ModuleNotFoundError: No module named 'gi'

Expected behavior

It should start without errors.

Screenshots

As above.

Additional context

This is a new install of nixos 23.05, and dropbox installed using home-manager.

Notify maintainers

@ttuegel

Metadata

Please run nix-shell -p nix-info --run "nix-info -m" and paste the result.

 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.31, NixOS, 23.05 (Stoat), 23.05.20230531.3a70dd9`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.13.3`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos`
peterhoeg commented 1 year ago

This is admittedly off-topic, but unless you absolutely need the actual dropbox client, I cannot strongly enough recommend maestral. Been using that for years as there is a limit to the number of clients you can use with the free plan, but maestral doesn't count against that.

brianmay commented 1 year ago

@peterhoeg Do you by any chance have a sample home-manager config for maestral that will automatically start it in a systemd user based service?

peterhoeg commented 1 year ago

Removing this in favour of the version with syntax highlighting. Not sure why this went through as plain text...

carlthome commented 1 year ago

Backticks for easier skimming:

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

let
  cfg = config.hoeg.programs.dropbox;

  inherit (lib)
    mkEnableOption mkIf mkMerge mkOption types;

  commonServiceConfig = {
    KillMode = "control-group"; # dropbox upstream recommends process
    NotifyAccess = "main";
    Restart = "on-failure";
    PrivateTmp = true;
    ProtectSystem = "strict";
    Nice = 10;
    Slice = "background.slice";
  };

  environment = {
    HOME = "%h";
  };

  wantedBy = [ "graphical-session.target" ];

  ini = pkgs.formats.ini { };

  defaultKeyring = "keyring.backends.kwallet.DBusKeyring";
  # defaultKeyring = "automatic";
  # defaultKeyring = "keyring.backends.SecretService.Keyring";

  maestralIni = ini.generate "maestral-override.ini" {
    app = {
      # if we pass a bool here, it will end up as false which makes maestral blow up
      analytics = "False";
      notification_level = 30; # SYNCISSUE
      update_notification_interval = 0;
    };

    # kwallet has support for SecretService, but it doesn't seem to work
    auth = {
      keyring = defaultKeyring;
    };
  };

  keyringIni = ini.generate "keyringrc.cfg" {
    backend.default-keyring = defaultKeyring;
  };

in
{
  meta.maintainers = with lib.maintainers; [ peterhoeg ];

  options.hoeg.programs.dropbox = {
    enable = mkEnableOption "Dropbox/Maestral";

    preferMaestral = mkOption {
      description = "Prefer maestral";
      type = types.bool;
      default = true;
    };

    runGUI = mkEnableOption "Run GUI tool";

    folderPath = mkOption {
      description = "Path to local dropbox folder";
      type = types.nullOr types.str;
      default = null;
    };
  };

  config = mkIf cfg.enable (mkMerge [
    (mkIf cfg.preferMaestral {
      environment.systemPackages = [
        (pkgs.maestral.overrideAttrs (old: {
          # doCheck = false;
        }))
      ];

      systemd.user.services = {
        maestral = rec {
          description = "Maestral - OpenSource Dropbox client";
          conflicts = [ "dropbox.service" ];
          restartTriggers = [ maestralIni ];
          wants = [ ]; # [ "kwalletd5.service" ];
          # we need kwallet to be running before maestral can fetch the auth
          # token, so we *need* this to be a graphical session
          after = wantedBy ++ wants;
          inherit environment wantedBy;

          unitConfig = {
            ConditionUser = "!@system";
            ConditionPathExists = [
              "%h/.config/maestral/maestral.ini"
              # do not set this here as each machine has its own path and thus sets it itself
            ] ++ lib.optional (cfg.folderPath != null) cfg.folderPath;
          };

          serviceConfig = with pkgs; (
            commonServiceConfig // {
              Type = "notify";
              ExecStartPre = "/bin/sh -c '${pkgs.crudini}/bin/crudini --merge $HOME/.config/maestral/maestral.ini < ${maestralIni}'";
              ExecStart = "${lib.getBin maestral}/bin/maestral start --foreground";
              ExecStop = "${lib.getBin maestral}/bin/maestral stop";
              # ExecStopPost = ''/bin/sh -c "test "$SERVICE_RESULT" != "success" && ${pkgs.libnotify}/bin/notify-send Maestral 'Daemon failed'"'';
              ExecReload = "${lib.getBin coreutils}/bin/kill -HUP $MAINPID";
              EnvironmentFile = "-%t/keys/maestral";
              WatchdogSec = "60s";
              RuntimeDirectory = "maestral";
            }
          );
        };
      };
    })

    (mkIf (! cfg.preferMaestral) {
      networking.firewall = {
        allowedTCPPorts = [ 17500 ];
        allowedUDPPorts = [ 17500 ];
      };

      environment.systemPackages = [ pkgs.dropbox-cli ];

      systemd.user.services.dropbox = rec {
        description = "Dropbox";
        after = wants ++ wantedBy;
        wants = [ "xembed-sni-proxy.service" ];
        conflicts = [ "maestral.service" "maestral-gui.service" ];
        inherit environment wantedBy;

        unitConfig = {
          ConditionPathExists = mkIf (cfg.folderPath != null) cfg.folderPath;
          ConditionUser = "!@system";
        };

        serviceConfig = with pkgs; (
          commonServiceConfig // {
            ExecStart = "${lib.getBin dropbox}/bin/dropbox";
            ExecReload = "${lib.getBin coreutils}/bin/kill -HUP $MAINPID";
          }
        );
      };
    })
  ]);
}
kciredor commented 1 year ago

Hi @eyJhb, I see you are listed as the Dropbox nix package maintainer.

Can confirm that dropbox is broken on latest stable and unstable NixOS.

Would you be willing to take a look? I'm using home-manager which doesn't say anything, but a manual dropbox start -i results in No module named 'gi', which blocks Dropbox from running and syncing.

carlthome commented 1 year ago

Same issue here.

eyJhb commented 1 year ago

Sorry, I no longer use Dropbox. I should most likely remove myself as maintainer :/

AlexChalk commented 1 year ago

It would be great if a maestral user who's configured a working systemd user service to run the daemon could add a code snippet to https://nixos.wiki/wiki/Dropbox :pray:.

amacfie commented 1 year ago

there's this but I haven't tried it myself

AlexChalk commented 1 year ago

I'm also on 23.05 and dropbox (the actual client) is working fine for me. The only change is that dropbox-cli reports 'Dropbox isn't running!' if I call dropbox status, even though I can update files and manually verify the changes have synced. This is my configuration.nix:

  systemd.user.services.dropbox = {
    description = "Dropbox";
    wantedBy = [ "default.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 = "${lib.getBin pkgs.dropbox}/bin/dropbox";
      ExecReload = "${lib.getBin pkgs.coreutils}/bin/kill -HUP $MAINPID";
      KillMode = "control-group";
      Restart = "on-failure";
      PrivateTmp = true;
      ProtectSystem = "full";
      Nice = 10;
    };
  };
❯❯❯ dropbox version
Dropbox daemon version: 178.3.4678
Dropbox command-line interface version: 2020.03.04
❯❯❯ systemctl --user status dropbox.service
● dropbox.service - Dropbox
     Loaded: loaded (/etc/systemd/user/dropbox.service; enabled; preset: enabled)
     Active: active (running) since Wed 2023-07-05 21:55:54 EDT; 4min 48s ago
   Main PID: 2170 (bwrap)
      Tasks: 86 (limit: 9367)
     Memory: 398.3M
        CPU: 10.286s
     CGroup: /user.slice/user-1000.slice/user@1000.service/app.slice/dropbox.service
             ├─2170 /nix/store/hdmv0c9wdjp088y5yyy2mfgbysc7y8h3-bubblewrap-0.8.0/bin/bwrap --dev-bind /dev /dev --proc /proc --chdir /home/me --unshare-user --unshare-ipc --unshare-pid --unshare-uts --unshare-cg>
             ├─2192 /nix/store/hdmv0c9wdjp088y5yyy2mfgbysc7y8h3-bubblewrap-0.8.0/bin/bwrap --dev-bind /dev /dev --proc /proc --chdir /home/me --unshare-user --unshare-ipc --unshare-pid --unshare-uts --unshare-cg>
             └─2195 /home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/dropbox

Jul 05 21:55:54 my-device systemd[2161]: Started Dropbox.
Jul 05 21:55:55 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/cryptography.hazmat.bindings._openssl.abi3.so'
Jul 05 21:55:55 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/cryptography.hazmat.bindings._padding.abi3.so'
Jul 05 21:55:55 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/apex._apex.abi3.so'
Jul 05 21:55:55 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/psutil._psutil_linux.cpython-38-x86_64-linux-gnu.so'
Jul 05 21:55:55 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/psutil._psutil_posix.cpython-38-x86_64-linux-gnu.so'
Jul 05 21:55:56 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/tornado.speedups.cpython-38-x86_64-linux-gnu.so'
Jul 05 21:55:58 my-device dropbox[2195]: dropbox: load fq extension '/home/me/.dropbox-dist/dropbox-lnx.x86_64-178.3.4678/wrapt._wrappers.cpython-38-x86_64-linux-gnu.so'
AlexChalk commented 1 year ago

@amacfie I found a few snippets like that on github, but they seem to store credentials in plaintext by default. I don't think the native dropbox daemon does that?

brianmay commented 1 year ago

I translated the maestral snippet above to work with home manager:

systemd.user.services.maestral = {
    Unit.Description = "Maestral daemon";
    Install.WantedBy = [ "default.target" ];
    Service = {
      ExecStart = "${pkgs.maestral}/bin/maestral start -f";
      ExecStop = "${pkgs.maestral}/bin/maestral stop";
      Restart = "on-failure";
      Nice = 10;
    };
  };

So far seems to work.

I think a built in module that lets you do services.maestral.enable = true; would be better.

@AlexChalk not sure I understand your concern, this doesn't do anything with passwords. Unless you are saying Meastral is insecure in the way it stores the credentials?

brianmay commented 1 year ago

@AlexChalk I note you are not using the home manager module, i.e. dropbox.service.enable = true; - wonder if this is why it works for you...

carlthome commented 1 year ago

On migrating from the official Dropbox client to Maestral I've also been having troubles with needing to reauthenticate often (about weekly?), and not being able to sync files with sizes over 350 GB. Assume these are limitations enforced by Dropbox but might be good to be aware of that the clients don't have feature parity.

kciredor commented 1 year ago

Perhaps Maestral needs it's own Github issue ;-)

I'm not planning on migrating away from the official Dropbox client and currently the official client is broken on stable NixOS.

denibertovic commented 1 year ago

I'm also experiencing this issue right on 23.05 (with home-manager).

SuperSandro2000 commented 2 weeks ago

ModuleNotFoundError: No module named 'gi'

This line https://github.com/NixOS/nixpkgs/blob/master/pkgs/applications/networking/dropbox/cli.nix#L47 is missing at runtime