krateng / maloja

Self-hosted music scrobble database to create personal listening statistics and charts
https://maloja.krateng.ch
GNU General Public License v3.0
1.18k stars 69 forks source link

ImportError: cannot import name 'config' from 'doreah' on NixOS #351

Closed gBasil closed 7 months ago

gBasil commented 7 months ago

When trying to run the latest version of Maloja (3.2.2) on NixOS (unstable nixpkgs, updated within the past few hours), I get the following error:

Traceback (most recent call last):
  File "/nix/store/nvrppqjqi94gdx024y6l0s91w8c98lib-malojaserver-3.2.2/bin/.maloja-wrapped", line 6, in <module>
    from maloja.__main__ import main
  File "/nix/store/nvrppqjqi94gdx024y6l0s91w8c98lib-malojaserver-3.2.2/lib/python3.11/site-packages/maloja/__init__.py", line 4, in <module>
    from .pkg_global import conf
  File "/nix/store/nvrppqjqi94gdx024y6l0s91w8c98lib-malojaserver-3.2.2/lib/python3.11/site-packages/maloja/pkg_global/conf.py", line 336, in <module>
    from doreah import config
ImportError: cannot import name 'config' from 'doreah' (/nix/store/xi425vxg5l1hpwwknffsdzsm5wfvjnms-doreah-2.0.1/lib/python3.11/site-packages/doreah/__init__.py)

It builds correctly, but when trying to run it, this error is thrown.

I know Nix isn't officially supported, but this is my configuration, if it's any help:

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

with lib;

let
    nimrodel = pkgs.python311Packages.buildPythonApplication rec {
        pname = "nimrodel";
        version = "0.8.0";
        format = "pyproject";

        src = pkgs.python311Packages.fetchPypi {
            inherit pname version;
            sha256 = "sha256-f9XVuvMXMAgqlDyDsZTF7Afquj9L/0U/4xVsN+VgtW0=";
        };

        checkInputs = with pkgs.python311Packages; [ flit-core ];
        propagatedBuildInputs = with pkgs.python311Packages; [ bottle waitress doreah parse ];

        pythonImportsCheck = [ "nimrodel" ];

        meta = {
            description = "Bottle-wrapper to make python objects accessible via HTTP API";
            homepage = "https://github.com/krateng/nimrodel";
            license = licenses.gpl3;
        };
    };

    doreah = pkgs.python311Packages.buildPythonApplication rec {
        pname = "doreah";
        version = "2.0.1";
        format = "wheel";

        src = pkgs.python311Packages.fetchPypi {
            inherit pname version format;
            dist = "py3";
            python = "py3";
            sha256 = "sha256-iU45e0n+BABVHvQcQKfwkxfypduCdCudUZzKCLF0CHM=";
        };

        propagatedBuildInputs = with pkgs.python311Packages; [ requests pyyaml jinja2 bcrypt ];

        pythonImportsCheck = [ "doreah" ];

        meta = {
            description = "Personal package of helpful utilities";
            homepage = "https://github.com/krateng/doreah";
            license = licenses.gpl3;
        };
    };

    maloja = pkgs.python311Packages.buildPythonApplication rec {
        pname = "malojaserver";
        version = "3.2.2";
        format = "wheel";

        src = pkgs.python311Packages.fetchPypi {
            inherit pname version format;
            dist = "py3";
            python = "py3";
            sha256 = "sha256-kX4M3mHSHgI5zuDmXaRcNju2+pqwOustonnawdUdKEo=";
        };

        propagatedBuildInputs = with pkgs.python311Packages; [
            bottle
            waitress
            doreah
            nimrodel
            jinja2
            lru-dict
            psutil
            sqlalchemy
            datauri
            requests
            setuptools
            toml
            pyyaml
        ];

        meta = {
            description = "Self-hosted music scrobble database to create personal listening statistics and charts";
            homepage    = "https://github.com/krateng/maloja";
            license     = with licenses; [gpl3];
            platforms   = platforms.unix;
        };
    };

    cfg = config.services.maloja;
    ini = pkgs.formats.ini { };
    iniSettings = ini.generate "settings.ini" {
        MALOJA = cfg.settings;
    };
in {
    options = {
        services.maloja = {
            enable = mkEnableOption "maloja";

            settings = mkOption {
                type = with types; attrsOf (oneOf [bool int float string]);
                default = {
                    skip_setup = true;
                    port = 9000;
                };
                example = {
                    port = 9000;
                };
                description = mdDoc ''
                    Configuration for maloja, see
                    <https://github.com/krateng/maloja/blob/master/settings.md>
                    for supported settings.
                '';
            };

            envFile = mkOption {
                type = types.nullOr types.str;
                default = null;
                description = mdDoc ''
                    An optional ENV file that gets loaded into the Maloja service.
                '';
            };
        };
    };

    config = mkIf cfg.enable {
        # Config file
        system.activationScripts.create-maloja = ''
            cp ${iniSettings} /var/lib/maloja/settings.ini
        '';

        # Service
        systemd.services.maloja = {
            wantedBy = [ "multi-user.target" ];
            environment.MALOJA_DATA_DIRECTORY = "/var/lib/maloja";

            serviceConfig = {
                DynamicUser = true;
                StateDirectory = "maloja";
                EnvironmentFile = cfg.envFile;
                ExecStart = "${maloja}/bin/maloja run";
            };
        };
    };
}
gBasil commented 7 months ago

After looking into it, I think this error happens because I was checking the dependencies of the latest commit, instead of for the 3.2.2 tag. Will close this once I update and test.

gBasil commented 7 months ago

Downgrading doreah fixed it.