Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No windows path #2

Open
crramirez opened this issue Sep 5, 2021 · 8 comments
Open

No windows path #2

crramirez opened this issue Sep 5, 2021 · 8 comments

Comments

@crramirez
Copy link

Hello,

I was giving a look at your Gentoo build and I found that it doesn't have Windows Path appended:

image

I investigated a bit but I don't find the reason why it is not there. Even if I add:

[interop]
appendWindowsPath=true

It doesn't work

@imaandrew
Copy link
Owner

Huh that's strange. I don't know what causes the windows path to be appended but I'll take a look at other distros that do it and see if I can figure it out.

@crramirez
Copy link
Author

If I delete this file /etc/profile.env it gets fixed. The issue is related to /etc/profile

@imaandrew
Copy link
Owner

I'm trying to figure out what would be the best fix for this. I can't delete /etc/profile.env since it's recreated everytime env-update is run and that's called by the package manager. My best idea right now is to remove the PATH variable from /etc/env.d/50baselayout since that's where env-update gets it from and adding PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/opt/bin:${PATH}" to /etc/profile. The only problem is this would just prepend the path every time /etc/profile is sourced but I could probably add a check for that too.

@crramirez
Copy link
Author

You don't need to add the path to the profile. Check /etc/profile in Pengwin or Ubuntu you'll see an if not WSL then add the path.

@imaandrew
Copy link
Owner

Alright I'm a bit confused. I see the check for not running on WSL, but is there any time that check would actually pass? I assume microsoft will always be found in /proc/version

@crramirez
Copy link
Author

I think that the check won't ever pass even if you are root but I need to confirm that

@mikemol
Copy link

mikemol commented Sep 5, 2022

So, I ran into this in my Gentoo-on-WSL setup and found this issue while looking for a solution. For others' reference:

/etc/env.d/50baselayout is, indeed what env-update pulls from to generate /etc/profile.env. However, env-update is a python script, not a bash script, and doesn't interpolate constructions like "${SOME_OTHER_VAR}", so you can't do what I tried, which was add 49winpath with WINPATH="${PATH}" and 51winpath PATH=${PATH}:${WINPATH}; the resulting PATH you get after running env-update winds up ending with :${PATH}:${WINPATH}, because env-update dissects the PATH declarations and assembles a :-delimited PATH declaration of its own in /etc/profile.env.

It's also important to point out that the export PATH='...' that env-update emits into line uses ' instead of ", so you can't put any shell-interpreted strings there, either.

The only place I can see where you might plumb the Windows path through is in /etc/profile, where you can save off $PATH before sourcing /etc/profile.env, check /proc/version for WSL2 if desired, and then append your temporary back onto $PATH.

In all honesty, I wouldn't worry too much about multiple sourcings of /etc/profile; it doesn't seem to me like it's something that would happen in the normal course of events.

@mikemol
Copy link

mikemol commented Sep 5, 2022

In the end, this in /etc/profile served my purposes:

# Load environment settings from profile.env, which is created by
# env-update from the files in /etc/env.d
if [ -e /etc/profile.env ] ; then
        WINPATH=${PATH}
        . /etc/profile.env
        PATH="${PATH}:${WINPATH}"
fi

If I really cared, I could check if WINPATH already existed, and not reassign it if it did.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants