sources module unaware of the environment
Metadata
Current evaluation
No evaluation has been recorded for this issue yet.
Issue body
### Bug Description
The [sources](https://github.com/canonical/craft-parts/tree/main/craft_parts/sources) modules in craft_parts executes subcommands without passing env vars. So when using the lib as a project running in a snap, env vars from the snap, and especially the PATH, are not considered.
See [current log output](https://github.com/canonical/imagecraft/actions/runs/10315021793/job/28554568598?pr=54) of imagecraft spread tests. `git` is not found on the system (even though it is packaged in the snap), then installed. But the installed version is not compatible and unable to properly handle the given command.
See [the related discussion on matrix](https://matrix.to/#/!GGqzbFAUQprdPgYYCM:ubuntu.com/$Lj7xtjSH1a3XZFeW0iLFK-j1AYkaPostfMMb4tar0Hw?via=ubuntu.com&via=matrix.org&via=envs.net) for context.
### To Reproduce
Create a simple craft app using craft_parts and consuming a part using a plugin calling the sources modules.
Example of a plugin in imagecraft: [gadget plugin](https://github.com/canonical/imagecraft/blob/main/imagecraft/plugins/gadget.py).
The following YAML is to be run with imagecraft. Following this [how-to build a basic image with imagecraft](https://canonical-imagecraft.readthedocs-hosted.com/en/latest/howto/basic_image/) on a 18.04 machine should reproduce the issue.
### part yaml
```shell
name: ubuntu-server-amd64
version: "1"
base: ubuntu@24.04
series: noble
platforms:
amd64:
build-for: [amd64]
build-on: [amd64]
package-repositories:
- type: apt
components: [main, restricted, universe, multiverse]
url: http://archive.ubuntu.com/ubuntu/
pocket: updates
used-for: build
parts:
gadget:
plugin: gadget
source: https://github.com/snapcore/pc-gadget.git
source-branch: classic
rootfs:
plugin: ubuntu-seed
ubuntu-seed-pocket: updates
ubuntu-seed-germinate:
urls:
- "git://git.launchpad.net/~ubuntu-core-dev/ubuntu-seeds/+git/"
branch: noble
vcs: true
names:
- server
- minimal
- standard
- cloud-image
ubuntu-seed-kernel: linux-image-generic
ubuntu-seed-extra-snaps: [snapd]
stage:
- -rootfs/etc/cloud/cloud.cfg.d/90_dpkg.cfg
- -rootfs/dev/stderr # workaround until u-i cleans it
- -rootfs/dev/stdin # workaround until u-i cleans it
- -rootfs/dev/stdout # workaround until u-i cleans it
cloud-init:
plugin: dump
source: cloud-init/
organize:
'*': rootfs/
```
### Relevant log output
```shell
2024-08-09T07:10:18.4712656Z 2024-08-09 07:10:14.332 Initialising lifecycle
2024-08-09T07:10:18.4713825Z 2024-08-09 07:10:14.333 ignore patterns: []
2024-08-09T07:10:18.4714769Z 2024-08-09 07:10:14.333 source build packages: {'git'}
2024-08-09T07:10:18.4715994Z 2024-08-09 07:10:14.333 plugin build packages: {'make'}
2024-08-09T07:10:18.4717724Z 2024-08-09 07:10:14.333 plugin build snaps: {'i', '-', 'a', 'b', 't', 'g', 'u', 'n', 'e', 'm'}
2024-08-09T07:10:18.4718928Z 2024-08-09 07:10:14.334 Installing build-packages
2024-08-09T07:10:18.4720367Z 2024-08-09 07:10:14.334 Requested build-packages: ['git', 'make']
2024-08-09T07:10:18.4721841Z 2024-08-09 07:10:16.746 Marking git (and its dependencies) to be fetched
2024-08-09T07:10:18.4723060Z 2024-08-09 07:10:16.746 package: git
2024-08-09T07:10:18.4724485Z 2024-08-09 07:10:16.761 Marking make (and its dependencies) to be fetched
2024-08-09T07:10:18.4725899Z 2024-08-09 07:10:16.761 package: make
2024-08-09T07:10:18.4728001Z 2024-08-09 07:10:16.806 Requested build-packages already installed: ['git', 'make']
2024-08-09T07:10:18.4729985Z 2024-08-09 07:10:17.138 Installing build-snaps
[...]
2024-08-09T07:10:18.4886486Z 2024-08-09 07:10:17.223 Pulling gadget
2024-08-09T07:10:18.4893619Z 2024-08-09 07:10:17.223 execute action gadget:Action(part_name='gadget', step=Step.PULL, action_type=ActionType.RUN, reason=None, project_vars=None, properties=ActionProperties(changed_files=None, changed_dirs=None))
2024-08-09T07:10:18.4896541Z 2024-08-09 07:10:17.225 Executing: git clone --recursive --branch classic https://github.com/snapcore/pc-gadget.git
2024-08-09T07:10:18.4900147Z 2024-08-09 07:10:17.344 :: Cloning into '/home/imagecraft/tests/spread/amd64/classic/ubuntu_server_pc_amd64/parts/gadget/src'...
2024-08-09T07:10:18.4905073Z 2024-08-09 07:10:18.285 :: usage: git submodule [--quiet] [--cached]
2024-08-09T07:10:18.4910611Z 2024-08-09 07:10:18.285 :: or: git submodule [--quiet] add [-b <branch>] [-f|--force] [--name <name>] [--reference <repository>] [--] <repository> [<path>]
[...]
```
Evaluation history
No evaluation history available.