about summary refs log tree commit diff
path: root/pkgs/profpatsch/execline/importer.nix
blob: 67464d17368af26a891ffd2142f69be7e143443d (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
{ lib, coreutils, s6-portable-utils, symlink }:
let
  example = {from, as, just, ...}:
    [
      (from coreutils [
        (just "echo")
        (as "core-ls" "ls")
      ])
      (from s6-portable-utils [
        (as "ls" "s6-ls")
        (just "s6-echo")
      ])
    ];

  runImport = impsFn:
    let
      combinators = rec {
        from = source: imports: {
          inherit source imports;
        };
        as = newname: oldname: {
          inherit oldname newname;
        };
        just = x: as x x;
      };

      # Drv -> As -> Symlink
      toBin = module: {oldname, newname}: {
        dest = "bin/${newname}";
        orig = "${module}/bin/${oldname}";
      };
      # List (Import { source: Drv
      #              , imports: List (As { oldname: String
      #                                  , newname: String }))
      # -> Drv
      run = imps:
        symlink "foo" (lib.concatLists
          (map ({source, imports}:
                   map (toBin source) imports)
               imps));

    # TODO: typecheck w/ newtypes
    in run (impsFn combinators);

in runImport example