about summary refs log tree commit diff
path: root/config/tools.nix
blob: 5e26bafdda17e0acea9fcf804d00de014ece1eef (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
{ lib, symlinkJoin, writeTextFile, writeShellScriptBin }:

let
  inherit (lib) concatStrings mapAttrsToList;

in rec {

  configure = pkg: wrapped:
    (symlinkJoin {
      name = "${pkg.name}-configured";
      paths = [ wrapped pkg ];
    }).overrideAttrs (oldAttrs: {
      passthru = pkg.passthru or {};
    }) // {
      unconfigured = pkg;
    };

  addFlags = pkg: bin: flags:
    configure pkg (writeShellScriptBin bin ''
      exec ${pkg}/bin/${bin} ${flags} "$@"
    '');

  setEnv = pkg: bin: env:
    configure pkg (writeShellScriptBin bin
      ((concatStrings (mapAttrsToList
        (name: value: "export ${name}=${value}\n") env)) + ''
          exec ${pkg}/bin/${bin} "$@"
        '')
    );

  xdgConfig = { package, executable, path, text }:
    setEnv package executable {
      XDG_CONFIG_HOME = writeTextFile {
        name = "${package.name}-config";
        destination = "/${path}";
        inherit text;
      };
    };

}