generated from ryantm/home-manager-template
/
app.nix
63 lines (58 loc) · 1.32 KB
/
app.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
{
# custom args
name,
appname ? name,
version,
src,
description,
homepage,
postInstall ? "",
sourceRoot ? ".",
# nix supplied
pkgs,
stdenv,
lib,
undmg,
unzip,
...
}:
if stdenv.isDarwin then
[(stdenv.mkDerivation {
name = "${name}-${version}";
version = "${version}";
src = src;
buildInputs = [ unzip ];
unpackCmd = ''
echo "File to unpack: $curSrc"
if ! [[ "$curSrc" =~ \.dmg$ ]]; then return 1; fi
mnt=$(mktemp -d -t ci-XXXXXXXXXX)
function finish {
echo "Detaching $mnt"
/usr/bin/hdiutil detach $mnt -force
rm -rf $mnt
}
trap finish EXIT
echo "Attaching $mnt"
/usr/bin/hdiutil attach -nobrowse -readonly $src -mountpoint $mnt
echo "What's in the mount dir"?
ls -la $mnt/
echo "Copying contents"
shopt -s extglob
DEST="$PWD"
(cd "$mnt"; cp -a !(Applications) "$DEST/")
'';
sourceRoot = sourceRoot;
phases = [ "unpackPhase" "installPhase" ];
installPhase = ''
mkdir -p "$out/Applications/${appname}.app"
cp -a ./. "$out/Applications/${appname}.app/"
'' + postInstall;
meta = {
description = description;
homepage = homepage;
maintainers = [ "ldeck <ldeck@example.com>" ];
platforms = lib.platforms.darwin;
};
})]
else
[]