Skip to content

Commit

Permalink
feat(flake): complete revamp with devenv/direnv
Browse files Browse the repository at this point in the history
Not perfect, and mostly a port of the previous edition. Hours have
already been sunk into this, and need to get this out for consumption,
and for ironing out.
For more information see: https://devenv.sh

NOTE: impure is used only because of the devenv-managed state, do not be
alarmed!
  • Loading branch information
xarvex committed Aug 25, 2024
1 parent e1b1ef9 commit cb4798b
Show file tree
Hide file tree
Showing 4 changed files with 691 additions and 115 deletions.
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
if ! has nix_direnv_version || ! nix_direnv_version 2.2.1; then
source_url 'https://raw.githubusercontent.com/nix-community/nix-direnv/2.2.1/direnvrc' 'sha256-zelF0vLbEl5uaqrfIzbgNzJWGmLzCmYAkInj/LNxvKs='
fi

watch_file flake.nix
watch_file flake.lock

if ! use flake . --impure; then
printf '%s\n' "devenv could not be built. The devenv environment was not loaded. Make the necessary changes to devenv.nix and hit enter to try again." >&2
fi
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -253,3 +253,6 @@ compile_commands.json
.TagStudio
TagStudio.ini
# End of https://www.toptal.com/developers/gitignore/api/visualstudiocode,python,qt

.direnv
.devenv
Loading

5 comments on commit cb4798b

@Rbon
Copy link

@Rbon Rbon commented on cb4798b Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a NixOS user (there are dozens of us!), I greatly appreciate the changes here. I had been trying for days to get TagStudio to even open, but now I can just run nix develop --impure and then python3 tagstudio/tag_studio.py and everything just works. Thank you very much for the work you put into this commit. It does not go unnoticed.

@xarvex
Copy link
Member Author

@xarvex xarvex commented on cb4798b Aug 25, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As a NixOS user (there are dozens of us!), I greatly appreciate the changes here. I had been trying for days to get TagStudio to even open, but now I can just run nix develop --impure and then python3 tagstudio/tag_studio.py and everything just works. Thank you very much for the work you put into this commit. It does not go unnoticed.

Thank you for the kind words! By the way, I'd recommend looking into direnv! This will automatically enable development environments when that .envrc file is present.

Home Manager has options for it:

programs.direnv = {
  enable = true;
  nix-direnv.enable = true; # Ensures things don't get garbage collected.
};

Lastly, I made a small script/alias that does the python command for you, just use tagstudio in your shell. Slightly less typing. ;)

I hope to improve upon this further, but things are already in a much better state. Thanks again for the appreciation!

@necauqua
Copy link

@necauqua necauqua commented on cb4798b Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As another NixOS user, I don't get the point of devenv being used here?.

You don't have any containers, and you do have the LD_LIBRARY_PATH hacks and the --impure and the extra .devenv folder thing because of it
Like the only benefit over native flake devShells is sligtly better syntax in a couple of places maybe I guess?

I'm pretty sure you don't need the watch_files unless devenv for some reason requires them?. Or maybe it's backwards compat for direnv versions that maybe didn't do that already for use_flake, okay

Also it's just a shell and not a full blown package, but I think I saw that you realise that and it's a bunch of work to get right as well and you already did infinitely more than I did anyway 😅

@xarvex
Copy link
Member Author

@xarvex xarvex commented on cb4798b Aug 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As another NixOS user, I don't get the point of devenv being used here?.

You don't have any containers, and you do have the LD_LIBRARY_PATH hacks and the --impure and the extra .devenv folder thing because of it Like the only benefit over native flake devShells is sligtly better syntax in a couple of places maybe I guess?

Actually, it does take care of Python shenanigans under the hood, be it pathing of Python itself and specifically to do with the virtual environment, which, in the previous iteration of the flake would require actions such as rm -rfing the directory. devenv takes care of that. These reasons and devenv's usage across the Nix ecosystem are why I did opt for the change here. See my next statement for how --impure will actually be able to be rid of, and LD_LIBRARY_PATH is expected to be resolved through languages.python.libraries where devenv handles wrapping just the python binary.

I'm pretty sure you don't need the watch_files unless devenv for some reason requires them?. Or maybe it's backwards compat for direnv versions that maybe didn't do that already for use_flake, okay

The .envrc is the recommended boilerplate from devenv, as seen here. It does seem like it has updated recently, actually to a stage where impure is no longer needed, so I will port that over in a moment here and see how things function, but is what I had used. I do see some differences though with the template from nix-direnv, so I will see about how that fares as well.

Also it's just a shell and not a full blown package, but I think I saw that you realise that and it's a bunch of work to get right as well and you already did infinitely more than I did anyway 😅

The packaging will take a bit longer to do for TagStudio as there are numerous pip dependencies that are not in the nixpkgs repos. That being said, I have seen some projects use devenv for its extra Python packages, so I am looking into if that covers things (or at the very least less work).

I hope that addresses your concerns.

@necauqua
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, thanks, that clarified things
I never packaged any python stuff for nix so I might've overlooked things, it's sad that native nixpkgs packaging is still lacking (it seems?) in that regard

Please sign in to comment.