`xdg`: Wrap binaries that don't follow XDG Base Dirs spec.
Lehmanator opened this issue · comments
Sam Lehman commented
Problem: Many programs don't support the XDG Base Directory specification. These programs often pollute a user's $HOME
directory or other directories with unwanted files that would be better placed in the appropriate XDG directories.
Solution: Many of these programs can be configured to use alternate files/directories by running the program with CLI options passed, environment variables set, or config files/options set. Wrap these programs with whatever is necessary to get these programs closer to the XDG Base Directory spec.
List of Programs
- ArchLinux Wiki: XDG Base Directory: List of programs, XDG Base Directory spec support status, & configuration to make them adhere to the spec.
antidot
rulesantidot
CSVxdg-ninja
program/*.json
files
Possibilities
- Create wrapped packages with included env vars, cmdline options, and/or config files.
- Overlay original packages w/ wrapped version, so no other NixOS / home-manager config is necessary.
- Create new packages and set NixOS / home-manager options like
program.<name>.package = pkgs.<name>-xdg-compliant
(or whatever name) to use the wrapped versions while keeping the original programs.
Docs
- https://nixos.wiki/wiki/Wrappers_vs._Dotfiles
- https://nixos.wiki/wiki/Nix_Cookbook#Wrapping_packages
xdg-ninja
package / repo / source codeantidot
package / repo / source code
Nix Libs / Examples
Trivial Builders
pkgs.wrapShellScriptBin
pkgs.wrapShellScript
pkgs.runCommand
pkgs.writeText
pkgs.writeTextFile
Functions available in pkgs.stdenv
Example Snippets
(pkgs.writeScriptBin "htop" ''
#! ${pkgs.bash}/bin/bash
export HTOPRC=${pkgs.writeText "htoprc" ...}
exec ${pkgs.htop}/bin/htop "$@"
'')
writeShellScriptBinAndSymlink = name: text: super.symlinkJoin {
name = name;
paths = [
super."${name}"
(super.writeShellScriptBin name text)
];
};
pkgs.writeShellScriptBin "hello" ''
# Call hello with a traditional greeting
exec ${pkgs.hello}/bin/hello -t
''
pkgs.runCommand "hello" {
buildInputs = [ pkgs.makeWrapper ];
} ''
mkdir $out
# Link every top-level folder from pkgs.hello to our new target
ln -s ${pkgs.hello}/* $out
# Except the bin folder
rm $out/bin
mkdir $out/bin
# We create the bin folder ourselves and link every binary in it
ln -s ${pkgs.hello}/bin/* $out/bin
# Except the hello binary
rm $out/bin/hello
# Because we create this ourself, by creating a wrapper
makeWrapper ${pkgs.hello}/bin/hello $out/bin/hello \
--add-flags "-t"
''
pkgs.symlinkJoin {
name = "hello";
paths = [ pkgs.hello ];
buildInputs = [ pkgs.makeWrapper ];
postBuild = ''
wrapProgram $out/bin/hello \
--add-flags "-t"
'';
}