JanDeDobbeleer / oh-my-posh

The most customisable and low-latency cross platform/shell prompt renderer
https://ohmyposh.dev
MIT License
17.38k stars 2.39k forks source link

Not working on NixOS, might be due to a hardcoded path sowewhere? #784

Closed isti115 closed 2 years ago

isti115 commented 3 years ago

Prerequisites

Description

I installed NixOS with powershell as my default shell today, posh-git works fine, but this module gives the following error message:

PowerShell 7.1.3
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

~> Set-PoshPrompt -Theme agnoster
ResourceUnavailable: /home/isti/.local/share/powershell/Modules/oh-my-posh/3.162.0/oh-my-posh.psm1:70
Line |
  70 |      (& $poshCommand --init --shell=pwsh --config="$config") | Invoke- …
     |      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Program 'posh-linux-amd64' failed to run: No such file or directoryAt
     | /home/isti/.local/share/powershell/Modules/oh-my-posh/3.162.0/oh-my-posh.psm1:70 char:6 +     (& $poshCommand --init --shell=pwsh --config="$config") | Invoke- … +      ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~.

~>

While trying to figure this out I also noticed that running the file directly from the shell gives a similar error:

~/.local/share/powershell/Modules/oh-my-posh/3.162.0/bin> ./posh-linux-amd64
ResourceUnavailable: Program 'posh-linux-amd64' failed to run: No such file or directoryAt line:1 char:1
+ ./posh-linux-amd64
+ ~~~~~~~~~~~~~~~~~~.

which after reading a bit about it online gives the impression of a hardcoded shebang path or something like that.

Sh and Bash straight up claim that the file doesn't even exist:

[isti@libra:~/.local/share/powershell/Modules/oh-my-posh/3.162.0/bin]$ ./posh-linux-amd64
bash: ./posh-linux-amd64: No such file or directory

Paths are VERY different in NixOS, so I tried symlinking the executable from the store to /bin/pwsh and /usr/bin/pwsh, but that didn't solve the issue. I guess that NixOS is kind of supported, since there is an icon for it in the code, so it has probably already worked at some point.

Environment

Optional

Steps to Reproduce

  1. Install NixOS with powershell
  2. Install this module
  3. Try to load a theme

Expected behavior: The theme should be loaded

Actual behavior: I get the error message presented above.

JanDeDobbeleer commented 3 years ago

@Isti115 the icon in the code is for displaying the OS, not necessarily related to it being supported although it should work nonetheless. According to the module that file is included, and paths aren't hardcoded due to obvious reasons 😅. Unless Powershell is having a hard time when it comes to those paths (they don't seem weird to me), we'll need to have a look at what's happening. If you run Get-ChildItem "$((Get-Module oh-my-posh).ModuleBase)/bin", what do you see?

isti115 commented 3 years ago

Thanks for the quick response! I get what I would assume is the desired output:

~> Get-ChildItem "$((Get-Module oh-my-posh).ModuleBase)/bin"

    Directory: /home/isti/.local/share/powershell/Modules/oh-my-posh/3.162.0/bin

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-----            6/5/2021  1:19 PM       17472952 posh-darwin-amd64
-----            6/5/2021  1:19 PM       16504842 posh-linux-amd64
-----            6/5/2021  1:19 PM       14722682 posh-linux-arm
-----            6/5/2021  1:19 PM       15443968 posh-windows-386.exe
-----            6/5/2021  1:19 PM       16897536 posh-windows-amd64.exe

~>
JanDeDobbeleer commented 3 years ago

Yes. Meaning the file is there. Let me try to reproduce this, but I need to set up a VM in that case.

JanDeDobbeleer commented 3 years ago

@Isti115 binaries don't don't work by default on Nix so that's the issue. Starship has a separate package for example specifically for Nix, so we'll need to look at that (or patch the binary).

isti115 commented 3 years ago

Wow, thanks for digging into this as deep as setting up a VM! :) Now that you mention it I recall that I have also heard about the binary incompatibility earlier, I was just too tunnelvisioned on the weird paths after finding that first answer for this type of error. This implies that if I build it myself from source, it should work, right? I'll try to give that a go!

isti115 commented 3 years ago

After cloning and setting up go, building and overwriting the binary it now works beautifully! :tada:

(Man, this piece of software is so awesome, I just realized it again after missing my custom theme with icons for path locations, indicator for ranger / lf level and such for two days! Thank you very much for the development of this great customizable and extensible utility!)

[I don't exactly know what combination of commands I used after several failed attempts at go run main.go and such, since this was my first time using Go and I had no idea how dependecies and includes are handled, but something like this should work for anyone who wishes to replicate the successful steps in the future:

nix-env -iA nixos.go
git clone git@github.com:JanDeDobbeleer/oh-my-posh.git
cd ./oh-my-posh/src/
go build .
cp ./oh-my-posh ~/.local/share/powershell/Modules/oh-my-posh/3.162.0/bin/posh-linux-amd64

ps.: In case you have a newer version, make sure to update the numer in the path!]

JanDeDobbeleer commented 3 years ago

I'll add the manual steps on how to compile to the docs. You don't need to use the module in this case, you can simply follow the nix guide and use the executable.

ShrykeWindgrace commented 3 years ago

While we are on the subject of nix, one can also pull oh-my-posh via this nix derivation: https://gitlab.com/ShrykeWindgrace/powershell-modules/-/tree/master/oh-my-posh and then modify $env:PSModulePath accordingly. Pardon my self-promotion=)

brwilkinson commented 3 years ago

I noticed the same issue in GitHub CodeSpaces.

using: mcr.microsoft.com/vscode/devcontainers/dotnet:5.0

Linux codespaces_89ccbb 5.4.0-1055-azure #57ü18.04.1-Ubuntu SMP Fri Jul 16 19:40:19 UTC 2021 x86_64 x86_64 x86_64 GNU/Linux

JanDeDobbeleer commented 2 years ago

As the module is no longer available, this is solved by installing via homebrew.

github-actions[bot] commented 10 months ago

This issue has been automatically locked since there has not been any recent activity (i.e. last half year) after it was closed. It helps our maintainers focus on the active issues. If you have found a problem that seems similar, please open a discussion first, complete the body with all the details necessary to reproduce, and mention this issue as reference.