Created
August 3, 2017 20:35
-
-
Save infinisil/a82c894755d27c2382dcb711f60b4e8b to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
self: super: let | |
mkXDG = import ../xdg.nix; | |
in | |
{ | |
wget = mkXDG { | |
pname = "wget"; | |
pkg = super.wget; | |
mods = { cache }: { | |
wget.flags = "--hsts-file=${cache}/hsts"; | |
}; | |
}; | |
zsh = mkXDG { | |
pname = "zsh"; | |
pkg = super.zsh; | |
mods = { config }: { | |
zsh.env.ZDOTDIR = config; | |
}; | |
}; | |
irssi = mkXDG { | |
pname = "irssi"; | |
pkg = super.irssi; | |
mods = { config }: { | |
irssi.flags = "--home=${config}"; | |
}; | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
with import <nixpkgs> {}; | |
let | |
mkXDG = { pname, pkg, mods }: let | |
xdgDirs = { | |
cache = "\${XDG_CACHE_HOME:-$HOME/.cache}/${pname}"; | |
config = "\${XDG_CONFIG_HOME:-$HOME/.config}/${pname}"; | |
data = "\${XDG_DATA_HOME:-$HOME/.local/share}/${pname}"; | |
}; | |
dirsUsed = builtins.intersectAttrs (builtins.functionArgs mods) xdgDirs; | |
mods' = mods dirsUsed; | |
mkdirWrap = if dirsUsed == {} then throw "Taking no arguments" else | |
"--run 'mkdir -p ${lib.concatMapStrings (dir: "\"${xdgDirs.${dir}}\"") (builtins.attrNames dirsUsed)}' \\\n\t"; | |
envWrap = bin: "${lib.concatMapStringsSep "\\\n\t" (var: "--set ${var} '${mods'.${bin}.env.${var}}' ") (builtins.attrNames mods'.${bin}.env or {})}"; | |
flagWrap = bin: if mods'.${bin} ? flags then "--add-flags '${mods'.${bin}.flags}'" else ""; | |
wrap = bin: '' | |
wrapProgram $out/bin/${bin} \ | |
${mkdirWrap}${envWrap bin}${flagWrap bin} | |
''; | |
in pkg.overrideAttrs (old: { | |
buildInputs = old.buildInputs ++ [ pkgs.makeWrapper ]; | |
postInstall = (old.postInstall or "") + lib.concatMapStrings (bin: wrap bin) (builtins.attrNames mods'); | |
}); | |
in | |
mkXDG |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment