-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.nix
74 lines (60 loc) · 1.77 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
{ config, lib, pkgs, ... }:
with lib;
let
cfg = config.services.link-apps;
createMacOSAlias = (
(builtins.toString (
pkgs.callPackage
({ stdenv }:
stdenv.mkDerivation rec {
name = "create-macos-alias";
unpackPhase = "true"; # nothing to unpack
src = ./create-macos-alias.swift;
dontConfigure = true;
buildInputs = [ ];
dontBuild = true;
installPhase = ''
install -D -m755 $src $out/bin/create-macos-alias
'';
meta = with stdenv.lib; {
license = licenses.mit;
platforms = platforms.darwin;
maintainers = with maintainers; [ landakram ];
};
}
) { }
)) + "/bin/create-macos-alias"
);
in
{
options = {
services.link-apps = {
enable = mkEnableOption "create aliases (not symlinks) for macOS Apps at activation time";
userName = mkOption {
type = types.str;
};
userHome = mkOption {
type = types.path;
};
dest = mkOption {
type = types.path;
default = "${cfg.userHome}/Applications/Nix";
description = "Destination where nix-compiled Apps will be aliased.";
};
};
};
config = mkIf cfg.enable {
system.activationScripts.postActivation.text = ''
echo "Aliasing Apps to ${cfg.dest}"
mkdir -p ${cfg.dest}
chown ${cfg.userName} ${cfg.dest}
find ${config.system.build.applications}/Applications -maxdepth 1 -type l | while read f; do
src="$(/usr/bin/stat -f%Y $f)"
appname="$(basename $src)"
dest=${cfg.dest}/$appname
[ -f $dest ] && rm $dest
${createMacOSAlias} "''${src}" "''${dest}"
done
'';
};
}