You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The previous explanation was vague and meandering.
The new text is structured around the two use cases and their
disadvantages, so that it's easier to understand the context in which
the arguments are made.
The subjective arguments are largely replaced by concrete ones,
such as the accidental store copying risk and the difficulty of
version-controlling non-hermetic expressions.
Controls handling of absolute path literals (paths starting with `/`) and home path literals (paths starting with `~/`).
403
+
Controls the handling of absolute path literals (paths starting with `/`) and home path literals (paths starting with `~/`).
404
+
These may be considered antipatterns, as explained below.
405
+
406
+
Possible values:
404
407
405
408
- `ignore`: Ignore without warning (default)
406
409
- `warn`: Emit a warning about non-portability
407
410
- `fatal`: Treat as a parse error
408
411
409
-
It is true that some files are more difficult to reference with relative paths,
410
-
because they would require lots of `../../..` upward traversing to reach them.
411
-
But firstly, it is probably not a good idea to reference these files ---
412
-
such paths often make Nix expressions less portable and reproducible,
413
-
as they depend on the file system layout of the machine evaluating the expression.
412
+
There are two use cases for these literals.
413
+
- Specifying a location without reading its contents during evaluation, e.g. using `toString`
414
+
- Providing more sources for expressions and builds, e.g. using string interpolation
414
415
415
-
Secondly, with [pure evaluation mode](#conf-pure-eval), most such files are prohibited to access anyway,
416
-
whether by absolute or relative paths.
417
-
In that case, enabling this lint in fatal mode is less disruptive,
418
-
because the paths pure eval allows are usually not the ones that would be ergonomically expressed with absolute paths anyway.
419
-
)",
416
+
Absolute or home path literals have significant disadvantages for both use cases.
417
+
418
+
The simpler use case is specifying a location without reading its contents.
419
+
This comes with the risk of accidentally copying unintended files into the store, making a snapshot of those files readable by all system users.
420
+
This happens easily, because string interpolation (`"${some-path-value}"`) and some other operations blur the line between these two use cases: they implicitly convert the path value to a store path by copying its contents to the store.
421
+
Arguably, this makes path literals unfit for the simple string-like use case.
422
+
423
+
Additionally, a home path literal can make the home directory *location* of the evaluating user an implicit input to the evaluation, specifically when `toString` is called, e.g. `toString ~/.config`.
424
+
Evaluating on different accounts or machines will result in different derivations - an evaluation impurity.
425
+
426
+
Sometimes the intent is to read the file system contents at the path, as part of evaluation or instantiation.
427
+
In that case, using absolute or home path literals is undesirable for different reasons.
428
+
It requires that anyone who uses your expressions sets up more sources in those exact locations.
429
+
This is not a requirement that should normally be imposed on users, because it causes extra work, may not be possible to achieve for all users, or may conflict with their preferred file system layout.
430
+
Furthermore, it is non-hermetic, so it's difficult to version-control such expressions correctly.
431
+
A similar problem can be caused by upward relative path literals like `../../..`, which is not checked by this option, but by [pure evaluation mode](#conf-pure-eval).
432
+
433
+
[Pure evaluation mode](#conf-pure-eval) by itself also disallows home path literals, with a different error message.
434
+
It does not disallow absolute path literals, as it only restricts access to the *contents* of most file system locations.
0 commit comments