Home-manager-shell: nix-shell for your home-manager config

home-manager-shell allows you to run any program with your home-manager configuration without installing it in one command.

For the times you ssh into a friend’s or coworker’s machine and don’t want to pollute their environment.

Inspired by nixos-shell and nix develop (or the plain old nix-shell).

Why?

For some programs like neovim it is easy to write a wrapper package that includes your personal configuration. For most others though it is not. Usually programs expect their configuration files at specific paths in $HOME, and writing there is not an option on someone else’s machine.

How does it work?

home-manager-shell generates a temporary flake that pulls in your configuration, builds its profile, references it via $PATH, exports its other environment variables, and finally starts a shell or your program using proot to bind-mount the profile’s paths like ~/.config/git/config over the host’s filesystem. That allows us to layer our own config files on top of the host’s config files without touching them, only from the perspective of the started shell.

Try it

Run my CLI calendar with color scheme and key bindings:

nix run sourcehut:~dermetfan/garnix#home-manager-shell -- -U dermetfan -e programs.wyrd -e programs.kakoune -- wyrd

(Can't open file: /home/you/.local/share/remind is to be expected as you don’t have a calendar file on your machine)

Run my text editor with color scheme, key bindings, and tons of plugins (huge build):

nix run sourcehut:~dermetfan/garnix#home-manager-shell -- -U dermetfan -e programs.kakoune -- kak

Status

It works well enough for my use cases. That includes kakoune, timewarrior, buku, and wyrd. I use this daily so I keep it up to date with home-manager releases. There are release branches for 22.11 and 22.05.

At the moment it’s just a simple bash script. If we want to add more features it might make sense to rewrite in another language though.

There is an open home-manager issue discussing what the flake output for sharing modules should be named by convention. At the moment I use .#homeManagerProfiles but I will update this as soon as the community makes a decision.

Contributing

I do not expect hordes of contributors as this is probably a niche use case. However, since this is currently neither hosted nor mirrored on GitHub, here are some quick links:

Sourcehut unfortunately has no pull request feature. If you do wish to send a patch I do not require you to do it the sourcehut way or native git way though; just post the patch on the issue tracker or post a link to your fork.

9 Likes
Hosted by Flying Circus.