nix-community / home-manager

Manage a user environment using Nix [maintainer=@rycee]

Home Page:https://nix-community.github.io/home-manager/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Static nix-shell shebangs

timokau opened this issue · comments

I want to use nix-shell shebangs in my personal script collection to make sure all the needed dependencies are available. That has two disadvantages however:

  • it adds significant overhead (~half a second on my machine if all dependencies are already present)
  • dependencies may be garbage collected so usage of scripts may need internet access

So what I'd actually like is nix-shell like dependency declaration that is resolved statically whenever I update my channels. I've hacked together a proof of concept to do this in home-manager: I iterate through all my scripts, parse the nix-shell shebang line and generate a wrapper script that sets PATH. It is very hacky at the moment and I'm not sure yet if I will improve it in the future, but I thought it couldn't hurt to share it here. What do you think about including something similar as a home-manager library function?

Here is my POC which I import in my home.nix.

This is my solution for python: https://github.com/wiedzmin/nixos-config/blob/master/modules/util.nix#L9. Will look into your PoC, looks interesting.

commented

Thank you for your contribution! I marked this issue as stale due to inactivity. If this remains inactive for another 7 days, I will close this issue. Please read the relevant sections below before commenting.

If you are the original author of the issue

  • If this is resolved, please consider closing it so that the maintainers know not to focus on this.
  • If this might still be an issue, but you are not interested in promoting its resolution, please consider closing it while encouraging others to take over and reopen an issue if they care enough.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

If you are not the original author of the issue

  • If you are also experiencing this issue, please add details of your situation to help with the debugging process.
  • If you know how to solve the issue, please consider submitting a Pull Request that addresses this issue.

Memorandum on closing issues

If you have nothing of substance to add, please refrain from commenting and allow the bot close the issue. Also, don't be afraid to manually close an issue, even if it holds valuable information.

Closed issues stay in the system for people to search, read, cross-reference, or even reopen--nothing is lost! Closing obsolete issues is an important way to help maintainers focus their time and effort.

This is just a proof of concept and not very actionable at this point. It would need quite a bit of polishing before it could be included in home-manager. I'll close this for now. Please leave a message if you are interested in this issue and think that it should be re-opened.

I noticed that there are a few reactions to this issue. That may be a reason to leave it open. I do not plan to work on this though, at least not in the near future. The stale bot was probably added to cut down on the backlog, so I'll leave this closed unless somebody wants to push it forward. I'd be happy if somebody else comes up with a solution that can be integrated into home-manager.

Yeah, I think it is a good idea. But I would suggest creating a separate tool that provides this feature, then we can use it here. It would then also be useful for people not using Home Manager.

I agree, it would be very nice to have this as an external tool. It's currently hard to integrate such a tool into the home-manager and nixos profile generation though. The scripts should be wrapped/patched at "home-manager build" time and then be placed in the profile. The way forward would probably be a library that you could import into your nixos and home-manager configuration. As I said, I don't have any plans to work in this though.