blob: 75af450936fa68931696c7515160bb5b65d2f26f (
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
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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
|
{
lib,
config,
pkgs,
baseLib,
...
}: let
cfg = config.soispha.programs.tskm;
allProjectNames = lib.lists.flatten (lib.attrsets.mapAttrsToList mkProject cfg.projects);
projectList = builtins.concatStringsSep "\n" allProjectNames;
mkProject = name: value: let
subprojects = lib.attrsets.mapAttrsToList (newName: mkProject "${name}.${newName}") value.subprojects;
in
[name] ++ subprojects;
firefoxProfiles = builtins.listToAttrs (builtins.map (name:
lib.attrsets.nameValuePair name {
inherit name;
# We use the hash-based function here, so that we can avoid an id change if a new
# profile is added (i.e., simply using it index.)
# TODO: However, I do not know what this id is for and if it would be bad if it changed? <2025-04-02>
id = baseLib.idFromString name;
})
allProjectNames);
contexts =
builtins.concatStringsSep "\n"
(lib.lists.flatten
(lib.attrsets.mapAttrsToList mkContext cfg.projects));
mkContext = name: value: let
subprojects =
lib.attrsets.mapAttrsToList
(newName: newValue: let
finalValue =
if newValue.prefix == ""
then newValue // {inherit (value) prefix;}
else newValue;
in
mkContext "${name}.${newName}" finalValue)
value.subprojects;
contextName = builtins.replaceStrings ["."] ["_"] name;
in
[
''
context.${contextName}.rc.neorg_path=${value.prefix}/index.norg
context.${contextName}.read=project:${name}
context.${contextName}.write=project:${name}
''
]
++ subprojects;
contextsFile =
pkgs.writeText "contexts-file" contexts;
projectType = lib.types.submodule {
options = {
name = lib.mkOption {
type = lib.types.str;
example = "timesinks";
description = "The name of this project";
};
prefix = lib.mkOption {
type = lib.types.str;
default = "";
example = "programming/zig";
description = ''
A prefix to append to the project neorg path.
This can be used to group similar project's neorg directories together. '
'';
};
subprojects = lib.mkOption {
type = lib.types.attrsOf projectType;
description = ''
A list of subprojects.
These can also contain subprojects.
'';
default = {};
};
};
};
in {
options.soispha.programs.tskm = {
enable = lib.mkEnableOption "tskm";
projects = lib.mkOption {
type = lib.types.attrsOf projectType;
};
};
config = lib.mkIf cfg.enable {
soispha.programs = {
firefox.profiles = firefoxProfiles;
taskwarrior = {
includeFiles = {
tskm-contexts = contextsFile;
};
hooks = {
enforce-projects =
config.lib.taskwarrior.mkHook "on-add" [
pkgs.jq
pkgs.gnugrep
pkgs.tskm
]
./taskwarrior_hooks/enforce-projects.sh;
};
};
};
home-manager.users.soispha = {
home.sessionVariables = {
# TODO: Remove this hard-coded path with a reference. <2025-04-04>
"TSKM_PROJECT_FILE" = "/home/soispha/repos/nix/config/modules/common/projects.json";
};
programs.nixvim = {
plugins.neorg.settings.load."core.dirman".config.workspaces = {
tskm = "~/.local/share/tskm/notes";
};
};
xdg.configFile."tskm/projects.list" = {
text = projectList;
};
};
};
}
|