Single file home-manager kit

In the spirit of getting innocent and unsuspecting souls hooked on portable declarative packgage management, I’m wondering whether it’s possible create a not-too-ugly, self-contained and self-installing home-manager configuration, in a single file.

The idea is to make the process so simple, that anyone who knows which end of a keyboard to sit at, should be able to follow it. The proverbial grandmother, if you like.

Put another way, I should be able to say to someone, “Save this single file, run this single command, and you will have installed the N packages you want/need/we talked about over coffee”.

Assumptions / prerequisites

  1. nix-shell -p cowsay --run 'cowsay Nix is installed!' works in the victim’s account on the victim’s machine.

Rules of the Game

  1. Provide the victim with a SINGLE FILE. (Let’s assume, in what follows, that the victim saves it as $HOME/the-magic-nix-file, but any reasonable name will do. Maybe even .config/nixpkgs/home.nix, though a more obviously/sensibly version-controllable location would be preferable.)
  2. Ask the victim to exectue a SINGLE SHELL COMMAND, that uses $HOME/the-magic-nix-file.

Having completed these two steps, the victim should now have whatever packages were specified in home.packages inside the file.

  1. Changing the set of installed packages should consist of exactly 2 steps:

    a. updating home.packages in $HOME/the-magic-nix-file

    • EITHER repeat exactly the same command as was used in part 2
    • OR home-manager switch
  2. The pkgs version should be pinned.

Can you propose a solution?


I’ve have bootstrapped people with a single directory containing 3 files

  • bootstrap-home-manager
  • sources.nix
  • nixpkgs/home.nix

If I could reduce this to a single file, I would be able to persuade more people to give it a go, eventually leading them to benefit from the wonders that home-manager has to offer.

I would like the solution to be home-manager based, because there is an easy upgrade path to more involved configurations, for those victims who get hooked.

Alternatively, I would like to be able to answer the question

with something like



Introducing tiny-home-manager! The full instructions and GitHub template are available at the link, but here is the complete file (shell.nix) and the command to run is nix-shell. The default configuration is to install bash as your shell and the program cowsay:


  nixpkgs-src = builtins.fetchTarball { url = ""; };
  pkgs = import nixpkgs-src {};

  home-manager-src = builtins.fetchTarball { url = ""; };
  home-manager = (import home-manager-src {inherit pkgs;}).home-manager;

  home.nix = ''
    { pkgs, ... }:
      home.username = "$USER";
      home.homeDirectory = "$HOME";
      home.stateVersion = "20.09";
      programs.bash = {
        enable = true;
      home.packages = [

in pkgs.mkShell rec {

  shellHook = ''
    export NIX_PATH="nixpkgs=${nixpkgs-src}:home-manager=${home-manager-src}"
    trap 'rm -f "$TMPFILE"' EXIT
    TMPFILE=$(mktemp) || exit 1
    ${home-manager}/bin/home-manager switch
    exit 0


I’d already worked out most of the details here for home-manager-template.

This doesn’t satisfy #4 but it should be relatively trivial for your hypothetical person setting this up to do.

Ryan Mulligan


Obligatory mention, a tool by another nix genius- Static Nix: a command-line swiss army knife