Skip to content

fix(linux): use home cache dir to avoid tmpfs→ext4 EINVAL on SDK install#211

Merged
kabiroberai merged 3 commits into
xtool-org:mainfrom
swapnilnakate7:fix/linux-mint-tmpfs-sdk-install
Apr 18, 2026
Merged

fix(linux): use home cache dir to avoid tmpfs→ext4 EINVAL on SDK install#211
kabiroberai merged 3 commits into
xtool-org:mainfrom
swapnilnakate7:fix/linux-mint-tmpfs-sdk-install

Conversation

@swapnilnakate7
Copy link
Copy Markdown
Contributor

Problem

xtool setup fails on Linux Mint (and other distros) with:

Error: Error Domain=NSCocoaErrorDomain Code=512 "(null)" UserInfo={
  NSUserStringVariant=["Copy"],
  NSSourceFilePathErrorKey=/tmp/sh.xtool/tmp-DarwinSDKBuild-.../darwin.artifactbundle/...,
  NSDestinationFilePath=/home/<user>/.swiftpm/swift-sdks/darwin.artifactbundle/...,
  NSUnderlyingError=Error Domain=NSPOSIXErrorDomain Code=22 "Invalid argument"
}

Root Cause

On Linux Mint (and Ubuntu-based distros), /tmp is mounted as tmpfs while the home directory is on ext4. Foundation's FileManager.copyItem uses sendfile(2) internally, which returns EINVAL (22) when copying between different filesystem types.

TemporaryDirectoryRoot defaults to FileManager.default.temporaryDirectory/tmp on Linux. When swift sdk install copies the built SDK from /tmp/sh.xtool/... to ~/.swiftpm/swift-sdks/, it crosses filesystem boundaries and fails.

Fix

On Linux, default the temp directory root to $XDG_CACHE_HOME/xtool (falling back to ~/.cache/xtool) instead of /tmp. This keeps the build directory and install destination on the same filesystem, so the copy always succeeds.

  • $XTL_TMPDIR and $TMPDIR overrides continue to work as before
  • macOS behaviour is unchanged
  • Follows XDG Base Directory Specification

Changes

One file, Sources/XUtils/TemporaryDirectory.swift — 11 lines added inside a #if os(Linux) block.

Fixes #181

On Linux systems where /tmp is a tmpfs mount (common on Ubuntu/Mint),
FileManager.copyItem fails with POSIX EINVAL (22) when swift sdk install
copies the Darwin SDK from /tmp to ~/.swiftpm on an ext4 filesystem.

Fix by defaulting to ~/.cache/xtool (respecting \$XDG_CACHE_HOME) on
Linux, keeping the build and install destination on the same filesystem.

Fixes xtool-org#181
Copy link
Copy Markdown
Member

@kabiroberai kabiroberai left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thanks! looks good for the most part, just one nit

Comment thread Sources/XUtils/TemporaryDirectory.swift Outdated
#endif
}

let url = base.appendingPathComponent("sh.xtool")
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can we avoid doing this in the branch you added, since the directory is already ~/.cache/xtool? we can instead append sh.xtool specifically in the (XTL_)TMPDIR and macOS-temporaryDirectory branches.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch, fixed! Moved the sh.xtool append into the TMPDIR and macOS branches so the Linux path stays at ~/.cache/xtool directly.

Per review feedback: the Linux XDG cache branch already lands at
~/.cache/xtool so it should not have sh.xtool appended again.
Move the appendPathComponent into the other two branches instead.
Comment thread Sources/XUtils/TemporaryDirectory.swift Outdated
}

let url = base.appendingPathComponent("sh.xtool")
let url = base
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

last nit, can we drop this and just rename base to url?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, renamed base to url directly.

@kabiroberai kabiroberai merged commit c65d45b into xtool-org:main Apr 18, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

xtool setup fails on linux mint

2 participants