NixOS / nixpkgs

Nix Packages collection & NixOS
MIT License
16.55k stars 13.04k forks source link

Mealie failing to launch with `PermissionError: [Errno 13] Permission denied: '/run/secrets'` after updating to 1.9.0 #321623

Open poperigby opened 2 weeks ago

poperigby commented 2 weeks ago

Describe the bug

Mealie was updated from 1.7.0 to 1.9.0, and it's now failing to launch, even though I'm using the exact same configuration. It actually seems that just enabling Mealie, with no configuration isn't working. What's weird is that the error is referring to /run/secrets, which is a sops-nix directory. I even rebooted, but it's still getting that particular error

Jun 21 15:18:08 haddock init_db[3231]: PermissionError: [Errno 13] Permission denied: '/run/secrets'
Jun 21 15:18:08 haddock init_db[3231]: The above exception was the direct cause of the following exception:
Jun 21 15:18:08 haddock init_db[3231]: Traceback (most recent call last):
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7xwds1znnwbaici9k55piwap0s8gdpkx-python3.11-mealie-1.9.0/lib/python3.11/site-packages/mealie/db/init_db.py", line 13, in <module>
Jun 21 15:18:08 haddock init_db[3231]:     from mealie.db.db_setup import session_context
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7xwds1znnwbaici9k55piwap0s8gdpkx-python3.11-mealie-1.9.0/lib/python3.11/site-packages/mealie/db/db_setup.py", line 10, in <module>
Jun 21 15:18:08 haddock init_db[3231]:     settings = get_app_settings()
Jun 21 15:18:08 haddock init_db[3231]:                ^^^^^^^^^^^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7xwds1znnwbaici9k55piwap0s8gdpkx-python3.11-mealie-1.9.0/lib/python3.11/site-packages/mealie/core/config.py", line 40, in get_app_settings
Jun 21 15:18:08 haddock init_db[3231]:     return app_settings_constructor(env_file=ENV, production=PRODUCTION, data_dir=determine_data_dir())
Jun 21 15:18:08 haddock init_db[3231]:            ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7xwds1znnwbaici9k55piwap0s8gdpkx-python3.11-mealie-1.9.0/lib/python3.11/site-packages/mealie/core/settings/settings.py", line 254, in app_settings_constructor
Jun 21 15:18:08 haddock init_db[3231]:     app_settings = AppSettings(
Jun 21 15:18:08 haddock init_db[3231]:                    ^^^^^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7pvk1sfzmdcgrb8qikgq2z9vql9y19wm-python3.11-pydantic-settings-2.2.1/lib/python3.11/site-packages/pydantic_settings/main.py", line 85, in __init__
Jun 21 15:18:08 haddock init_db[3231]:     **__pydantic_self__._settings_build_values(
Jun 21 15:18:08 haddock init_db[3231]:       ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7pvk1sfzmdcgrb8qikgq2z9vql9y19wm-python3.11-pydantic-settings-2.2.1/lib/python3.11/site-packages/pydantic_settings/main.py", line 187, in _settings_build_values
Jun 21 15:18:08 haddock init_db[3231]:     return deep_update(*reversed([source() for source in sources]))
Jun 21 15:18:08 haddock init_db[3231]:                                  ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7pvk1sfzmdcgrb8qikgq2z9vql9y19wm-python3.11-pydantic-settings-2.2.1/lib/python3.11/site-packages/pydantic_settings/main.py", line 187, in <listcomp>
Jun 21 15:18:08 haddock init_db[3231]:     return deep_update(*reversed([source() for source in sources]))
Jun 21 15:18:08 haddock init_db[3231]:                                   ^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7pvk1sfzmdcgrb8qikgq2z9vql9y19wm-python3.11-pydantic-settings-2.2.1/lib/python3.11/site-packages/pydantic_settings/sources.py", line 382, in __call__
Jun 21 15:18:08 haddock init_db[3231]:     return super().__call__()
Jun 21 15:18:08 haddock init_db[3231]:            ^^^^^^^^^^^^^^^^^^
Jun 21 15:18:08 haddock init_db[3231]:   File "/nix/store/7pvk1sfzmdcgrb8qikgq2z9vql9y19wm-python3.11-pydantic-settings-2.2.1/lib/python3.11/site-packages/pydantic_settings/sources.py", line 318, in __call__
Jun 21 15:18:08 haddock init_db[3231]:     raise SettingsError(
Jun 21 15:18:08 haddock init_db[3231]: pydantic_settings.sources.SettingsError: error getting value for field "theme" from source "SecretsSettingsSource"

Steps To Reproduce

Use the following configuration:

{ ... }:

{
  services.mealie.enable = true;
}

Expected behavior

Mealie successfully starts.

Additional context

Here's my original Nix configuration:

{ config, lib, ... }:

let
    cfg = config.services.mealie;
in
{
    services = {
        mealie = {
            enable = true;
            credentialsFile = config.sops.templates.mealie-secrets.path;
            settings = {
                ALLOW_SIGNUP = false;
                MAX_WORKERS = 1;
                WEB_CONCURRENCY = 1;
                BASE_URL = "https://food.haddock.cc";
                # Database
                DB_ENGINE = "postgres";
                # https://github.com/mealie-recipes/mealie/issues/3573
                POSTGRES_URL_OVERRIDE = "postgresql://mealie:@localhost/mealie?host=/run/postgresql";
                # OpenID Connect
                OIDC_AUTH_ENABLED = true;
                OIDC_SIGNUP_ENABLED = true;
                OIDC_CONFIGURATION_URL = "https://auth.haddock.cc/.well-known/openid-configuration";
                OIDC_AUTO_REDIRECT = true;
                OIDC_ADMIN_GROUP = "lldap_admin";
            };
        };
        caddy.virtualHosts."food.haddock.cc".extraConfig = ''
            import auth
            reverse_proxy :${builtins.toString cfg.port}
        '';
    };

    systemd.services.mealie = {
        unitConfig = {
            After = [ "authelia-haddock.service" ];
            Requires = [ "authelia-haddock.service" ];
        };
        # DynamicUser messes with sops-nix
        serviceConfig.DynamicUser = lib.mkForce false;
    };

    # Setup a user and group for Mealie
    users = {
        users.mealie = {
            group = "mealie";
            isSystemUser = true;
        };
        groups.mealie = {};
    };

    sops = {
        templates.mealie-secrets = {
            content = ''
                OIDC_CLIENT_ID=${config.sops.placeholder.mealie-oidc-client-id_mealie}
            '';
            owner = "mealie";
        };
        secrets = {
            mealie-oidc-client-id_mealie = {
                key = "haddock/mealie/oidc_client_id";
                owner = "mealie";
            };
            mealie-oidc-client-id_authelia = {
                key = "haddock/mealie/oidc_client_id";
                owner = "authelia-haddock";
            };
        };
    };
}

Notify maintainers

@litchipi @anoadragon453

Metadata

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

 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.33, NixOS, 24.11 (Vicuna), 24.11.20240620.d603719`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.23.0`
 - nixpkgs: `/nix/store/xfpiyfgf6y30fxk5ngv0cjn474qfr3sj-source`

Add a :+1: reaction to issues you find important.

litchipi commented 2 weeks ago

Tested on VM, works fine with the base configuration. The problem comes from the credentialsFile = config.sops.templates.mealie-secrets.path; part of your configuration, it seams that you need the setup the user mealie to get access to the /run/secret directory. I'm not familiar with sops, is there a group you could add the user mealie to so that it can access the directory ?

anoadragon453 commented 2 weeks ago

You can allow a specific user/group access to the decrypted sops secret file using the sops.secrets.<secret name>.{user,group} options.

See this example in my config: https://github.com/anoadragon453/dotfiles/blob/20a1fa7f42f6722db5bba941de762c4df3dc2697/flake.nix#L523

poperigby commented 2 weeks ago

It still doesn't work after doing that.

I wonder if it's some state getting left over that screws something up, because it's weird it would still not work after removing everything but enable = true.

I deleted /var/lib/mealie though, and it's still happening, and it also still works if I role back to 1.7.0.

Although, I am using PostgreSQL so maybe it's something in there? Note that it's happening in init_db.

Here's my updated Nix file:

{ config, lib, ... }:

let
    cfg = config.services.mealie;
in
{
    services = {
        mealie = {
            enable = true;
            credentialsFile = config.sops.templates.mealie-secrets.path;
            settings = {
                ALLOW_SIGNUP = false;
                MAX_WORKERS = 1;
                WEB_CONCURRENCY = 1;
                BASE_URL = "https://food.haddock.cc";
                # Database
                DB_ENGINE = "postgres";
                # https://github.com/mealie-recipes/mealie/issues/3573
                POSTGRES_URL_OVERRIDE = "postgresql://mealie:@localhost/mealie?host=/run/postgresql";
                # OpenID Connect
                OIDC_AUTH_ENABLED = true;
                OIDC_SIGNUP_ENABLED = true;
                OIDC_CONFIGURATION_URL = "https://auth.haddock.cc/.well-known/openid-configuration";
                OIDC_AUTO_REDIRECT = true;
                OIDC_ADMIN_GROUP = "lldap_admin";
            };
        };
        caddy.virtualHosts."food.haddock.cc".extraConfig = ''
            import auth
            reverse_proxy :${builtins.toString cfg.port}
        '';
    };

    systemd.services.mealie = {
        unitConfig = {
            After = [ "authelia-haddock.service" ];
            Requires = [ "authelia-haddock.service" ];
        };
        # DynamicUser messes with sops-nix
        serviceConfig.DynamicUser = lib.mkForce false;
    };

    # Setup a user and group for Mealie
    users = {
        users.mealie = {
            group = "mealie";
            isSystemUser = true;
        };
        groups.mealie = {};
    };

    sops = {
        templates.mealie-secrets = {
            content = ''
                OIDC_CLIENT_ID=${config.sops.placeholder.mealie-oidc-client-id_mealie}
            '';
            owner = "mealie";
            group = "mealie";
        };
        secrets = {
            mealie-oidc-client-id_mealie = {
                key = "haddock/mealie/oidc_client_id";
                owner = "mealie";
                group = "mealie";
            };
            mealie-oidc-client-id_authelia = {
                key = "haddock/mealie/oidc_client_id";
                owner = "authelia-haddock";
                group = "mealie";
            };
        };
    };
}
Birdy2014 commented 2 weeks ago

The issue seems to have something to do with this mealie commit: https://github.com/mealie-recipes/mealie/commit/445754c5d844ccf098f3678bc4f3cc9642bdaad6

Mealie 1.9.0 works when the commit is reverted: https://github.com/Birdy2014/nixos-config/blob/4d9925c230ab7088e913c8e666f8529435db9f6c/hosts/seidenschwanz/services/mealie.nix#L8-L19