Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

xdg: Wrap binaries that don't follow XDG Base Dirs spec. #32

Open
Lehmanator opened this issue Jan 30, 2024 · 0 comments
Open

xdg: Wrap binaries that don't follow XDG Base Dirs spec. #32

Lehmanator opened this issue Jan 30, 2024 · 0 comments
Assignees

Comments

@Lehmanator
Copy link
Owner

Lehmanator commented Jan 30, 2024

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

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

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"
  '';
}
@Lehmanator Lehmanator self-assigned this Jan 30, 2024
@Lehmanator Lehmanator changed the title Wrap binaries that don't follow XDG Base Dirs spec. xdg: Wrap binaries that don't follow XDG Base Dirs spec. Feb 7, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant