Repository: spack/spack

Issue:
clingo bootstrap failing inside certain environments
### Steps to reproduce

I believe this is an issue with trying to bootstrap inside an environment. It could be anonymous environments.  I'm not sure. pinging @alalazo 

```console
rm -rf ~/.spack $SPACK_ROOT
#clone spack
#source spack-setup.sh
#create anonyomus env with no view and concretization: together
#activate env
spack add nalu-wind
spack concretize
```


### Error message

```console
psakiev@skybridge-login3 disk_dev]$ spack -d concretize
==> [2021-09-16-06:40:17.351737] Imported concretize from built-in commands
==> [2021-09-16-06:40:17.352881] Imported concretize from built-in commands
==> [2021-09-16-06:40:17.367058] Reading config file /projects/wind/spack-manager/environments/disk_dev/general_repos.yaml
==> [2021-09-16-06:40:17.369307] Reading config file /projects/wind/spack-manager/environments/disk_dev/general_config.yaml
==> [2021-09-16-06:40:17.372345] Reading config file /projects/wind/spack-manager/environments/disk_dev/general_packages.yaml
==> [2021-09-16-06:40:17.390171] Reading config file /projects/wind/spack-manager/environments/disk_dev/machine_compilers.yaml
==> [2021-09-16-06:40:17.406069] Reading config file /projects/wind/spack-manager/environments/disk_dev/machine_packages.yaml
==> [2021-09-16-06:40:17.440079] Reading config file /projects/wind/spack-manager/environments/disk_dev/machine_config.yaml
==> [2021-09-16-06:40:17.447444] Reading config file /projects/wind/spack-manager/environments/disk_dev/spack.yaml
==> [2021-09-16-06:40:17.556539] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/bootstrap.yaml
==> [2021-09-16-06:40:17.580823] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/config.yaml
==> [2021-09-16-06:40:17.614834] DATABASE LOCK TIMEOUT: 3s
==> [2021-09-16-06:40:17.614934] PACKAGE LOCK TIMEOUT: No timeout
==> [2021-09-16-06:40:17.615501] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/bootstrap.yaml
==> [2021-09-16-06:40:17.633425] DATABASE LOCK TIMEOUT: 3s
==> [2021-09-16-06:40:17.633528] PACKAGE LOCK TIMEOUT: No timeout
==> [2021-09-16-06:40:17.633668] [BOOTSTRAP CONFIG SCOPE] name=_builtin
==> [2021-09-16-06:40:17.634234] [BOOTSTRAP CONFIG SCOPE] name=defaults, path=/projects/wind/spack-manager/spack/etc/spack/defaults
==> [2021-09-16-06:40:17.634322] [BOOTSTRAP CONFIG SCOPE] name=defaults/linux, path=/projects/wind/spack-manager/spack/etc/spack/defaults/linux
==> [2021-09-16-06:40:17.634403] [BOOTSTRAP CONFIG SCOPE] name=system, path=/etc/spack
==> [2021-09-16-06:40:17.634481] [BOOTSTRAP CONFIG SCOPE] name=system/linux, path=/etc/spack/linux
==> [2021-09-16-06:40:17.634570] [BOOTSTRAP CONFIG SCOPE] name=site, path=/projects/wind/spack-manager/spack/etc/spack
==> [2021-09-16-06:40:17.634648] [BOOTSTRAP CONFIG SCOPE] name=site/linux, path=/projects/wind/spack-manager/spack/etc/spack/linux
==> [2021-09-16-06:40:17.634735] [BOOTSTRAP CONFIG SCOPE] name=user, path=/ascldap/users/psakiev/.spack
==> [2021-09-16-06:40:17.634812] [BOOTSTRAP CONFIG SCOPE] name=user/linux, path=/ascldap/users/psakiev/.spack/linux
==> [2021-09-16-06:40:17.640129] [BOOTSTRAP ROOT SPEC] clingo: clingo-bootstrap@spack+python %gcc target=x86_64
==> [2021-09-16-06:40:17.640215] [BOOTSTRAP MODULE clingo] Try importing from Python
==> [2021-09-16-06:40:17.640689] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/bootstrap.yaml
==> [2021-09-16-06:40:17.662455] Bootstrapping clingo from pre-built binaries
==> [2021-09-16-06:40:17.777211] Imported buildcache from built-in commands
==> [2021-09-16-06:40:17.785090] Imported buildcache from built-in commands
==> [2021-09-16-06:40:17.786600] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/config.yaml
==> [2021-09-16-06:40:17.839194] DATABASE LOCK TIMEOUT: 3s
==> [2021-09-16-06:40:17.839281] PACKAGE LOCK TIMEOUT: No timeout
==> [2021-09-16-06:40:17.892251] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/mirrors.yaml
==> [2021-09-16-06:40:18.207104] Cached index for https://mirror.spack.io/bootstrap/github-actions/v0.1 already up to date
==> [2021-09-16-06:40:18.222695] [BOOTSTRAP MODULE clingo] Try installing "clingo-bootstrap" from binary cache at "https://mirror.spack.io/bootstrap/github-actions/v0.1"
==> [2021-09-16-06:40:25.528251] NoCompilersForArchError: No compilers found for operating system rhel7 and target sandybridge.
If previous installations have succeeded, the operating system may have been updated.
Compilers are defined for the following operating systems and targets:
	rhel5-x86_64
    Run 'spack compiler find' to add compilers.
==> [2021-09-16-06:40:25.535851] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/bootstrap.yaml
==> [2021-09-16-06:40:26.009221] diffutils applying constraint iconv
==> [2021-09-16-06:40:26.308821] ncurses applying constraint pkgconfig
==> [2021-09-16-06:40:26.310875] readline applying constraint ncurses
==> [2021-09-16-06:40:26.312950] gdbm applying constraint readline
==> [2021-09-16-06:40:26.368339] bzip2 applying constraint diffutils
==> [2021-09-16-06:40:26.425215] perl applying constraint gdbm@:1.19
==> [2021-09-16-06:40:26.427484] perl applying constraint berkeley-db
==> [2021-09-16-06:40:26.429713] perl applying constraint bzip2
==> [2021-09-16-06:40:26.431957] perl applying constraint zlib
==> [2021-09-16-06:40:26.434233] bison applying constraint diffutils
==> [2021-09-16-06:40:26.436433] bison applying constraint m4
==> [2021-09-16-06:40:26.438630] bison applying constraint perl
==> [2021-09-16-06:40:26.441166] clingo-bootstrap applying constraint python
==> [2021-09-16-06:40:26.442178] python applying constraint pkgconfig@0.9.0:
==> [2021-09-16-06:40:26.445835] python applying constraint pkgconfig@0.9.0:
==> [2021-09-16-06:40:26.451382] clingo-bootstrap applying constraint cmake@3.16.0:
==> [2021-09-16-06:40:26.454091] clingo-bootstrap applying constraint re2c@0.13:
==> [2021-09-16-06:40:26.457168] clingo-bootstrap applying constraint bison@2.5:
==> [2021-09-16-06:40:26.459679] clingo-bootstrap applying constraint python
==> [2021-09-16-06:40:26.464214] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/packages.yaml
==> [2021-09-16-06:40:33.312655] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/config.yaml
==> [2021-09-16-06:40:33.449589] clingo-bootstrap applying constraint cmake@3.16.0:
==> [2021-09-16-06:40:33.452269] clingo-bootstrap applying constraint re2c@0.13:
==> [2021-09-16-06:40:33.453871] clingo-bootstrap applying constraint bison@2.5:
==> [2021-09-16-06:40:33.455070] bison applying constraint diffutils
==> [2021-09-16-06:40:33.455789] diffutils applying constraint libiconv
==> [2021-09-16-06:40:33.456952] bison applying constraint m4
==> [2021-09-16-06:40:33.458127] bison applying constraint perl
==> [2021-09-16-06:40:33.459316] perl applying constraint gdbm@:1.19
==> [2021-09-16-06:40:33.460453] gdbm applying constraint readline
==> [2021-09-16-06:40:33.461561] readline applying constraint ncurses
==> [2021-09-16-06:40:33.462236] ncurses applying constraint pkgconfig
==> [2021-09-16-06:40:33.463384] perl applying constraint berkeley-db
==> [2021-09-16-06:40:33.464511] perl applying constraint bzip2
==> [2021-09-16-06:40:33.465637] bzip2 applying constraint diffutils
==> [2021-09-16-06:40:33.466754] perl applying constraint zlib
==> [2021-09-16-06:40:33.468113] clingo-bootstrap applying constraint python
==> [2021-09-16-06:40:33.468958] python applying constraint pkgconfig@0.9.0:
==> [2021-09-16-06:40:33.569161] clingo-bootstrap applying constraint cmake@3.16.0:
==> [2021-09-16-06:40:33.571687] clingo-bootstrap applying constraint re2c@0.13:
==> [2021-09-16-06:40:33.573167] clingo-bootstrap applying constraint bison@2.5:
==> [2021-09-16-06:40:33.574240] bison applying constraint diffutils
==> [2021-09-16-06:40:33.574889] diffutils applying constraint libiconv
==> [2021-09-16-06:40:33.575934] bison applying constraint m4
==> [2021-09-16-06:40:33.577110] bison applying constraint perl
==> [2021-09-16-06:40:33.578203] perl applying constraint gdbm@:1.19
==> [2021-09-16-06:40:33.579255] gdbm applying constraint readline
==> [2021-09-16-06:40:33.580285] readline applying constraint ncurses
==> [2021-09-16-06:40:33.580928] ncurses applying constraint pkgconf
==> [2021-09-16-06:40:33.581985] perl applying constraint berkeley-db
==> [2021-09-16-06:40:33.583033] perl applying constraint bzip2
==> [2021-09-16-06:40:33.584051] bzip2 applying constraint diffutils
==> [2021-09-16-06:40:33.585069] perl applying constraint zlib
==> [2021-09-16-06:40:33.586314] clingo-bootstrap applying constraint python
==> [2021-09-16-06:40:33.587051] python applying constraint pkgconf
==> [2021-09-16-06:40:33.603726] clingo-bootstrap applying constraint cmake@3.16.0:
==> [2021-09-16-06:40:33.606278] clingo-bootstrap applying constraint re2c@0.13:
==> [2021-09-16-06:40:33.607738] clingo-bootstrap applying constraint bison@2.5:
==> [2021-09-16-06:40:33.608804] bison applying constraint diffutils
==> [2021-09-16-06:40:33.609509] diffutils applying constraint libiconv
==> [2021-09-16-06:40:33.610546] bison applying constraint m4
==> [2021-09-16-06:40:33.611631] bison applying constraint perl
==> [2021-09-16-06:40:33.612753] perl applying constraint gdbm@:1.19
==> [2021-09-16-06:40:33.613897] gdbm applying constraint readline
==> [2021-09-16-06:40:33.614930] readline applying constraint ncurses
==> [2021-09-16-06:40:33.615579] ncurses applying constraint pkgconf
==> [2021-09-16-06:40:33.616638] perl applying constraint berkeley-db
==> [2021-09-16-06:40:33.617666] perl applying constraint bzip2
==> [2021-09-16-06:40:33.618689] bzip2 applying constraint diffutils
==> [2021-09-16-06:40:33.619706] perl applying constraint zlib
==> [2021-09-16-06:40:33.620960] clingo-bootstrap applying constraint python
==> [2021-09-16-06:40:33.629770] [BOOTSTRAP MODULE clingo] Unexpected error "No compilers with spec gcc found for operating system rhel7 and target x86_64.
    Run 'spack compiler find' to add compilers or 'spack compilers' to see which compilers are already recognized by spack."
==> [2021-09-16-06:40:33.648392] Reading config file /projects/wind/spack-manager/spack/etc/spack/defaults/config.yaml
Traceback (most recent call last):
  File "/projects/wind/spack-manager/spack/bin/spack", line 100, in <module>
    sys.exit(spack.main.main())
  File "/projects/wind/spack-manager/spack/lib/spack/spack/main.py", line 797, in main
    return _invoke_command(command, parser, args, unknown)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/main.py", line 525, in _invoke_command
    return_val = command(parser, args)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/cmd/concretize.py", line 37, in concretize
    concretized_specs = env.concretize(force=args.force, tests=tests)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/environment.py", line 1147, in concretize
    return self._concretize_together(tests=tests)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/environment.py", line 1187, in _concretize_together
    *self.user_specs, tests=tests)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/concretize.py", line 725, in concretize_specs_together
    return _concretize_specs_together_new(*abstract_specs, **kwargs)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/concretize.py", line 730, in _concretize_specs_together_new
    result = spack.solver.asp.solve(abstract_specs)
  File "/projects/wind/spack-manager/spack/lib/spack/spack/solver/asp.py", line 1679, in solve
    driver = PyclingoDriver()
  File "/projects/wind/spack-manager/spack/lib/spack/spack/solver/asp.py", line 292, in __init__
    spack.bootstrap.ensure_clingo_importable_or_raise()
  File "/projects/wind/spack-manager/spack/lib/spack/spack/bootstrap.py", line 559, in ensure_clingo_importable_or_raise
    module='clingo', abstract_spec=clingo_root_spec()
  File "/projects/wind/spack-manager/spack/lib/spack/spack/bootstrap.py", line 399, in ensure_module_importable_or_raise
    raise ImportError(msg)
ImportError: cannot bootstrap the "clingo" Python module from spec "clingo-bootstrap@spack+python %gcc target=x86_64"
```

### Information on your system

```console
* **Spack:** 0.16.2-4267-5b211c90f5
* **Python:** 3.6.8
* **Platform:** linux-rhel7-sandybridge
* **Concretizer:** clingo
```

### General information

- [X] I have run `spack debug report` and reported the version of Spack/Python/Platform
- [X] I have searched the issues of this repo and believe this is not a duplicate
- [X] I have run the failing commands in debug mode and reported the output


Discussion:
I can't reproduce this issue, as everything works for me. Differences with your environment:

* **Spack:** 0.16.2-4270-244a3074ad
* **Python:** 3.8.10
* **Platform:** linux-ubuntu20.04-icelake
* **Concretizer:** clingo

<details>

<summary> Console output </summary>

```console
ulpo@nivola:/tmp$ spack env activate /tmp
culpo@nivola:/tmp$ spack add nalu-wind
==> Adding nalu-wind to environment /tmp
culpo@nivola:/tmp$ cat spack.yaml 
# This is a Spack Environment file.
#
# It describes a set of packages to be installed, along with
# configuration settings.
spack:
  # add package specs to the `specs` list
  specs: [nalu-wind]
  concretization: together
  view: false
culpo@nivola:/tmp$ spack concretize
==> Bootstrapping clingo from pre-built binaries
==> Concretized nalu-wind
 -   c3qquwz  nalu-wind@master%gcc@9.3.0~boost~catalyst~cuda~fftw~hypre~ipo~openfast+pic~tioga~wind-utils abs_tol=1e-15 build_type=RelWithDebInfo cuda_arch=none rel_tol=1e-12 arch=linux-ubuntu20.04-icelake
 -   jcjw6cc      ^cmake@3.21.2%gcc@9.3.0~doc+ncurses+openssl+ownlibs~qt build_type=Release arch=linux-ubuntu20.04-icelake
 -   wevrxpl          ^ncurses@6.2%gcc@9.3.0~symlinks+termlib abi=none arch=linux-ubuntu20.04-icelake
 -   5u2zrji              ^pkgconf@1.8.0%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   cltxaaa          ^openssl@1.1.1l%gcc@9.3.0~docs+systemcerts arch=linux-ubuntu20.04-icelake
 -   5fknwft              ^perl@5.34.0%gcc@9.3.0+cpanm+shared+threads arch=linux-ubuntu20.04-icelake
 -   bca2ndl                  ^berkeley-db@18.1.40%gcc@9.3.0+cxx~docs+stl patches=b231fcc4d5cff05e5c3a4814f6a5af0e9a966428dc2176540d2c05aff41de522 arch=linux-ubuntu20.04-icelake
 -   m6msmwh                  ^bzip2@1.0.8%gcc@9.3.0~debug~pic+shared arch=linux-ubuntu20.04-icelake
 -   vscaehj                      ^diffutils@3.7%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   ueh6r5u                          ^libiconv@1.16%gcc@9.3.0 libs=shared,static arch=linux-ubuntu20.04-icelake
 -   q5oia5x                  ^gdbm@1.19%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   23mubk3                      ^readline@8.1%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   ech7q6s                  ^zlib@1.2.11%gcc@9.3.0+optimize+pic+shared arch=linux-ubuntu20.04-icelake
 -   7pymgof      ^nccmp@1.9.0.1%gcc@9.3.0~ipo build_type=RelWithDebInfo arch=linux-ubuntu20.04-icelake
 -   4reffoc          ^netcdf-c@4.8.0%gcc@9.3.0~dap~fsync~hdf4~jna+mpi+parallel-netcdf+pic+shared arch=linux-ubuntu20.04-icelake
 -   qwoajd6              ^hdf5@1.10.7%gcc@9.3.0~cxx~fortran+hl~ipo~java+mpi+shared~szip~threadsafe+tools api=default build_type=RelWithDebInfo arch=linux-ubuntu20.04-icelake
 -   ixwmjr3                  ^openmpi@4.1.1%gcc@9.3.0~atomics~cuda~cxx~cxx_exceptions+gpfs~internal-hwloc~java~legacylaunchers~lustre~memchecker~pmi~singularity~sqlite3+static~thread_multiple+vt+wrapper-rpath fabrics=none schedulers=none arch=linux-ubuntu20.04-icelake
 -   zpzvvem                      ^hwloc@2.5.0%gcc@9.3.0~cairo~cuda~gl~libudev+libxml2~netloc~nvml~opencl+pci~rocm+shared arch=linux-ubuntu20.04-icelake
 -   f3ujejk                          ^libpciaccess@0.16%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   w2merzt                              ^libtool@2.4.6%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   qal57j2                                  ^m4@1.4.19%gcc@9.3.0+sigsegv patches=9dc5fbd0d5cb1037ab1e6d0ecc74a30df218d0a94bdd5a02759a97f62daca573,bfdffa7c2eb01021d5849b36972c069693654ad826c1a20b53534009a4ec7a89 arch=linux-ubuntu20.04-icelake
 -   basfgy2                                      ^libsigsegv@2.13%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   rh46vik                              ^util-macros@1.19.3%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   umfo2pm                          ^libxml2@2.9.12%gcc@9.3.0~python arch=linux-ubuntu20.04-icelake
 -   essg37l                              ^xz@5.2.5%gcc@9.3.0~pic libs=shared,static arch=linux-ubuntu20.04-icelake
 -   6ilhue2                      ^libevent@2.1.12%gcc@9.3.0+openssl arch=linux-ubuntu20.04-icelake
 -   fsvgtuq                      ^numactl@2.0.14%gcc@9.3.0 patches=4e1d78cbbb85de625bad28705e748856033eaafab92a66dffd383a3d7e00cc94,62fc8a8bf7665a60e8f4c93ebbd535647cebf74198f7afafec4c085a8825c006 arch=linux-ubuntu20.04-icelake
 -   6ago2g2                          ^autoconf@2.69%gcc@9.3.0 patches=35c449281546376449766f92d49fc121ca50e330e60fefcfc9be2af3253082c2,7793209b33013dc0f81208718c68440c5aae80e7a1c4b8d336e382525af791a7,a49dd5bac3b62daa0ff688ab4d508d71dbd2f4f8d7e2a02321926346161bf3ee arch=linux-ubuntu20.04-icelake
 -   7yycpt6                          ^automake@1.16.3%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   qr4oxe3                      ^openssh@8.7p1%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   7elophq                          ^libedit@3.1-20210216%gcc@9.3.0 arch=linux-ubuntu20.04-icelake
 -   akgvm7f              ^parallel-netcdf@1.12.2%gcc@9.3.0~burstbuffer+cxx+fortran+pic+shared arch=linux-ubuntu20.04-icelake
 -   p7ehdcw      ^trilinos@develop%gcc@9.3.0~adios2+amesos+amesos2+anasazi+aztec~basker+belos+boost~chaco~complex~cuda~cuda_rdc~debug~dtk+epetra+epetraext~epetraextbtf~epetraextexperimental~epetraextgraphreorderings+exodus+explicit_template_instantiation~float+fortran+hdf5~hypre+ifpack+ifpack2~intrepid~intrepid2~ipo~isorropia+kokkos~mesquite~minitensor+ml+mpi+muelu~mumps~nox~openmp~phalanx~piro~python~rol~rythmos+sacado~scorec+shards+shared~shylu+stk~stokhos~stratimikos~strumpack~suite-sparse~superlu~superlu-dist~teko~tempus+tpetra~trilinoscouplings~wrapper~x11+zlib+zoltan~zoltan2 build_type=RelWithDebInfo cuda_arch=none cxxstd=14 gotype=long arch=linux-ubuntu20.04-icelake
 -   af7cbex          ^boost@1.77.0%gcc@9.3.0+atomic+chrono~clanglibcpp~container~context~coroutine+date_time~debug+exception~fiber+filesystem+graph~icu+iostreams+locale+log+math~mpi+multithreaded~numpy~pic+program_options~python+random+regex+serialization+shared+signals~singlethreaded+system~taggedlayout+test+thread+timer~versionedlayout+wave cxxstd=98 visibility=hidden arch=linux-ubuntu20.04-icelake
 -   j47kdyo          ^cgns@4.2.0%gcc@9.3.0~base_scope~fortran+hdf5~int64~ipo~legacy~mem_debug+mpi+scoping+shared~static~testing build_type=RelWithDebInfo arch=linux-ubuntu20.04-icelake
 -   zpw3jff          ^matio@1.5.17%gcc@9.3.0+hdf5+shared+zlib arch=linux-ubuntu20.04-icelake
 -   hemcf6d          ^metis@5.1.0%gcc@9.3.0~gdb~int64~real64+shared build_type=Release patches=4991da938c1d3a1d3dea78e49bbebecba00273f98df2a656e38b83d55b281da1,b1225da886605ea558db7ac08dd8054742ea5afe5ed61ad4d0fe7a495b1270d2 arch=linux-ubuntu20.04-icelake
 -   j6lxgt3          ^openblas@0.3.17%gcc@9.3.0~bignuma~consistent_fpcsr~ilp64+locking+pic+shared threads=none arch=linux-ubuntu20.04-icelake
 -   s3f3bds          ^parmetis@4.0.3%gcc@9.3.0~gdb~int64~ipo+shared build_type=RelWithDebInfo patches=4f892531eb0a807eb1b82e683a416d3e35154a455274cf9b162fb02054d11a5b,50ed2081bc939269689789942067c58b3e522c269269a430d5d34c00edbc5870,704b84f7c7444d4372cb59cca6e1209df4ef3b033bc4ee3cf50f369bce972a9d arch=linux-ubuntu20.04-icelake
 -   s2day2u      ^yaml-cpp@0.7.0%gcc@9.3.0~ipo+pic+shared~tests build_type=RelWithDebInfo arch=linux-ubuntu20.04-icelake

 spack find -b
==> Showing internal bootstrap store at "/home/culpo/.spack/bootstrap/store"
==> 3 installed packages
-- linux-rhel5-x86_64 / gcc@9.3.0 -------------------------------
clingo-bootstrap@spack  python@3.8

-- linux-ubuntu20.04-icelake / gcc@9.3.0 ------------------------
patchelf@0.13
```

</details>

Do you have either:
- `patchelf` installed on your system, or
- a C++11 capable compiler to build it from sources

?
I'll retry in a docker environment with CentOS 7
I was worried this would be hard to reproduce on another system.  I do have `patchelf` and a C+11.  Also I get a successful bootstrap if I run `spack solve zlib` outside the environment. So it seems to be related to the environment and/or calling `solve` vs `concretize`.  

I have replicated this issue several different times on the current system so it is repeatable on mine.
I see this in your log:
```
[BOOTSTRAP MODULE clingo] Try installing "clingo-bootstrap" from binary cache at "https://mirror.spack.io/bootstrap/github-actions/v0.1"
==> [2021-09-16-06:40:25.528251] NoCompilersForArchError: No compilers found for operating system rhel7 and target sandybridge.
If previous installations have succeeded, the operating system may have been updated.
Compilers are defined for the following operating systems and targets:
	rhel5-x86_64
```
What do you get from `spack compiler list`? EDIT: don't mind having `rhel5`, that's because of the buildcache.
These are the system compilers
```
[psakiev@skybridge-login3 disk_dev]$ spack compiler list
==> Available compilers
-- gcc rhel7-x86_64 ---------------------------------------------
gcc@4.8.5

-- intel rhel7-x86_64 -------------------------------------------
intel@16.0.2
```

I can't reproduce it even on a CentOS 7 docker image. In the end the environment concretizes and Spack has this in the bootstrap store:
```console
# spack find -b
==> Showing internal bootstrap store at "/root/.spack/bootstrap/store"
==> 3 installed packages
-- linux-centos7-haswell / gcc@4.8.5 ----------------------------
patchelf@0.13

-- linux-rhel5-x86_64 / gcc@9.3.0 -------------------------------
clingo-bootstrap@spack  python@2.7
```

Also, the version of Spack you reported is recent enough to have https://github.com/spack/spack/pull/25607 so I wonder what is the trigger here.
Can you reproduce the same behavior on another rhel7 machine?
Here is my bootstrap store after successful bootstraping
```console
# spack find -b
==> Showing internal bootstrap store at "/ascldap/users/psakiev/.spack/bootstrap/store"
==> 3 installed packages
-- linux-rhel5-x86_64 / gcc@9.3.0 -------------------------------
clingo-bootstrap@spack  python@3.6

-- linux-rhel7-sandybridge / gcc@4.8.5 --------------------------
patchelf@0.13
```
I'll try to reproduce on another machine later today. Unfortunately all the rhel7 machines I use share the same home directory so I need to wipe `~/.spack` again.  One of my struggles with `~/.spack` priority
I was able to try it now.  Same error on a different rhel7 machine. Here are the compilers for this case
```console
# spack compiler list
-- gcc rhel7-x86_64 ---------------------------------------------
gcc@4.8.5  gcc@4.4.7
```
Also `spack solve libz` fails with the same error inside the environment. So it does seem to be an issue with being in the environment.
> So it does seem to be an issue with being in the environment.

This is weird because https://github.com/spack/spack/pull/25607 should ensure environments are deactivated during bootstrapping :thinking: I need to check if I have access to a rhel7 machine but currently I tried cento7, rhel8, ubuntu20.04 and couldn't reproduce. Can you `cat` your `spack.yaml`?
yeah here it is
```
# This is a Spack Environment file.
#
# It describes a set of packages to be installed, along with
# configuration settings.
spack:
  # add package specs to the `specs` list
  specs: [nalu-wind]
  view: false
  compilers:
  - compiler:
      spec: gcc@4.4.7
      paths:
        cc: /usr/bin/gcc44
        cxx: /usr/bin/g++44
        f77: null
        fc: null
      flags: {}
      operating_system: rhel7
      target: x86_64
      modules: []
      environment: {}
      extra_rpaths: []
  - compiler:
      spec: gcc@4.8.5
      paths:
        cc: /usr/bin/gcc
        cxx: /usr/bin/g++
        f77: /usr/bin/gfortran
        fc: /usr/bin/gfortran
      flags: {}
      operating_system: rhel7
      target: x86_64
      modules: []
      environment: {}
      extra_rpaths: []
```
here is the info on the second machine too
```console
# spack debug report
* **Spack:** 0.16.2-4269-2d34acf
* **Python:** 3.6.8
* **Platform:** linux-rhel7-ivybridge
* **Concretizer:** clingo
```
Hmm, just a guess but since there's one difference with mine... can you try to remove the `compilers` section and see if you still get the issue?
Adding a compilers section to `spack.yaml` I can finally reproduce a failure.
That was actually added for me. I'm going from a completely fresh clone and no `~/.spack` so I believe something in the concretize/bootstrap is running a compiler find operation and it is getting added to the `spack.yaml`.  When I remove that section spack adds it back for me again.  This could be the differentiator.
That shouldn't happen per the PR above :thinking: The issue with compilers should be solved when we merge #25608 but I need to verify that.
I think I understand what is happening here. These lines:

https://github.com/spack/spack/blob/bb29c5d6744a227c6169aafa2a79d36a51de85b6/lib/spack/spack/bootstrap.py#L495-L506

search for a compiler before deactivating the environment, if none are present. In my case I didn't hit the issue because I always started from places where a `compilers.yaml` was already there. Can you confirm that the issue goes away for you too if, outside of the environment, you run:
```
$ spack compiler find
```
and then you do all the other things you did before? If that's the issue I'll submit a fix tomorrow.
@alalazo yes that solves it for me as well. Thanks for tracking this down.

Resolving patch:
diff --git a/lib/spack/spack/bootstrap.py b/lib/spack/spack/bootstrap.py
--- a/lib/spack/spack/bootstrap.py
+++ b/lib/spack/spack/bootstrap.py
@@ -490,18 +490,20 @@ def _bootstrap_config_scopes():
     return config_scopes
 
 
-@contextlib.contextmanager
-def ensure_bootstrap_configuration():
-    # We may need to compile code from sources, so ensure we have compilers
-    # for the current platform before switching parts.
-    arch = spack.architecture.default_arch()
+def _add_compilers_if_missing():
+    # Do not use spack.architecture.default_arch() since it memoize the result
+    arch = spack.architecture.Arch(
+        spack.architecture.real_platform(), 'default_os', 'default_target'
+    )
     arch = spack.spec.ArchSpec(str(arch))  # The call below expects an ArchSpec object
     if not spack.compilers.compilers_for_arch(arch):
-        compiler_cmd = spack.main.SpackCommand('compiler')
-        compiler_cmd(
-            'find', output=os.devnull, error=os.devnull, fail_on_error=False
-        )
+        new_compilers = spack.compilers.find_new_compilers()
+        if new_compilers:
+            spack.compilers.add_compilers_to_config(new_compilers, init_config=False)
 
+
+@contextlib.contextmanager
+def ensure_bootstrap_configuration():
     bootstrap_store_path = store_path()
     with spack.environment.deactivate_environment():
         with spack.architecture.use_platform(spack.architecture.real_platform()):
@@ -511,6 +513,9 @@ def ensure_bootstrap_configuration():
                     # and builtin but accounting for platform specific scopes
                     config_scopes = _bootstrap_config_scopes()
                     with spack.config.use_configuration(*config_scopes):
+                        # We may need to compile code from sources, so ensure we have
+                        # compilers for the current platform before switching parts.
+                        _add_compilers_if_missing()
                         with spack.modules.disable_modules():
                             with spack_python_interpreter():
                                 yield
diff --git a/lib/spack/spack/cmd/compiler.py b/lib/spack/spack/cmd/compiler.py
--- a/lib/spack/spack/cmd/compiler.py
+++ b/lib/spack/spack/cmd/compiler.py
@@ -18,7 +18,6 @@
 import spack.compilers
 import spack.config
 import spack.spec
-from spack.spec import ArchSpec, CompilerSpec
 
 description = "manage compilers"
 section = "system"
@@ -78,24 +77,13 @@ def compiler_find(args):
     # None signals spack.compiler.find_compilers to use its default logic
     paths = args.add_paths or None
 
-    # Don't initialize compilers config via compilers.get_compiler_config.
-    # Just let compiler_find do the
-    # entire process and return an empty config from all_compilers
-    # Default for any other process is init_config=True
-    compilers = [c for c in spack.compilers.find_compilers(paths)]
-    new_compilers = []
-    for c in compilers:
-        arch_spec = ArchSpec((None, c.operating_system, c.target))
-        same_specs = spack.compilers.compilers_for_spec(
-            c.spec, arch_spec, init_config=False)
-
-        if not same_specs:
-            new_compilers.append(c)
-
+    # Below scope=None because we want new compilers that don't appear
+    # in any other configuration.
+    new_compilers = spack.compilers.find_new_compilers(paths, scope=None)
     if new_compilers:
-        spack.compilers.add_compilers_to_config(new_compilers,
-                                                scope=args.scope,
-                                                init_config=False)
+        spack.compilers.add_compilers_to_config(
+            new_compilers, scope=args.scope, init_config=False
+        )
         n = len(new_compilers)
         s = 's' if n > 1 else ''
 
@@ -110,7 +98,7 @@ def compiler_find(args):
 
 
 def compiler_remove(args):
-    cspec = CompilerSpec(args.compiler_spec)
+    cspec = spack.spec.CompilerSpec(args.compiler_spec)
     compilers = spack.compilers.compilers_for_spec(cspec, scope=args.scope)
     if not compilers:
         tty.die("No compilers match spec %s" % cspec)
@@ -128,7 +116,7 @@ def compiler_remove(args):
 
 def compiler_info(args):
     """Print info about all compilers matching a spec."""
-    cspec = CompilerSpec(args.compiler_spec)
+    cspec = spack.spec.CompilerSpec(args.compiler_spec)
     compilers = spack.compilers.compilers_for_spec(cspec, scope=args.scope)
 
     if not compilers:
diff --git a/lib/spack/spack/compilers/__init__.py b/lib/spack/spack/compilers/__init__.py
--- a/lib/spack/spack/compilers/__init__.py
+++ b/lib/spack/spack/compilers/__init__.py
@@ -192,15 +192,12 @@ def all_compiler_specs(scope=None, init_config=True):
 
 
 def find_compilers(path_hints=None):
-    """Returns the list of compilers found in the paths given as arguments.
+    """Return the list of compilers found in the paths given as arguments.
 
     Args:
         path_hints (list or None): list of path hints where to look for.
             A sensible default based on the ``PATH`` environment variable
             will be used if the value is None
-
-    Returns:
-        List of compilers found
     """
     if path_hints is None:
         path_hints = get_path('PATH')
@@ -242,6 +239,30 @@ def remove_errors(item):
     )
 
 
+def find_new_compilers(path_hints=None, scope=None):
+    """Same as ``find_compilers`` but return only the compilers that are not
+    already in compilers.yaml.
+
+    Args:
+        path_hints (list or None): list of path hints where to look for.
+            A sensible default based on the ``PATH`` environment variable
+            will be used if the value is None
+        scope (str): scope to look for a compiler. If None consider the
+            merged configuration.
+    """
+    compilers = find_compilers(path_hints)
+    compilers_not_in_config = []
+    for c in compilers:
+        arch_spec = spack.spec.ArchSpec((None, c.operating_system, c.target))
+        same_specs = compilers_for_spec(
+            c.spec, arch_spec, scope=scope, init_config=False
+        )
+        if not same_specs:
+            compilers_not_in_config.append(c)
+
+    return compilers_not_in_config
+
+
 def supported_compilers():
     """Return a set of names of compilers supported by Spack.
 
@@ -289,8 +310,9 @@ def all_compilers(scope=None):
 
 
 @_auto_compiler_spec
-def compilers_for_spec(compiler_spec, arch_spec=None, scope=None,
-                       use_cache=True, init_config=True):
+def compilers_for_spec(
+        compiler_spec, arch_spec=None, scope=None, use_cache=True, init_config=True
+):
     """This gets all compilers that satisfy the supplied CompilerSpec.
        Returns an empty list if none are found.
     """


Test patch:
diff --git a/lib/spack/spack/test/bootstrap.py b/lib/spack/spack/test/bootstrap.py
--- a/lib/spack/spack/test/bootstrap.py
+++ b/lib/spack/spack/test/bootstrap.py
@@ -5,6 +5,7 @@
 import pytest
 
 import spack.bootstrap
+import spack.compilers
 import spack.environment
 import spack.store
 import spack.util.path
@@ -78,3 +79,23 @@ def test_bootstrap_disables_modulefile_generation(mutable_config):
         assert 'lmod' not in spack.config.get('modules:enable')
     assert 'tcl' in spack.config.get('modules:enable')
     assert 'lmod' in spack.config.get('modules:enable')
+
+
+@pytest.mark.regression('25992')
+@pytest.mark.requires_executables('gcc')
+def test_bootstrap_search_for_compilers_with_no_environment(no_compilers_yaml):
+    assert not spack.compilers.all_compiler_specs(init_config=False)
+    with spack.bootstrap.ensure_bootstrap_configuration():
+        assert spack.compilers.all_compiler_specs(init_config=False)
+    assert not spack.compilers.all_compiler_specs(init_config=False)
+
+
+@pytest.mark.regression('25992')
+@pytest.mark.requires_executables('gcc')
+def test_bootstrap_search_for_compilers_with_environment_active(
+        no_compilers_yaml, active_mock_environment
+):
+    assert not spack.compilers.all_compiler_specs(init_config=False)
+    with spack.bootstrap.ensure_bootstrap_configuration():
+        assert spack.compilers.all_compiler_specs(init_config=False)
+    assert not spack.compilers.all_compiler_specs(init_config=False)
diff --git a/lib/spack/spack/test/cmd/compiler.py b/lib/spack/spack/test/cmd/compiler.py
--- a/lib/spack/spack/test/cmd/compiler.py
+++ b/lib/spack/spack/test/cmd/compiler.py
@@ -16,18 +16,6 @@
 compiler = spack.main.SpackCommand('compiler')
 
 
-@pytest.fixture
-def no_compilers_yaml(mutable_config):
-    """Creates a temporary configuration without compilers.yaml"""
-
-    for scope, local_config in mutable_config.scopes.items():
-        compilers_yaml = os.path.join(
-            local_config.path, scope, 'compilers.yaml'
-        )
-        if os.path.exists(compilers_yaml):
-            os.remove(compilers_yaml)
-
-
 @pytest.fixture
 def mock_compiler_version():
     return '4.5.3'
diff --git a/lib/spack/spack/test/conftest.py b/lib/spack/spack/test/conftest.py
--- a/lib/spack/spack/test/conftest.py
+++ b/lib/spack/spack/test/conftest.py
@@ -652,6 +652,15 @@ def mutable_empty_config(tmpdir_factory, configuration_dir):
         yield cfg
 
 
+@pytest.fixture
+def no_compilers_yaml(mutable_config):
+    """Creates a temporary configuration without compilers.yaml"""
+    for scope, local_config in mutable_config.scopes.items():
+        compilers_yaml = os.path.join(local_config.path, 'compilers.yaml')
+        if os.path.exists(compilers_yaml):
+            os.remove(compilers_yaml)
+
+
 @pytest.fixture()
 def mock_low_high_config(tmpdir):
     """Mocks two configuration scopes: 'low' and 'high'."""