Skip to content

Commit e3f8a99

Browse files
committed
Elevate the Stack root to a specific topic
1 parent 8a88de8 commit e3f8a99

File tree

8 files changed

+172
-132
lines changed

8 files changed

+172
-132
lines changed

doc/GUIDE.md

Lines changed: 6 additions & 86 deletions
Original file line numberDiff line numberDiff line change
@@ -42,10 +42,11 @@ package will be built against.
4242

4343
Finally, Stack is __isolated__: it will not make changes outside of specific
4444
Stack directories. Stack-built files generally go in either the Stack root
45-
directory or `./.stack-work` directories local to each project. The Stack root
46-
directory holds packages belonging to snapshots and any Stack-installed versions
47-
of GHC. Stack will not tamper with any system version of GHC or interfere with
48-
packages installed by other build tools, such as Cabal (the tool).
45+
directory or `./.stack-work` directories local to each project. The
46+
[Stack root](stack_root.md) directory holds packages belonging to snapshots and
47+
any Stack-installed versions of GHC. Stack will not tamper with any system
48+
version of GHC or interfere with packages installed by other build tools, such
49+
as Cabal (the tool).
4950

5051
## Downloading and Installation
5152

@@ -807,7 +808,7 @@ The reason we have this structure is that:
807808
non-standard content into the shared snapshot database.
808809

809810
As you probably guessed, there can be multiple snapshot databases available. See
810-
the contents of the `snapshots` directory in the Stack root.
811+
the contents of the `snapshots` directory in the [Stack root](stack_root.md).
811812

812813
* On Unix-like operating systems, each snapshot is in the last of a sequence of
813814
three subdirectories named after the platform, a 256-bit hash of the source
@@ -1429,87 +1430,6 @@ configuration. It has no effect on projects at all. Every package you install
14291430
with it is put into isolated databases just like everywhere else. The only magic
14301431
is that it's the catch-all project whenever you're running Stack somewhere else.
14311432

1432-
## Setting the Stack root location
1433-
1434-
The Stack root is a directory where Stack stores important files. The location
1435-
and contents of the directory depend on the operating system and/or whether
1436-
Stack is configured to use the XDG Base Directory Specification.
1437-
1438-
The location of the Stack root can be configured by setting the `STACK_ROOT`
1439-
environment variable or using Stack's `--stack-root` option on the command line.
1440-
1441-
=== "Unix-like"
1442-
1443-
The Stack root contains snapshot packages; tools such as GHC, in a
1444-
`programs` directory; and Stack's global YAML configuration file
1445-
(`config.yaml`).
1446-
1447-
The default Stack root is `~/.stack`.
1448-
1449-
=== "Windows"
1450-
1451-
The Stack root contains snapshot packages; and Stack's global YAML
1452-
configuration file (`config.yaml`). The default location of tools such as
1453-
GHC and MSYS2 is outside of the Stack root.
1454-
1455-
The default Stack root is `%APPDIR%\stack`.
1456-
1457-
The default location of tools is `%LOCALAPPDATA%\Programs\stack`.
1458-
1459-
On Windows, the length of filepaths may be limited (to
1460-
[MAX_PATH](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd)),
1461-
and things can break when this limit is exceeded. Setting a Stack root with
1462-
a short path to its location (for example, `C:\sr`) can help.
1463-
1464-
=== "XDG Base Directory Specification"
1465-
1466-
On Unix-like operating systems and Windows, Stack can be configured to
1467-
follow the XDG Base Directory Specification if the environment variable
1468-
`STACK_XDG` is set to any non-empty value. However, Stack will ignore that
1469-
configuration if the Stack root location has been set on the command line or
1470-
the `STACK_ROOT` environment variable exists.
1471-
1472-
If Stack is following the XDG Base Directory Specification, the Stack root
1473-
contains what it would otherwise contain for the operating system, but
1474-
Stack's global YAML configuration file (`config.yaml`) may be located
1475-
elsewhere.
1476-
1477-
The Stack root is `<XDG_DATA_HOME>/stack`. If the `XDG_DATA_HOME`
1478-
environment variable does not exist, the default is `~/.local/share/stack`
1479-
on Unix-like operating systems and `%APPDIR%\stack` on Windows.
1480-
1481-
The location of `config.yaml` is `<XDG_CONFIG_HOME>/stack`. If the
1482-
`XDG_CONFIG_HOME` environment variable does not exist, the default is
1483-
`~/.config/stack` on Unix-like operating systems and `%APPDIR%\stack` on
1484-
Windows.
1485-
1486-
This approach treats:
1487-
1488-
* the project-level YAML configuration file that is common to all projects
1489-
without another such file in their project directory or its ancestor
1490-
directories as _data_ rather than as part of Stack's own
1491-
_configuration_;
1492-
1493-
* the snapshots database as essential data rather than as non-essential
1494-
data that would be part of a _cache_, notwithstanding that Stack will
1495-
rebuild that database as its contents are needed; and
1496-
1497-
* the Pantry store as essential data rather than as non-essential data
1498-
that would be part of a _cache_, notwithstanding that Stack will
1499-
download the package index and rebuild the store if it is absent.
1500-
1501-
The location of the Stack root is reported by command:
1502-
1503-
~~~text
1504-
stack path --stack-root
1505-
~~~
1506-
1507-
The full path of Stack's global YAML configuration file is reported by command:
1508-
1509-
~~~text
1510-
stack path --global-config
1511-
~~~
1512-
15131433
## `stack.yaml` versus Cabal files
15141434

15151435
Now that we've covered a lot of Stack use cases, this quick summary of

doc/build_command.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -554,9 +554,9 @@ All the following examples assume that:
554554
* if `stack build` is commanded outside of a project directory, there is no
555555
`stack.yaml` file in the current directory or ancestor directory and,
556556
consequently, the project-level configuration will be determined by a
557-
`stack.yaml` file in the `global-project` directory in the Stack root (for
558-
further information, see the [YAML configuration](yaml_configuration.md)
559-
documentation); and
557+
`stack.yaml` file in the `global-project` directory in the
558+
[Stack root](stack_root.md) (for further information, see the
559+
[YAML configuration](yaml_configuration.md) documentation); and
560560

561561
* if `stack build` is commanded in a project directory, there is a
562562
`stack.yaml` file in that directory.

doc/environment_variables.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,8 +76,8 @@ file (`config.yaml`).
7676
Overridden by: Stack's global
7777
[`--stack-root`](global_flags.md#-stack-root-option) option.
7878

79-
The environment variable `STACK_ROOT` can be used to specify the Stack root
80-
directory.
79+
The environment variable `STACK_ROOT` can be used to specify the
80+
[Stack root](stack_root.md) directory.
8181

8282
## `STACK_WORK`
8383

doc/global_flags.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ Restrictions: POSIX systems only
1313

1414
Default: True, if inside Docker; false otherwise
1515

16-
Enable/disable permitting users other than the owner of the Stack root directory
17-
to use a Stack installation. For further information, see the documentation for
18-
the corresponding non-project specific configuration
19-
[option](yaml_configuration.md#allow-different-user).
16+
Enable/disable permitting users other than the owner of the
17+
[Stack root](stack_root.md) directory to use a Stack installation. For further
18+
information, see the documentation for the corresponding non-project specific
19+
configuration [option](yaml_configuration.md#allow-different-user).
2020

2121
## `--arch` option
2222

@@ -212,7 +212,8 @@ specific configuration [option](yaml_configuration.md#stack-colors).
212212
Overrides: `STACK_ROOT` environment variable
213213

214214
Pass the option `--stack-root <absolute_path_to_the_Stack_root>` to specify the
215-
path to the Stack root directory. The path must be an absolute one.
215+
path to the [Stack root](stack_root.md) directory. The path must be an absolute
216+
one.
216217

217218
## `--stack-yaml` option
218219

doc/stack_root.md

Lines changed: 119 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,119 @@
1+
<div class="hidden-warning"><a href="https://docs.haskellstack.org/"><img src="https://cdn.jsdelivr.net/gh/commercialhaskell/stack/doc/img/hidden-warning.svg"></a></div>
2+
3+
# Stack root location
4+
5+
The Stack root is a directory where Stack stores important files. The location
6+
and contents of the directory depend on the operating system, whether
7+
Stack is configured to use the XDG Base Directory Specification, and/or
8+
whether an alternative location to Stack's default 'programs' directory has
9+
been specified.
10+
11+
The location of the Stack root can be configured by setting the
12+
[`STACK_ROOT`](environment_variables.md#stack_root) environment variable or
13+
using Stack's [`--stack-root`](global_flags.md#stack-root-option) option on the
14+
command line.
15+
16+
=== "Unix-like"
17+
18+
The Stack root contains snapshot packages; (by default) tools such as GHC,
19+
in a `programs` directory; Stack's global
20+
[YAML configuration](yaml_configuration.md#yaml-configuration) file
21+
(`config.yaml`); and Stack's
22+
[`global-projects`](yaml_configuration.md#yaml-configuration) directory.
23+
24+
The default Stack root is `~/.stack`.
25+
26+
=== "Windows"
27+
28+
The Stack root contains snapshot packages; Stack's global
29+
[YAML configuration](yaml_configuration.md#yaml-configuration) file
30+
(`config.yaml`); and Stack's
31+
[`global-projects`](yaml_configuration.md#yaml-configuration) directory. The
32+
default location of tools such as GHC and MSYS2 is outside of the Stack
33+
root.
34+
35+
The default Stack root is `%APPDIR%\stack`.
36+
37+
If the `LOCALAPPDATA` environment variable exists, the default location of
38+
tools is `%LOCALAPPDATA%\Programs\stack`. Otherwise, it is the `programs`
39+
directory in the Stack root.
40+
41+
!!! warning
42+
43+
If there is a space character in the `%LOCALAPPDATA%` path (which may be
44+
the case if the relevant user account name and its corresponding user
45+
profile path have a space) this may cause problems with building
46+
packages that make use of the GNU project's `autoconf` package and
47+
`configure` shell script files. That may be the case particularly if
48+
there is no corresponding short name ('8 dot 3' name) for the directory
49+
in the path with the space (which may be the case if '8 dot 3' names
50+
have been stripped or their creation not enabled by default). If there
51+
are problems building, it will be necessary to override the default
52+
location of Stack's 'programs' directory to specify an alternative path
53+
that does not contain space characters. Examples of packages on
54+
Hackage that make use of `configure` are `network` and `process`.
55+
56+
On Windows, the length of filepaths may be limited (to
57+
[MAX_PATH](https://docs.microsoft.com/en-us/windows/win32/fileio/maximum-file-path-limitation?tabs=cmd)),
58+
and things can break when this limit is exceeded. Setting a Stack root with
59+
a short path to its location (for example, `C:\sr`) can help.
60+
61+
=== "XDG Base Directory Specification"
62+
63+
On Unix-like operating systems and Windows, Stack can be configured to
64+
follow the XDG Base Directory Specification if the environment variable
65+
`STACK_XDG` is set to any non-empty value. However, Stack will ignore that
66+
configuration if the Stack root location has been set on the command line or
67+
the `STACK_ROOT` environment variable exists.
68+
69+
If Stack is following the XDG Base Directory Specification, the Stack root
70+
contains what it would otherwise contain for the operating system, but
71+
Stack's global YAML configuration file (`config.yaml`) may be located
72+
elsewhere.
73+
74+
The Stack root is `<XDG_DATA_HOME>/stack`. If the `XDG_DATA_HOME`
75+
environment variable does not exist, the default is `~/.local/share/stack`
76+
on Unix-like operating systems and `%APPDIR%\stack` on Windows.
77+
78+
The location of `config.yaml` is `<XDG_CONFIG_HOME>/stack`. If the
79+
`XDG_CONFIG_HOME` environment variable does not exist, the default is
80+
`~/.config/stack` on Unix-like operating systems and `%APPDIR%\stack` on
81+
Windows.
82+
83+
This approach treats:
84+
85+
* the project-level YAML configuration file that is common to all projects
86+
without another such file in their project directory or its ancestor
87+
directories as _data_ rather than as part of Stack's own
88+
_configuration_;
89+
90+
* the snapshots database as essential data rather than as non-essential
91+
data that would be part of a _cache_, notwithstanding that Stack will
92+
rebuild that database as its contents are needed; and
93+
94+
* the Pantry store as essential data rather than as non-essential data
95+
that would be part of a _cache_, notwithstanding that Stack will
96+
download the package index and rebuild the store if it is absent.
97+
98+
An alternative to the default location of tools such as GHC can be specified
99+
with the [`local-programs-path`](yaml_configuration.md#local-programs-path)
100+
configuration option.
101+
102+
The location of the Stack root is reported by command:
103+
104+
~~~text
105+
stack path --stack-root
106+
~~~
107+
108+
The full path of Stack's global YAML configuration file is reported by command:
109+
110+
~~~text
111+
stack path --global-config
112+
~~~
113+
114+
The location of tools such as GHC for the current platform is reported by
115+
command:
116+
117+
~~~text
118+
stack path --programs
119+
~~~

0 commit comments

Comments
 (0)