-
Notifications
You must be signed in to change notification settings - Fork 0
/
module.nix
153 lines (147 loc) · 4.44 KB
/
module.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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
{ config, lib, pkgs, ...}:
with lib;
let
cfg = config.remoteapps;
connectRdp = name: app:
let
passwordSrc = if cfg.passwordFile == null then "echo ${toString cfg.password}" else "cat ${cfg.passwordFile}";
multiFlag = if cfg.multiMon then "/multimon" else "+span";
in
pkgs.writeShellScriptBin "startremoteapp-${name}.sh"
''
FILE_PATH=$(echo $1 | ${cfg.pathTransform})
${passwordSrc} | \
${pkgs.freerdp3}/bin/xfreerdp \
${toString cfg.extraFlags} \
/d:"${toString cfg.domain}" \
/u:"${cfg.user}" \
/from-stdin \
/v:"${cfg.host}:${toString cfg.port}" \
/cert:tofu \
/auto-reconnect \
/clipboard \
+home-drive \
-wallpaper \
/scale:${toString cfg.scale} \
${multiFlag} \
/dynamic-resolution \
/wm-class:"${app.fullName}" \
${if cfg.sharePrinters then "/printer" else ""} \
/shell:rdpinit.exe \
/app:program:"${app.winExecutable}",icon:"${app.icon}",cmd:"\"$FILE_PATH\""
'';
applicationOpts = { name, config, ...}: {
options = {
enable = mkEnableOption "whether to enable the application";
fullName = mkOption {
type = types.str;
description = "Full Name of the application";
};
winExecutable = mkOption {
type = types.str;
description = "Path to the windows executable";
};
categories = mkOption {
description = "Categories in which the entry should be shown in a menu.";
type = with types; listOf str;
default = [];
};
mimeTypes = mkOption {
description = "The MIME type(s) supported by this application.";
type = with types; listOf str;
default = [];
};
icon = mkOption {
description = "Icon to display in file manager, menus, etc.";
type = with types; nullOr (either str path);
default = null;
};
};
};
in
{
imports = [ ./apps ];
options = {
remoteapps = {
domain = mkOption {
description = "domain to log in with";
type = with types; nullOr str;
default = null;
};
host = mkOption {
description = "address of rdp server";
type = with types; str;
};
port = mkOption {
description = "port of the rdp server";
type = with types; port;
default = 3389;
};
user = mkOption {
description = "user to log in with";
type = with types; str;
};
password = mkOption {
description = ''
password to log in with
WARNING: stored in clear-text in nix store.
Use `passwordFile` instead.
'';
type = with types; nullOr str;
default = null;
};
passwordFile = mkOption {
description = "path to a file containing the password";
type = with types; nullOr (either path str);
default = null;
};
extraFlags = mkOption {
description = "additional arguments for `xfreerdp`";
type = with types; nullOr str;
default = null;
};
multiMon = mkOption {
description = "whether to enable /multimon or +span";
type = with types; bool;
default = false;
};
scale = mkOption {
description = "scale of the remote app in percent";
type = with types; int;
default = 100;
};
sharePrinters = mkOption {
description = "whether to enable the /printer flag";
type = with types; bool;
default = false;
};
pathTransform = mkOption {
type = with types; path;
description = ''A program that transforms a unix path to a windows path'';
default = pkgs.writeShellScript "default-path-transform.sh" ''
INPUT=$(cat)
echo INPUT
'';
};
apps = mkOption {
type = with types; attrsOf (submodule applicationOpts);
default = {};
};
};
};
config = {
xdg.desktopEntries = mapAttrs
(name: value: {
name = value.fullName;
icon = value.icon;
exec = "${toString (connectRdp name value)}/bin/startremoteapp-${name}.sh %U";
terminal = false;
categories = value.categories;
mimeType = value.mimeTypes;
})
(lib.attrsets.filterAttrs (name: value: value.enable) cfg.apps);
home.packages = attrsets.mapAttrsToList
(name: value: connectRdp name value)
(lib.attrsets.filterAttrs (name: value: value.enable) cfg.apps);
};
}