about summary refs log tree commit diff
path: root/config/tools.nix
diff options
context:
space:
mode:
Diffstat (limited to 'config/tools.nix')
-rw-r--r--config/tools.nix40
1 files changed, 40 insertions, 0 deletions
diff --git a/config/tools.nix b/config/tools.nix
new file mode 100644
index 000000000000..5e26bafdda17
--- /dev/null
+++ b/config/tools.nix
@@ -0,0 +1,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;
+      };
+    };
+
+}