Skip to content

Swift package error #243681

Closed
Closed

Description

@godalming123

Describe the bug

When running swift package the following error is produced:

/nix/store/mvdqpiimfqrv44ihhd4aq104w89qca6i-swift-wrapper-5.8/bin/swift: line 33: exec: swift-package: not found

Steps To Reproduce

Steps to reproduce the behavior:

  1. Install nix on fedora after disabling selinux
  2. Run nix-shell -p swift
  3. Withen that shell run swift package

Expected behavior

The swift package command works.

Notify maintainers

@stephank

Metadata

[user@system:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 6.3.11-200.fc38.x86_64, Fedora Linux, 38 (Workstation Edition), nobuild`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.16.1`
 - channels(root): `"nixpkgs"`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixpkgs`

Activity

  1. added
    0.kind: bug
    on Jul 15, 2023
  2. smkuehnhold commented on Aug 11, 2023

    @smkuehnhold

    Yeah I'm running into this too. Without looking into it too deeply, it seems like pkgs.swift is a lot more barebones on 23.05 than 22.11 and doesn't include a lot of the things that would normally be distributed in the toolchain (like the package manager in this case)?

    For example, if you add nixpkgs/23.05#swiftPackages.swiftpm to your environment, package subcommand will run, but calling swift build will result in an error (error: toolchain is invalid: could not find ar).

    Conversely, reverting to the swift found in 22.11 seems to restore all the missing functionality without the need of any additional packages.

    Can @stephank or any of the other maintainers (@dtzWill @trepetti @dduan @Trundle) give information on what has changed with how swift is packaged in 22.11 vs. 23.05? Also, can you give simple instructions on what packages are required to get the complete toolchain as is typically bundled with swift (i.e. the commands that are visible when simply calling swift)?

    Thanks,
    smkuehnhold

  3. ink-splatters commented on Nov 21, 2023

    @ink-splatters
    Contributor

    For the specified nixpkgs:

    airstation:~ nix-instantiate --eval '<nixpkgs>' --attr lib.version
    "23.11pre550945.f1f62c94f613"

    this broken shell:

    airstation:~ ic$ nix-shell -p swift
    
    [nix-shell:~]$ swift build
    /nix/store/sccf314q4yfs2n7669qjqicg9hcmxr55-swift-wrapper-5.8/bin/swift: line 33: exec: swift-build: not found

    is fixable by adding swiftPackages.swiftpm:

    airstation:~ ic$ nix-shell -p swift swiftPackages.swiftpm
    
    [nix-shell:~]$ swift build
    error: Could not find Package.swift in this directory or any of its parent directories.
  4. godalming123 commented on Nov 22, 2023

    @godalming123
    Author

    For the specified nixpkgs:

    airstation:~ nix-instantiate --eval '<nixpkgs>' --attr lib.version
    "23.11pre550945.f1f62c94f613"

    this broken shell:

    airstation:~ ic$ nix-shell -p swift
    
    [nix-shell:~]$ swift build
    /nix/store/sccf314q4yfs2n7669qjqicg9hcmxr55-swift-wrapper-5.8/bin/swift: line 33: exec: swift-build: not found

    is fixable by adding swiftPackages.swiftpm:

    airstation:~ ic$ nix-shell -p swift swiftPackages.swiftpm
    
    [nix-shell:~]$ swift build
    error: Could not find Package.swift in this directory or any of its parent directories.

    I haven't tested this since I just used another package manager, but I will assume that this works and close the issue.

  5. smkuehnhold commented on Nov 22, 2023

    @smkuehnhold

    @godalming123 Can you please re-open the issue since this is problem is not unique to you?

    What @ink-splatters did is no different than what I tried. If you try to build even the most basic package, you will get the ar error.

    Running

    nix shell nixpkgs/23.11-pre#swift nixpkgs/23.11-pre#swiftPackages.swiftpm
    mkdir tmp-pkg && cd tmp-pkg/
    swift package init
    swift build
    

    Results in:

    error: toolchain is invalid: could not find ar
    
  6. smkuehnhold commented on Nov 22, 2023

    @smkuehnhold
  7. smkuehnhold commented on Dec 2, 2023

    @smkuehnhold

    Probably something some of you have already done, but I've created a small flake to setup a docker-based development environment as a workaround until this is fixed.

  8. ink-splatters commented on Dec 4, 2023

    @ink-splatters
    Contributor

    FYI, I posted my solution to the neighbouring thread, which I used to build another swift app which requires packaging.

    I verified it works both for nix-shell and flakes' nix develop on the latest nixpkgs-unstable (to the date).

    However, I haven't managed to make it work with nix shell because the workaround used requires overriding stdenv (and I'm not sure it's easy enough with nix shell though I didn't bother TBH, as nix develop is just fine for my needs)


    UPD: nix shell evaluates flake' package attribute and is a tool for temporary accessing a package, hence not applicable here.

    Effective difference between nix-shell and nix develop is that the former permits impurity OOB. To match this behaviour, pure-by-design nix develop should be called with --impure flag

  9. added
    6.topic: swift
    on Nov 7, 2024
  10. added
    2.status: stale
    on Jul 3, 2025
  11. reckenrode commented on Oct 13, 2026

    @reckenrode
    Contributor

    Swift has been updated to Swift 6.x. Please reopen if this continues to be an issue. Swift should be able to find SwiftPM as long as it is on your path.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    0.kind: bug2.status: stale6.topic: swift

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions