about summary refs log tree commit diff
path: root/pkgs/profpatsch/nix-tools.nix
blob: 40db055c8b786c3bba52ba3fd158b34eda218ee2 (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
41
42
43
44
45
46
47
48
{ pkgs, writeExecline, getBins, runblock }:

let
  bins = getBins pkgs.nix [ "nix-build" "nix-instantiate" ];

  # TODO: both of these don’t prevent `result` from being created. good? bad?

  # Usage (execline syntax):
  #    nix-run { -A foo <more_nix_options> } args...
  #
  # Takes an execline block of `nix-build` arguments, which should produce an executable store path.
  # Then runs the store path with `prog...`.
  nix-run = writeExecline "nix-run" { argMode = "env"; } [
    "backtick" "-iE" "storepath" [
      runblock "1" bins.nix-build
    ]
    runblock "-r" "2" "$storepath"
  ];

  # Usage (execline syntax):
  #    nix-run-bin { -A foo <more_nix_options> } <foo_bin_name> args...
  #
  # Takes an execline block of `nix-build` arguments, which should produce a store path with a bin/ directory in it.
  # Then runs the given command line with the given arguments. All executables in the built storepath’s bin directory are prepended to `PATH`.
  nix-run-bin = writeExecline "nix-run-bin" { argMode = "env"; } [
    "backtick" "-iE" "storepath" [
      runblock "1" bins.nix-build
    ]
    "importas" "-ui" "PATH" "PATH"
    "export" "PATH" "\${storepath}/bin:\${PATH}"
    runblock "-r" "2"
  ];

  nix-eval = writeExecline "nix-eval" {} [
    bins.nix-instantiate
      "--read-write-mode"
      "--eval"
      "--strict"
      "$@"
  ];

in {
  inherit
    nix-run
    nix-run-bin
    nix-eval
    ;
}