-
Notifications
You must be signed in to change notification settings - Fork 0
/
default.nix
127 lines (120 loc) · 3.73 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
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
{ toolbox }:
{
lib,
pkgs,
config,
modulesPath,
...
}:
let
inherit (builtins) substring filter readDir;
inherit (lib) mkOption types getExe;
inherit (lib.strings) concatStringsSep optionalString;
cfg = config.toolbox.link-apps;
withInstallationMethod =
method: drv:
assert lib.asserts.assertOneOf "method" method [
"alias"
"copy"
"symlink"
];
drv.overrideAttrs (_: _: { meta.darwinInstallMethod = method; });
installByCopying = map (withInstallationMethod "copy");
installBySymlinking = map (withInstallationMethod "symlink");
installByAliasing = map (withInstallationMethod "alias");
filterPackagesWithMacApps = filter (drv: (readDir drv.outPath).Applications or null == "directory");
mkAppLinker =
{
packages,
destination,
verbose,
dryRun,
}:
let
getInstallMethodPrefix = drv: (substring 0 1 (drv.meta.darwinInstallMethod or "alias"));
getAppDerivationPaths =
apps: concatStringsSep " " (map (drv: "${getInstallMethodPrefix drv}:${drv.outPath}") apps);
in
''
${getExe cfg.package} \
${optionalString verbose "--verbose"} \
${optionalString dryRun "--dry-run"} \
--destination '${destination}' \
${getAppDerivationPaths (filterPackagesWithMacApps packages)}
'';
in
{
options.toolbox.link-apps = {
package = mkOption {
type = types.package;
default = pkgs.${toolbox.nixpkgs-namespace}.link-apps;
};
verbose = mkOption {
type = types.bool;
description = "When true the link-apps command will log its execution plan and commands during activation";
default = false;
};
dryRun = mkOption {
type = types.bool;
description = "When true the link-apps command will not execute its commands, only log its execution plan";
default = false;
};
userAppPath = mkOption {
type = types.str;
description = "The path in the user's home directory where applications will be installed. e.g. apps found in home.packages";
default = "/Applications/Nix Apps";
};
systemAppPath = mkOption {
type = types.str;
description = "The absolute path to install applications globally. e.g. apps found in environment.systemPackages";
default = "/Applications/Nix Apps";
};
};
# Disable nix-darwin's default app linking module
disabledModules = [ "${modulesPath}/system/applications.nix" ];
config = {
nixpkgs.overlays = [
(final: prev: {
${toolbox.nixpkgs-namespace} = {
inherit (toolbox.packages.${final.system}) link-apps;
lib = {
inherit
withInstallationMethod
installByCopying
installBySymlinking
installByAliasing
mkAppLinker
filterPackagesWithMacApps
;
};
};
})
];
system.build.applications = pkgs.buildEnv {
name = "system-applications";
paths = [ ];
pathsToLink = "/Applications";
};
system.activationScripts.applications.text = mkAppLinker {
packages = config.environment.systemPackages;
destination = cfg.systemAppPath;
verbose = cfg.verbose;
dryRun = cfg.dryRun;
};
home-manager.sharedModules = [
(
{ modulesPath, config, ... }:
{
# Disable Home Manager's default app linking module.
disabledModules = [ "${modulesPath}/targets/darwin/linkapps.nix" ];
home.activation.applications = mkAppLinker {
packages = config.home.packages;
destination = "${config.home.homeDirectory}${cfg.userAppPath}";
verbose = cfg.verbose;
dryRun = cfg.dryRun;
};
}
)
];
};
}