-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdefault.nix
99 lines (88 loc) · 2.66 KB
/
default.nix
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
# Author: Viacheslav Lotsmanov
# License: GNU/GPLv3 https://raw.githubusercontent.com/unclechu/gpaste-gui/master/LICENSE
let sources = import nix/sources.nix; in
{ callPackage
, lib
, perl
, perlPackages
, gpaste
# Overridable dependencies
, __nix-utils ? callPackage sources.nix-utils { inherit perlPackages; }
# Build options
, __name ? "gpaste-gui"
, __srcScript ? builtins.readFile ./gpaste-gui.pl
}:
let
inherit (__nix-utils)
esc lines unlines writeCheckedExecutable wrapExecutableWithPerlDeps
shellCheckers valueCheckers;
perl-exe = "${perl}/bin/perl";
gpaste-client = "${gpaste}/bin/gpaste-client";
deps = p: [
p.GetoptLong
# p.PodUsage # ‘null’ dummy plug
p.Glib
p.Gtk2
# Sub dependencies
p.Pango
p.Cairo
];
checkPhase = ''
${shellCheckers.fileIsExecutable perl-exe}
${shellCheckers.fileIsExecutable gpaste-client}
'';
patchLines = startReg: endReg: replaceTo: srcLinse:
assert builtins.isString startReg;
assert builtins.isString endReg;
assert builtins.isString replaceTo;
let
reducer = acc: line:
if ! isNull (builtins.match "^#!.*$" line) then (
acc
) else if acc.state == "pre" then (
let matches = builtins.match startReg line; in
if isNull matches
then acc // { lines = acc.lines ++ [line]; }
else { state = "in"; lines = acc.lines ++ [replaceTo]; }
) else if (acc.state == "in") then (
if isNull (builtins.match endReg line)
then acc
else acc // { state = "post"; }
) else if (acc.state == "post") then (
acc // { lines = acc.lines ++ [line]; }
) else throw "Unexpected state: ${acc.state}";
result = builtins.foldl' reducer { lines = []; state = "pre"; } srcLinse;
in
assert result.state == "post";
result.lines;
patchedScript = lib.pipe __srcScript [
lines
(
patchLines
"^my \\$gpaste_bin = .*$"
"^[^ ].*;$"
"my $gpaste_bin = q{${gpaste-client}};"
)
(
let version = builtins.splitVersion gpaste.version; in
assert builtins.all (x: builtins.seq (lib.toInt x) true) version;
patchLines
"^my @gpaste_version = .*$"
"^[^ ].*;$"
"my @gpaste_version = (${builtins.concatStringsSep "," version});"
)
unlines
];
perlScript = writeCheckedExecutable __name checkPhase ''
#! ${perl-exe}
${patchedScript}
'';
in
assert valueCheckers.isNonEmptyString __srcScript;
wrapExecutableWithPerlDeps "${perlScript}/bin/${__name}" {
inherit deps checkPhase;
} // {
inherit checkPhase;
perlDependencies = deps perlPackages;
srcScript = __srcScript;
}