romkatv / gitstatus

Git status for Bash and Zsh prompt
GNU General Public License v3.0
1.69k stars 106 forks source link

Use `gitstatus` from PATH as fallback #7

Closed colemickens closed 5 years ago

colemickens commented 5 years ago

Hello,

due to how NixOS works, pre-built binaries aren't really usable. I am building gitstatusd from source and would like the ZSH plugin to use it automatically.

Right now I'd doing this as a workaround:

rm -rf ~/powerlevel10k/gitstatus/bin
mkdir -p ~/powerlevel10k/gitstatus/bin
ln -s /run/current-system/sw/bin/gitstatusd ~/powerlevel10k/gitstatus/bin/gitstatus-linux-x86_64
romkatv commented 5 years ago

I'm not sure how the fallback will work. Given what uname returns, gitstatus thinks it has a binary that will work. It could try looking for gitstatusd in the PATH first, but this runs the risk of running zsh and native code that are out of sync.

You can define GITSTATUS_DAEMON to point to the binary. Does that work for you?

By the way, if I build a binary on NixOS (as statically linked as possible), will it work on all NixOS instances, or are they all so unique that you have to compile on every machine?

colemickens commented 5 years ago

You can define GITSTATUS_DAEMON to point to the binary. Does that work for you?

Yes, that will definitely work. Ah, it's already there, great!

By the way, if I build a binary on NixOS (as statically linked as possible), will it work on all NixOS instances, or are they all so unique that you have to compile on every machine?

With Nix and a given nixpkgs checkout, one gets reproducible (*) binaries, via simple build commands-- nix-build -A gitstatusd for example. for a given nixpkgs checkout. For example, now that I am building it as part of my system config, I am incidentally gitstatusd against nixos-unstable (a git tag of nixpkgs that is updated on some CI-driven cadence), and even pushing it to a cachix.org cache.

For users to get your binary, they need to teach their system about gitstatus. Most packages on a users system comes from the nixpkgs mono-repo. I maintain a couple "overlay" package sets for wayland users, and for things that I use. These allow users to reference my "overlay" and gain access to the packages that I curate/maintain.

For NixOS users, the minimum required is getting a way for the user to access the package definition. Once they have that and a given nixpkgs checkout, their system will either find the pre-built binary in a cache (maybe gitstatus.cachix.org) or it will just go ahead and build it. Since it's such a small binary and Nix takes care of the build, you might not bother with pushing to cachix.

I'll push my config in a minute and you can get a bit of a hands-on glimpse of how Nix works. This actually provides a really cool example since I needed to swap out libgit2 for your patched copy.

I'll close this for now since my issue is resolved, but I'll also follow up with a link to my config.

romkatv commented 5 years ago

Thanks for the explanation. This sounds super cool!

thepigeonoftime commented 5 years ago

@colemickens any chance you could post your build steps for gitstatusd? I'm new to NixOS and having trouble to have CMake find the required libraries (despite setting the env vars it complains about) and correctly link libgit2.a:

-- Could NOT find HTTP_Parser (missing: HTTP_PARSER_INCLUDE_DIR)  
-- LIBSSH2 not found. Set CMAKE_PREFIX_PATH if it is installed outside of the default search path

until it fails at:

[100%] Linking C static library ../libgit2.a  
Error running link command: No such file or directory  
make[2]: *** [src/CMakeFiles/git2.dir/build.make:394: libgit2.a] Error 2  
make[1]: *** [CMakeFiles/Makefile2:95: src/CMakeFiles/git2.dir/all] Error 2  
romkatv commented 5 years ago

I don't recommend invoking cmake with any combination of flags other than the one I'm using in build.zsh. It's the only configuration I'm testing.

By the way, what errors do you get if you try to build gitstatus following the documented instructions? Is it possible to change the build script so that it works on NixOS?

I tried to test this myself in a docker image but gave up after 15 minutes of struggling to compile "hello world" with gcc.

romkatv commented 5 years ago

I managed to get it working. The default build script works without any changes. Here's what I did:

docker run -e LANG=C.UTF-8 -e LC_ALL=C.UTF-8 -e TERM=$TERM -it --rm nixos/nix sh -uexc '
  cd
  nix-channel --add https://nixos.org/channels/nixpkgs-unstable nixpkgs
  nix-channel --update
  nix-env -i zsh curl git gcc cmake gnumake gcc-wrapper
  nix-env --set-flag priority 0 gcc-wrapper
  nix-env -i binutils
  zsh -c "$(curl -fsSL https://raw.githubusercontent.com/romkatv/gitstatus/master/build.zsh)"
  mv /tmp/gitstatus/gitstatus/bin/gitstatusd-linux-x86_64 gitstatusd
  git clone https://github.com/romkatv/powerlevel10k.git
  curl -fsSLO https://raw.githubusercontent.com/romkatv/dotfiles-public/master/.purepower
  echo "GITSTATUS_DAEMON=~/gitstatusd" >> .zshrc
  echo "PURE_POWER_MODE=portable source ~/.purepower" >> .zshrc
  echo "source ~/powerlevel10k/powerlevel10k.zsh-theme" >> .zshrc
  cd powerlevel10k
  zsh -i'

This builds gitstatusd and installs Powerlevel10k with Pure Power styling. It seems to work fine.

I'm sure the "nix" commands aren't the right way to do this but hopefully you can see what's being done and translate as necessary.

thepigeonoftime commented 5 years ago

@romkatv That did the trick. Thanks!