{"record":{"id":"f39c1b183a46229a","repo":"pkgxdev/pkgx","slug":"could-not-determine-cache-directory","errorCode":null,"errorMessage":"Could not determine cache directory","messagePattern":"Could not determine cache directory","errorType":"error_code","errorClass":"io::Error (NotFound)","httpStatus":null,"severity":"error","filePath":"crates/lib/src/config.rs","lineNumber":57,"sourceCode":"        if path.is_absolute() {\n            Some(path)\n        } else if let Ok(cwd) = env::current_dir() {\n            Some(cwd.join(path))\n        } else {\n            None\n        }\n    } else {\n        None\n    }\n}\n\nfn get_pantry_dir() -> io::Result<PathBuf> {\n    if let Some(path) = get_PKGX_PANTRY_DIR() {\n        Ok(path)\n    } else if let Some(path) = dirs_next::data_local_dir() {\n        Ok(path.join(\"pkgx/pantry\"))\n    } else {\n        Err(io::Error::new(\n            io::ErrorKind::NotFound,\n            \"Could not determine cache directory\",\n        ))\n    }\n}\n\nfn get_pkgx_dir() -> io::Result<PathBuf> {\n    if let Ok(path) = env::var(\"PKGX_DIR\") {\n        let path = PathBuf::from(path);\n        if path.is_absolute() {\n            return Ok(path);\n        }\n    }\n\n    // Use sudoer home directory if it is set.\n    if let Ok(path) = env::var(\"SUDO_HOME\") {\n        let path = PathBuf::from(path).join(\".pkgx\");\n        if path.is_absolute() {","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/pkgxdev/pkgx/blob/6de1d7e953b98061f69db95d4bd45a2a6ee5d7da/crates/lib/src/config.rs#L39-L75","documentation":"`Config::new` resolves the pantry directory: `PKGX_PANTRY_DIR` env var first, else the OS local-data directory (`dirs_next::data_local_dir()`). If neither is available — no env var set and the platform provides no local data dir (rare; typically headless/service contexts where HOME is unset) — it returns a NotFound io::Error 'Could not determine cache directory'. Config construction then fails for every downstream operation.","triggerScenarios":"Creating `Config::new()` on a system where `dirs_next::data_local_dir()` returns None (XDG_DATA_HOME unset and no resolvable home dir, e.g. systemd service with empty environment, cron job, container running as a user without /etc/passwd entry) and PKGX_PANTRY_DIR is not set.","commonSituations":"Running pkgx from a daemon/cron with no HOME, Docker containers with a minimal environment, CI steps that scrub environment variables, or users on unusual platforms where the dirs crate has no data-local-dir mapping.","solutions":["Set PKGX_PANTRY_DIR to an absolute path (e.g. export PKGX_PANTRY_DIR=$HOME/.pkgx/pantry)","Set HOME (or XDG_DATA_HOME) so dirs_next::data_local_dir() can resolve — e.g. in the systemd unit or Dockerfile set ENV HOME=/root","Run pkgx as a user with a valid passwd/home entry instead of a bare service account"],"exampleFix":"// before (systemd unit)\n[Service]\nExecStart=/usr/local/bin/pkgx install deno.land\n// after\n[Service]\nEnvironment=HOME=/root\nEnvironment=PKGX_PANTRY_DIR=/var/lib/pkgx/pantry\nExecStart=/usr/local/bin/pkgx install deno.land","handlingStrategy":"fallback","validationCode":"fn pantry_dir_resolvable() -> bool {\n    std::env::var(\"PKGX_PANTRY_DIR\").is_ok()\n        || dirs_next::data_local_dir().is_some()\n}","typeGuard":null,"tryCatchPattern":"match Config::new() {\n    Err(e) if e.to_string() == \"Could not determine cache directory\" => {\n        std::env::set_var(\"PKGX_PANTRY_DIR\", \"/var/lib/pkgx/pantry\");\n        Config::new()? // retry with explicit dir\n    }\n    other => other,\n}","preventionTips":["In daemons/cron/containers, always set HOME or XDG_DATA_HOME","Prefer setting PKGX_PANTRY_DIR explicitly in service units and Dockerfiles","Check environment of the executing user (systemd scrubbing, CI sanitizers)","Run services as a user with a valid passwd home entry"],"tags":["config","environment","xdg","directory"],"backgroundTag":"missing-env-var","analyzedSha":"6de1d7e953b98061f69db95d4bd45a2a6ee5d7da","analyzedAt":"2026-09-10T09:59:03.886Z","contentChangedAt":"2026-09-10T09:59:03.886Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}