blob: 04c2d28d32bc6c4bc740baa747a9b8eecde9d02f (
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
|
{ pkgs ? import <nixpkgs> {}
, confPath
, confAttr ? null
, check ? true
, newsReadIdsFile ? null
}:
with pkgs.lib;
let
env = import ../modules {
configuration =
if confAttr == "" || confAttr == null
then confPath
else (import confPath).${confAttr};
pkgs = pkgs;
check = check;
};
newsReadIds =
if newsReadIdsFile == null
then {}
else
let
ids = splitString "\n" (fileContents newsReadIdsFile);
in
builtins.listToAttrs (map (id: { name = id; value = null; }) ids);
newsIsRead = entry: builtins.hasAttr entry.id newsReadIds;
newsFiltered =
let
pred = entry: entry.condition && ! newsIsRead entry;
in
filter pred env.newsEntries;
newsNumUnread = length newsFiltered;
newsFileUnread = pkgs.writeText "news-unread.txt" (
concatMapStringsSep "\n\n" (entry:
let
time = replaceStrings ["T"] [" "] (removeSuffix "+00:00" entry.time);
in
''
* ${time}
${replaceStrings ["\n"] ["\n "] entry.message}
''
) newsFiltered
);
newsFileAll = pkgs.writeText "news-all.txt" (
concatMapStringsSep "\n\n" (entry:
let
flag = if newsIsRead entry then "read" else "unread";
time = replaceStrings ["T"] [" "] (removeSuffix "+00:00" entry.time);
in
''
* ${time} [${flag}]
${replaceStrings ["\n"] ["\n "] entry.message}
''
) env.newsEntries
);
# File where each line corresponds to an unread news entry
# identifier. If non-empty then the file ends in "\n".
newsUnreadIdsFile = pkgs.writeText "news-unread-ids" (
let
text = concatMapStringsSep "\n" (entry: entry.id) newsFiltered;
in
text + optionalString (text != "") "\n"
);
newsInfo = pkgs.writeText "news-info.sh" ''
local newsNumUnread=${toString newsNumUnread}
local newsDisplay="${env.newsDisplay}"
local newsFileAll="${newsFileAll}"
local newsFileUnread="${newsFileUnread}"
local newsUnreadIdsFile="${newsUnreadIdsFile}"
'';
in
{
inherit (env) activationPackage;
inherit newsInfo;
}
|