Difference between revisions of "Wrappers vs. Dotfiles"

From NixOS Wiki
Jump to: navigation, search
(Add warning about the new wiki)
m (rollback unauthorized mass edits)
Tag: Rollback
 
Line 1: Line 1:
{{warning|1=You are reading an article on the deprecated unofficial wiki. For the up to date version of this article, see https://wiki.nixos.org/wiki/Wrappers_vs._Dotfiles.}}
 
 
 
Usually user applications (like editors, etc.) get configured through dotfiles in the user's home directory.
 
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:
 
An alternative, declarative approach is to create wrappers for application on a per-user basis, like this:

Latest revision as of 10:58, 6 April 2024

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.

You can use this simple function which takes care of wrapping the script & symlinking

 writeShellScriptBinAndSymlink = name: text: super.symlinkJoin {
    name = name;
    paths = [
      super."${name}"
      (super.writeShellScriptBin name text)
    ];
  };

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