Skip to content

stack query generates a .cabal file as side effect #6780

Open

Description

@andreasabel

Running stack query, e.g. stack query compiler will create a .cabal file from package.yaml if such .cabal file does not exist yet.

Reproducer: create a directory with e.g. these two files:
stack.yaml

resolver: lts-22.44

package.yaml

name: stack-query-created-me
library:
  source-dirs: .

Then ask stack for the GHC version of the project:

$ stack query compiler actual                                                           
ghc-9.6.7

And, oops!, you have given birth to a new .cabal file:

$ ls *.cabal
stack-query-created-me.cabal

I am using the latest Stack (3.7.1):

$ stack --version                                                                      1 х │ ghc-9.6.7 hs │ 16:32:09 
Version 3.7.1, Git revision 331f4880f1a33f1d39e14317dc9ecc6d3d6d617d aarch64 hpack-0.38.1

I got here because I am using the zsh Powerlevel 10k prompt, and I was wondering why .cabal files were mysteriously appearing on my file system:

Activity

  1. mpilgrem commented on Aug 7, 2025

    @mpilgrem
    Member

    Yes, that is correct. stack query runs within a withBuildConfig withEnvConfig and like other similar Stack commands (for example stack build --dry-run) that involves configuring the build environment.

    Stepping back, what information is being sought? If it is not build information, then there may be a better 'home' for that functionality than stack query.

  2. andreasabel commented on Aug 8, 2025

    @andreasabel
    Author

    Stepping back, what information is being sought?

    Yeah, I don't really know. This Powerlevel 10k prompt displays all kinds of useful information on the environment of the current directory (git branch name etc.), so I guess they thought, why not print the GHC version if there is a stack.yaml present in the project?

    That a command named query writes new files to the local directory must be very surprising to anyone who is not an implementer of stack.
    So I think there should be prominent alerts in the documentation and also in the help text:

    $ stack query --help                                                       
    Usage: stack query [SELECTOR...] [--setup-info-yaml URL] 
                       [--snapshot-location-base URL]
    
      Query general build information (experimental).
    
    Available options: ...
    

    The expected behavior of stack query compiler would be that it extracts the resolver/snapshot from the stack.yaml file, computes the ghc version from this and prints it.
    Apparently just a stack.yaml is not enough:

    $ stack query compiler                                                                                         
    
    Error: [S-636]
           Stack looks for packages in the directories configured in the packages and extra-deps fields defined in its project-level configuration file (usually
           stack.yaml). The current entry points to /Users/abela/tmp/stack-query-compiler-no-package-yaml/ but no Cabal file or package.yaml could be found there.
    

    I think at this point it might be enough to add the alert to the documentation, to make potential users of the stack query command aware of the consequences.
    I suppose the authors of the shell prompt would have refrained from adding a hook for stack if they had known about the consequences of running stack query.

  3. mpilgrem commented on Aug 8, 2025

    @mpilgrem
    Member

    @andreasabel, there is a nuance to 'compiler' information: 'wanted' versus 'actual'. 'Wanted' is what is specified in the project-level configuration file and at the command line. 'Actual' is what is used. They can differ because of compiler-check options.

    A BuildConfig value has information about 'wanted' (via its smWanted field).

    A EnvConfig value also has information about 'actual' (via its sourceMap field).

    I think it would be straightforward to add a stack ls compiler command that output the 'wanted' compiler but did not configure the build environment.

  4. andreasabel commented on Aug 9, 2025

    @andreasabel
    Author

    I think it would be straightforward to add a stack ls compiler command that output the 'wanted' compiler but did not configure the build environment.

    Good.
    I am not in a position to request this feature, though, as I do not have an application for it right now, and the "Powerlevel 10k" folks might not be actively developing their product anymore, given the disclaimer on their github repo.

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

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions