commercialhaskell / commercialhaskell/stack

`stack --nix --nix-help` does not work

Open
#5,311 1 comment 0 reactions 0 assignees View on GitHub
type: enhancement
Dominant language
Haskell
Stars
4.1k
Forks
850
Avg merge
10h 37m
Merged PRs (30d)
4

Description

### Steps to reproduce

`stack --nix-help` isn't useful at all when used with some `--nix` options, e.g.:

```shell
$ stack --nix --nix-help
Run 'stack --nix-help' for details.
$ stack --no-nix-pure --nix-help
Run 'stack --nix-help' for details.
```

I suspect this is a problem with any `--nix` or `--no-nix` option.

You might wonder "Why would you pass some `--nix` flags if you want the help for Nix flags?". Well, I see 2 reasons:
* While one is toying with nix options in CLI and little by little, adding some, one wants to find out what other options may be used
* One uses a shell wrapper for Stack to pre-configure all Nix flags without relying on a global, computer-specific installation of the `nixpkgs` channel, and wants to use `--nix-help` with it.

I am currently in the second category, though I also encountered this issue when in the first.

More generally, shouldn't all other flags be ignored when using either `--help` or `--nix-help`? As a user that's the behavior I expect, though it may be an invalid intuition on my part :sweat_smile:

When using such a shell, it's impossible to display the `nix-help` section.
We have to quit the shell, run another shell `nix-shell -p stack` and then we have to run `stack --nix-help`.

### Expected

```shell
$ stack --nix --nix-help
Usage: stack [--[no-]nix] [--[no-]nix-pure] [--nix-packages NAMES]
[--nix-shell-file FILE] [--nix-shell-options OPTIONS]
[--nix-path PATH_OPTIONS] [--[no-]nix-add-gc-roots] OTHER ARGUMENTS
Only showing --nix* options.

Available options:
--[no-]nix Enable/disable use of a Nix-shell. Implies
'system-ghc: true'
--[no-]nix-pure Enable/disable use of a pure Nix-shell. Implies
'--nix' and 'system-ghc: true'
--nix-packages NAMES List of packages that should be available in the
nix-shell (space separated)
--nix-shell-file FILE Nix file to be used to launch a nix-shell (for
regular Nix users)
--nix-shell-options OPTIONS
Additional options passed to nix-shell
--nix-path PATH_OPTIONS Additional options to override NIX_PATH parts
(notably 'nixpkgs')
--[no-]nix-add-gc-roots Enable/disable addition of packages to the nix GC
roots so nix-collect-garbage doesn't remove them
(default: disabled)
```

### Actual

```shell
$ stack --nix --nix-help --verbose
Run 'stack --nix-help' for details.
$ stack --no-nix-pure --nix-help --verbose
Run 'stack --nix-help' for details.
```

### Stack version

```
$ stack --version
2.1.3.1 x86_64 hpack-0.33.0
```

### Method of installation

Through Nix (nixpkgs), commit 571212eb839d482992adb05479b86eeb6a9c7b2f

We have a `shell.nix` that configures many things for our project, and we want this shell to also configure nicely Stack, as such:
```nix
# shell.nix
with import (builtins.fetchTarball {
name = "nixpkgs-unstable-2020-05-22";
url = https://github.com/nixos/nixpkgs/archive/571212eb839d482992adb05479b86eeb6a9c7b2f.tar.gz;
sha256 = "0ncsh5rkjbcdaksngmn7apiq1qhm5z1z6xa1x70svxq91znibp4f";
}) {};

let
stack-wrapped = symlinkJoin {
name = "stack";
paths = [ stack ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/stack \
--add-flags "\
--nix \
--no-nix-pure \
--nix-shell-file nix/stack-integration.nix \
"
'';
};
in
mkShell {
buildInputs = [ stack-wrapped ];
MY_ENV_VARIABLE = "my value";
}
```

Cheers, and let me know if I have to provide additional information!

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.