Move flake scripts out of overlays
; fix format
script
#66
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Move flake scripts out from
overlays
The flake scripts themselves are fine and do presently work with the current merge through the use of overlays.
As I've learnt, this can be problematic however.
View the following for reference of what is explained below:
https://discourse.nixos.org/t/why-does-overlaying-check-with-nodepackages-prettier-cause-a-massive-rebuild/55810
When overlaying packages, if there is an existing package with the same name, this should either be avoided altogether or done with consideration to ensure it is a proper replacement.
check
for example, is an existing package innixpkgs
.Here a
check
overlay is defined, substituting it with thecheck
script derivation defined inflake.nix
. With he current batch of packages in the environment, nothing is affected fortunately. However, addingnodePackages.prettier
will cause a massive rebuild by Nix as there are many packages that are dependent on the originalcheck
package. Nix, doing the right thing, works to build what it needs. Although the final result will be what is expected, this is more a side effect.What is the point being argued here if the current implementation is working?
The big point is that this is a bad practice, since this is not what overlays were meant for. The same can be achieved by defining the packages anywhere else, and then referencing them as needed, rather than through overlays, which can cause unintended side effects, such as the one described.
Considering this is a repo that is very helpful particularly for beginners that may be new or not as experienced with the Nix ecosystem, presenting potential beginners to incorrect usage of overlays, can lead them to doing the same. Hence, the change here would be better in line with correct implementation. Someone visiting the repo hoping to implement helper script packages like here, could then reference this more "correct" implementation. Such as myself, who ended up following the previous implementation until I encountered the side effect explained in the post linked above.
The script derivations can really be defined anywhere, such as in a simple
let
binding, which I've done here. They will have gcroots linked so they won't be garbage collected, just like in the previous implementation.In the end, the resulting behavior remains entirely the same, just the implementation is corrected to avoid side effects and serveas an example of better practices.
This is to claim any sort of superiority or anything regarding the previous implementation, rather I was hoping to improve this to save others the headache of going down the rabbit hole that I myself did, as expressed in the linked post.
Many thanks.
Fix
format
scriptThe previous script was failing, as it was supposed to. It was trying to match a file named
'**/*.nix'
, ratherthan expanding the intended pattern.
Bash doesn't do shell expansion inside of quotes. It must be written unquoted, else
*
and other special characters are treated literally.'**/*.nix'
->**/*.nix
The new version will expand correctly.
Additionally, I've enabled
globstar
to make the expansion match all files ending with.nix
recursively, including the top level. Without this, the pattern will only match up one level.globstar
is documented here:https://www.gnu.org/software/bash/manual/html_node/The-Shopt-Builtin.html