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
{{ message }}
Repository navigation
Document conf.d / config.fish sourcing order #3099
So, the thing is, if you source conf.d after config.fish, that means that
Snippets can depend on config.fish
config.fish can't override snippets
If you do it the other way around, those two are going to be switched - config.fish can depend on snippets and override them, but snippets can't use config.fish stuff.
The tough question here is: What is less painful? What occurs more often? That snippets depend on config.fish, or that someone wishes to override snippets? It seems no matter which you pick there'll be some weirdness.
Then there's the issue that changing this would essentially require doing the snippets stuff in C++, since we don't have any script to hook it into (currently all stuff related to this is nicely encapsulated in share/config.fish).
So: What was your original issue with this? How'd you try to use it?
There is no config.fish requirement. You can move it over to conf.d if you so desire. I've just done so and it works.
The current situation is arguably more painful, only because it makes it impossible or very hard to have a unique entry point to configure some stuff.
No matter which order you pick, there is no "unique entry point". Either you configure something in config.fish and you don't see it because a snippet sets it (this would happen if config.fish before snippets, i.e. if we made this change), or you configure something in config.fish and a snippet can't use it (which is what happens now).
I'm quite wary of making it harder to override something a snippet does, because they can come from a variety of sources and might do something the user doesn't want - e.g. I could get a new snippet when I update some system package.
The only other thing I can come up with is making a "load-snippets" function that users can put into their ~/.config/fish/config.fish, and ship one that includes it by default.
I've currently worked around it by having a conf.d/000-env.fish instead that does all the stuff I want to set up in my environment. It gets executed first and everything works. I think that as long as there's a good and documented way for people to achieve ordering of conf.d entries I would actually be pretty happy to get rid of config.fish entirely. It also makes splitting up, modularising and having your configuration in VCS easier.
My current confusion stems from the fact that most shells have no concept of these kinds of snippets. As a consequence any behaviour like this basically comes down to sourcing the files in your .bashrc etc, allowing you to control order and avoiding surprises/ordering issues like these.
I think that as long as there's a good and documented way for people to achieve ordering of conf.d entries
That we can do. Do you have any wording suggestions? This uses the same sort function our completions use, which is a "natural" sort - so "1" < "2" < "2_b" < "02" < "3".
I'm not entirely sure what ordering to go for. The trick is to figure out what makes most sense when people are trying to debug why things aren't loading in the right order. When that happens I would personally prefer the order in which we process them to be more identical to what an ls -l or find . -type f would give me on that directory as that would make it more obvious in which order things happen and I wouldn't have to do the conversion between different sort orders myself. In both those cases the sort order is asciibetical, not natural.
However, if I'm just trying to figure out the order of things that are getting executed in my head I would result to natural/alphabetical order in my mental model, not asciibetical.
With regards to the ordering of conf.d first and then config.fish I think @faho is right and that order needs to be kept as is.
If we think about Fisherman plugins for example, when they ship configuration it all gets neatly loaded through conf.d snippets. However, if config.fish would get loaded first a plugin could override user defined behaviour and we'd take away the power of the user to fix that (though you could name a snippet in conf.d in such a way it would always get executed last). With config.fish being loaded last it can essentially function as a user's override file, without needing some explicit other mechanism or trickery to do so. It's only counter-intuitive because everyone's used to .bashrc and .zshrc and so on being the entrypoint for all configuration in the shell.
When that happens I would personally prefer the order in which we process them to be more identical to what an ls -l or find . -type f would give me on that directory
It's the same order as globs (because that's where the sorting happens).
Anyway, does anyone have any idea what the documentation should say? I'm struggling to come up with anything.
In most other shells the equivalent of config.fish would be the entrypoint where we start evaluating configuration. However in Fish config.fish gets evaluated last. This gives you the power to override behaviour or configuration that got added to your session by snippets in conf.d.
The order by which snippets in conf.d get evaluated is based on the file names using X sort order. This means that in order to set environment variables or configuration that other snippets might depend on you need to ensure that snippet gets executed as early as possible. You can achieve this by using a filename along the lines of 0-env.fish as that will guarantee it is evaluated first.
We should probably add an example or two about how the sort order works and how to fix things that aren't getting evaluated in the order the user expected.
In most other shells the equivalent of config.fish would be the entrypoint where we start evaluating configuration.
That is not true for any shell I've used in the past three decades. Certainly not sh, ksh, zsh, bash. From the bash man page:
When bash is invoked as an interactive login shell, or as a non-interactive shell with the --login option, it first reads and executes commands from the file /etc/profile, if that file exists. After reading that file, it looks for ~/.bash_profile, ~/.bash_login, and ~/.profile, in that order, and reads and exe- cutes commands from the first one that exists and is readable. The --noprofile option may be used when the shell is started to inhibit this behavior.
On operating systems where one can't get by by just guessing what ought to be on the path in case it is empty, we're not talking about restricting plugin functionality just a little bit— we're talking about restricting plugins to the point that they can never call external programs. This will affect all operating systems where the OS needs to be able to set the PATH variable (or any other, like library path variables or path variables for interpreted languages or whatever) before programs can find each other. That seems to me to defeat the purpose of even having an OS-level configuration file for fish.
If you go through with this plan, the only way to make fish plugins which dare to use even hostname or find work correctly on NixOS will be by patching $prefix/share/config.fish in the Fish source. And the thing is that it doesn't just break the plugins. The breakage can propagate to the whole shell, affecting login at every virtual console and preventing the display server from launching if the display manager service inherits its environment from the login shell.
Or you could permanently add more path hacking to $prefix/share/config.fish like you currently do for Darwin. :-\
I know having to implement this bit in the C++ code means generating more work for you and that my Linux distro is kind of marginal and non-standard. I hope I don't sound bratty here but this feels quite urgent for me because NixOS and fish are both part of trying to get the best Unix-like experience I can, even if it means having to take a little extra care and doing things a little differently sometimes. I hope that makes my case somewhat sympathetic.
Activity
faho commentedon Jun 1, 2016
So, the thing is, if you source conf.d after config.fish, that means that
If you do it the other way around, those two are going to be switched - config.fish can depend on snippets and override them, but snippets can't use config.fish stuff.
The tough question here is: What is less painful? What occurs more often? That snippets depend on config.fish, or that someone wishes to override snippets? It seems no matter which you pick there'll be some weirdness.
Then there's the issue that changing this would essentially require doing the snippets stuff in C++, since we don't have any script to hook it into (currently all stuff related to this is nicely encapsulated in share/config.fish).
So: What was your original issue with this? How'd you try to use it?
gretel commentedon Jun 1, 2016
i never really liked the idea of having a
config.fishat all. how aboutconfig.fishas a requirementconf.dand have deprecation noticeconf.d/config.fishwill be loaded first00_config.fishfaho commentedon Jun 1, 2016
There is no config.fish requirement. You can move it over to conf.d if you so desire. I've just done so and it works.
No matter which order you pick, there is no "unique entry point". Either you configure something in config.fish and you don't see it because a snippet sets it (this would happen if config.fish before snippets, i.e. if we made this change), or you configure something in config.fish and a snippet can't use it (which is what happens now).
I'm quite wary of making it harder to override something a snippet does, because they can come from a variety of sources and might do something the user doesn't want - e.g. I could get a new snippet when I update some system package.
The only other thing I can come up with is making a "load-snippets" function that users can put into their ~/.config/fish/config.fish, and ship one that includes it by default.
gretel commentedon Jun 1, 2016
@BRJ sure. but do rather propose solutions than backwards compatible changes 😸
@faho removing it is user behaviour, not what results of a default installation
daenney commentedon Jun 1, 2016
I've currently worked around it by having a
conf.d/000-env.fishinstead that does all the stuff I want to set up in my environment. It gets executed first and everything works. I think that as long as there's a good and documented way for people to achieve ordering ofconf.dentries I would actually be pretty happy to get rid ofconfig.fishentirely. It also makes splitting up, modularising and having your configuration in VCS easier.My current confusion stems from the fact that most shells have no concept of these kinds of snippets. As a consequence any behaviour like this basically comes down to sourcing the files in your
.bashrcetc, allowing you to control order and avoiding surprises/ordering issues like these.faho commentedon Jun 1, 2016
That we can do. Do you have any wording suggestions? This uses the same sort function our completions use, which is a "natural" sort - so "1" < "2" < "2_b" < "02" < "3".
gretel commentedon Jun 1, 2016
@faho hum.. good question. natural sort seems fine but for something automatic it is less determinable. going to have a read on asciibetical https://blog.codinghorror.com/sorting-for-humans-natural-sort-order/
daenney commentedon Jun 2, 2016
I'm not entirely sure what ordering to go for. The trick is to figure out what makes most sense when people are trying to debug why things aren't loading in the right order. When that happens I would personally prefer the order in which we process them to be more identical to what an
ls -lorfind . -type fwould give me on that directory as that would make it more obvious in which order things happen and I wouldn't have to do the conversion between different sort orders myself. In both those cases the sort order is asciibetical, not natural.However, if I'm just trying to figure out the order of things that are getting executed in my head I would result to natural/alphabetical order in my mental model, not asciibetical.
It's tricky.
daenney commentedon Jun 2, 2016
With regards to the ordering of
conf.dfirst and thenconfig.fishI think @faho is right and that order needs to be kept as is.If we think about Fisherman plugins for example, when they ship configuration it all gets neatly loaded through
conf.dsnippets. However, ifconfig.fishwould get loaded first a plugin could override user defined behaviour and we'd take away the power of the user to fix that (though you could name a snippet inconf.din such a way it would always get executed last). Withconfig.fishbeing loaded last it can essentially function as a user's override file, without needing some explicit other mechanism or trickery to do so. It's only counter-intuitive because everyone's used to.bashrcand.zshrcand so on being the entrypoint for all configuration in the shell.faho commentedon Jun 2, 2016
It's the same order as globs (because that's where the sorting happens).
Anyway, does anyone have any idea what the documentation should say? I'm struggling to come up with anything.
daenney commentedon Jun 2, 2016
Perhaps something like:
We should probably add an example or two about how the sort order works and how to fix things that aren't getting evaluated in the order the user expected.
krader1961 commentedon Jan 17, 2017
That is not true for any shell I've used in the past three decades. Certainly not sh, ksh, zsh, bash. From the bash man page:
therealpxc commentedon Mar 27, 2017
On operating systems where one can't get by by just guessing what ought to be on the path in case it is empty, we're not talking about restricting plugin functionality just a little bit— we're talking about restricting plugins to the point that they can never call external programs. This will affect all operating systems where the OS needs to be able to set the PATH variable (or any other, like library path variables or path variables for interpreted languages or whatever) before programs can find each other. That seems to me to defeat the purpose of even having an OS-level configuration file for fish.
If you go through with this plan, the only way to make fish plugins which dare to use even
hostnameorfindwork correctly on NixOS will be by patching $prefix/share/config.fish in the Fish source. And the thing is that it doesn't just break the plugins. The breakage can propagate to the whole shell, affecting login at every virtual console and preventing the display server from launching if the display manager service inherits its environment from the login shell.Or you could permanently add more path hacking to $prefix/share/config.fish like you currently do for Darwin. :-\
I know having to implement this bit in the C++ code means generating more work for you and that my Linux distro is kind of marginal and non-standard. I hope I don't sound bratty here but this feels quite urgent for me because NixOS and fish are both part of trying to get the best Unix-like experience I can, even if it means having to take a little extra care and doing things a little differently sometimes. I hope that makes my case somewhat sympathetic.
[-]Source user's config.fish before running conf.d snippets.[/-][+]Document conf.d / config.fish sourcing order[/+]Document snippet sourcing order
ranisalt commentedon Jan 13, 2018
hg42 commentedon Nov 4, 2019