Wrappers vs. Dotfiles: Difference between revisions

From NixOS Wiki
imported>Tv
m link Home Manager internally
imported>Fzakaria
Added wrapProgram example
Line 10: Line 10:
       exec ${pkgs.htop}/bin/htop "$@"
       exec ${pkgs.htop}/bin/htop "$@"
     '')
     '')
  ];
}
</syntaxhighlight>
Consider also using the simpler ''wrapProgram'' utility
<syntaxhighlight lang="nix">
{
  users.users.root.packages = [
    (pkg.wrapProgram ${pkgs.htop}/bin/htop --set HTOPRC ${pkgs.writeText "htoprc" ...}
   ];
   ];
}
}

Revision as of 03:57, 22 July 2020

Usually user applications (like editors, etc.) get configured through dotfiles in the user's home directory. An alternative, declarative approach is to create wrappers for application on a per-user basis, like this:

{
  users.users.root.packages = [
    (pkgs.writeScriptBin "htop" ''
      #! ${pkgs.bash}/bin/bash
      export HTOPRC=${pkgs.writeText "htoprc" ...}
      exec ${pkgs.htop}/bin/htop "$@"
    '')
  ];
}

Consider also using the simpler wrapProgram utility

{
  users.users.root.packages = [
    (pkg.wrapProgram ${pkgs.htop}/bin/htop --set HTOPRC ${pkgs.writeText "htoprc" ...}
  ];
}


Downside of the Wrapper Approach

  • There might be applications that don't provide means to specify configuration. One could override $HOME, but then there might be applications that require $HOME for other stuff than configuration.
  • Applications cannot write their configuration anymore, e.g. htop will just terminate without error and nothing changed.

Alternatives