summaryrefslogtreecommitdiffstats
path: root/krebs/5pkgs/simple/TabFS/default.nix
blob: 23fdf519df4482dabc9267ef32eae7955681500a (plain)
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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
{ lib, pkgs, stdenv }:

stdenv.mkDerivation rec {
  name = "TabFS";

  src = pkgs.fetchgit {
    url = https://cgit.krebsco.de/TabFS;
    rev = "1fc4845283a0e6aa46a8d8978f356d5ccdcedd13";
    sha256 = "0bsm5fhxrr6zwbnm9p10h9pwm85llr02g2ch97a62r62dhjjrc8h";
  };

  phases = [
    "unpackPhase"
    "buildPhase"
    "installPhase"
  ];

  nativeBuildInputs = [
    pkgs.jq
  ];

  buildInputs = [
    pkgs.fuse
  ];

  buildPhase = ''
    make -C fs
  '';

  installPhase = ''
    mkdir -p $out/bin

    cp fs/tabfs $out/bin

    ${lib.concatStrings
      (lib.mapAttrsToList
        (name: spec: /* sh */ ''
          jq < ${spec.source} > $out/bin/${name} \
          --arg out $out \
          --arg path ${lib.makeBinPath spec.path} \
          -Rrs \
          ${lib.escapeShellArg /* jq */ ''
            def when(cond; update): if cond then update else . end;

            split("\n") |
            map(${lib.concatMapStringsSep "|" (filter: "(${filter})")
              (lib.toList (spec.filter or []) ++ [
                /* jq */ ''when(test("^#!"); "\(.)\nexport PATH=\($path)")''
              ])
            }) |
            join("\n")
          ''}
          chmod +x $out/bin/${name}
        '')
        {
          tabfs-enable-native-messaging = {
            source = "install.sh";
            path = [
              pkgs.coreutils
            ];
            filter = /* jq */''
              when(test("^EXE_PATH="); "EXE_PATH=\($out)/bin/tabfs-wrapper")
            '';
          };
          tabfs-wrapper = {
            source = "fs/tabfs-wrapper";
            path = [
              pkgs.coreutils
              pkgs.findutils
              pkgs.gnugrep
              pkgs.procps
              "/run/wrappers" # for fusermount
            ];
          };
          tabfs-build-crx = {
            source = "build-crx.sh";
            path = [
              pkgs.coreutils
              pkgs.crx
              pkgs.gnugrep
              pkgs.jq
              pkgs.openssl
            ];
            filter = /* jq */''
              when(test("^source_dir=");
                sub("\\$\\(dirname \"\\$0\"\\)"; ${builtins.toJSON src})
              )
            '';
          };
          tabfs-install-crx = {
            source = "install-crx.sh";
            path = [
              pkgs.coreutils
            ];
          };
        }
      )
    }
  '';
}