Flox
Table of Contents
Learn about flox here flox docs
1. some general stuff
Flox is a super useful tool ! It lets you create environments with installed software via flox init
, and then acts as a package manager where you just do flox install
for example flox install firefox
. Yes with it you can install a lot of software including browsers libraries such as webkit2gtk and more. It’s a sort of wrapper around Nix from what I understand and simplifies it a ton.
It’s almost like using containers for development environments, but also better because you dont deal with containers which are from my experience awkward to deal with.
For every different language I use (or something like that) I create a directory in a root directory called devenvs.
devenvs ├── XUL ├── d ├── python └── website
Then in each I have a seperate flox environment.
This tool can be very nicely integrated with another one called direnv. There is an article about it on the flox blog.
My setup is pretty much the same, with an exception that I installed direnv normally via my host package manager, then simply added
direnv hook fish | source
and this fish function, which is quite important to see that flox environment is active in fish shell. When writing this there was no mode prompt when loading flox via direnv !
This is also generally an important function for me, to know what is active as you can see I also manage micromamba mode prompt via this.
function fish_mode_prompt --on-variable FLOX_ENV_DESCRIPTION set my_prompt "" if test $FLOX_ENV_DESCRIPTION set my_prompt (string join '' -- (set_color purple) "f," $FLOX_ENV_DESCRIPTION) end if test $CONDA_DEFAULT_ENV set my_prompt (string join (set_color white) "" -- $my_prompt "|" (string join '' -- (set_color 008080) "u," $CONDA_DEFAULT_ENV)) end if test $my_prompt set my_prompt (string join "" -- $my_prompt " ") end echo $my_prompt end
finally I can create my .envrc file which from what I understand is simply just a bash script that gets executed on entry to a directory.
so you basically echo 'use flox' > .envrc
the use flox thing is basically some function that you installed in your .config/direnv in one of the steps in the aformentioned flox blog post.
Then since this is just a bash script you can do a lot like exporting vairables etc.
However since it is bash and I prefer to use fish, is kind of annoying for example to activate mamba environment I must eval "$(micromamba shell hook --shell=bash)"
note the bash here even though I use fish. Of course this breaks the mode prompt so I must define it myself, which is fine because I like doing stuff myself xD.
Another very important thing is that you can do this.
source_up
in the .envrc
this will make it so that the .envrc in one of the previous directories also gets activated, very nice for my usecase, because then I simply load language specific and project specific config at once ! very cool !
2. Dlang, webkit2gtk, and flox
Recently I have been teaching myself bit of D (dlang) So I created such a flox environment for that. It worked great until for a stupid reason I started to develop a webview webkit2gtk app there. I ran into a ton of issues. Perhaps some day someone finds this useful. I think it taught me quite a lot about how nix works in general.
The issue was that dub and dmd were using c compilers which were installed as a dependency for dub/dmd. This lead to the use of those compilers and my host webkit2gtk library and also I initially didnt realise that I had to install webview on my host in order for dlang webview library to work (this wasnt the case with golang). So it was quite a messy situation.
So what resolved it in the end (perhaps there is a better way) was the following. Very simple just use everything from host. I mean this probably goes against the philosophy of Nix, but works, and every linux computer has that already installed so who cares.
Installed webview on host by cloning their git repo, and installed it. (no nix package for that) https://gothub.lunar.icu/webview/webview
I added this in my dub.json
"lflags": [ "-L/usr/lib/" ], "libs": [ "webview", "webkit2gtk-4.1" ],
And added this to my .envrc of the project
export LD_LIBRARY_PATH=/home/hebbian/devenvs/d/emacs-sketch/libwebview/ export XDG_DATA_DIRS=/usr/share/ export CC=/usr/bin/gcc export CXX=/usr/bin/gcc
and then I think it worked. Hopefully I didnt forget anything.