Nix development environment? #766

Closed
opened 2023-10-05 13:58:32 +00:00 by pizzapim · 4 comments
Contributor

I recently learned Nix (https://nixos.org/) and to work on the project, I created a Nix development environment which worked great for me. Perhaps it might be worth adding support for it, or just putting it in documentation? I uploaded the code on this branch: https://projects.torsion.org/pizzapim/borgmatic/src/branch/nix-dev-env

The idea is as follows: direnv (https://direnv.net/) automatically activates some environment which is specified in the .envrc file. This file in turn says to activate a Nix shell specified in the flake.nix file. This Nix shell makes some programs available (Python 3.11, borgbackup) and Python libraries (apprise, pipx, tox, etc.) in an ephemeral shell. If you move out of this directory, the shell is unloaded are not longer available.

I recently learned Nix (https://nixos.org/) and to work on the project, I created a Nix development environment which worked great for me. Perhaps it might be worth adding support for it, or just putting it in documentation? I uploaded the code on this branch: https://projects.torsion.org/pizzapim/borgmatic/src/branch/nix-dev-env The idea is as follows: direnv (https://direnv.net/) automatically activates some environment which is specified in the `.envrc` file. This file in turn says to activate a Nix shell specified in the `flake.nix` file. This Nix shell makes some programs available (Python 3.11, borgbackup) and Python libraries (apprise, pipx, tox, etc.) in an ephemeral shell. If you move out of this directory, the shell is unloaded are not longer available.
Owner

Pull requests welcome! 😄 I don't know much about NixOS, but the only issue I see is that a particular NixOS version and a particular Python version are encoded in that flake.nix file. So that would just need to be kept up-to-date or somehow parameterized.

A question though: In this ephemeral shell, are state files like .tox left behind.. or deleted after use? Because if those are ephemeral too, then you'll have to recreate your Tox environment every time you work on borgmatic. Honestly, not the worst thing in the world, and it might actually be kind of useful so you don't have to know when to run tox -r manually...

If this were to get merged into borgmatic, I think there should be at least a mention on the borgmatic dev documentation page: https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/

Pull requests welcome! 😄 I don't know much about NixOS, but the only issue I see is that a particular NixOS version and a particular Python version are encoded in that flake.nix file. So that would just need to be kept up-to-date or somehow parameterized. A question though: In this ephemeral shell, are state files like `.tox` left behind.. or deleted after use? Because if those are ephemeral too, then you'll have to recreate your Tox environment every time you work on borgmatic. Honestly, not the worst thing in the world, and it might actually be kind of useful so you don't have to know when to run `tox -r` manually... If this were to get merged into borgmatic, I think there should be at least a mention on the borgmatic dev documentation page: https://torsion.org/borgmatic/docs/how-to/develop-on-borgmatic/
Author
Contributor

Yeah, I don't think there is a ready way to automate synchronization between setup.py and the Nix flake. So if any dependencies are updated, they would need to be updated in the flake configuration as well by hand. It's probably not worth the effort to support two different dev environments. I was maybe thinking of a small sidenote in the dev documentation page with an (unsupported) example setup instead?

About your question: only the things specificed in flake.nix are ephemeral in the shell. Any side-effects like the .tox directory would remain after exiting the shell.

Yeah, I don't think there is a ready way to automate synchronization between `setup.py` and the Nix flake. So if any dependencies are updated, they would need to be updated in the flake configuration as well by hand. It's probably not worth the effort to support two different dev environments. I was maybe thinking of a small sidenote in the dev documentation page with an (unsupported) example setup instead? About your question: only the things specificed in flake.nix are ephemeral in the shell. Any side-effects like the `.tox` directory would remain after exiting the shell.
Owner

Sorry for the delay here. Yes, an unsupported example or a link to a separate repository from the dev docs would be fine IMO. PRs welcome!

Sorry for the delay here. Yes, an unsupported example or a link to a separate repository from the dev docs would be fine IMO. PRs welcome!
Owner

Closing this for now due to inactivity, but I'd be happy to revisit this if you'd still like to discuss!

Closing this for now due to inactivity, but I'd be happy to revisit this if you'd still like to discuss!
Sign in to join this conversation.
No Milestone
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: borgmatic-collective/borgmatic#766
No description provided.