Wrappers vs. Dotfiles: Difference between revisions

From NixOS Wiki
imported>Fzakaria
Remove incorrect suggestion
imported>Fzakaria
Added a link to the cookbook to keep all output files
Line 13: Line 13:
}
}
</syntaxhighlight>
</syntaxhighlight>
The disadvantage of this way is that it doesn't propagate man pages and other paths from the old derivation.
Please refer to [[Nix_Cookbook#Wrapping_packages]] to possible solutions to retain all outputs.


=== Downside of the Wrapper Approach ===
=== Downside of the Wrapper Approach ===

Revision as of 04:56, 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 "$@"
    '')
  ];
}

The disadvantage of this way is that it doesn't propagate man pages and other paths from the old derivation. Please refer to Nix_Cookbook#Wrapping_packages to possible solutions to retain all outputs.

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