Files
nix-darwin/modules/archive-installs.nix

42 lines
1.1 KiB
Nix

{ pkgs, lib, ... }:
let
cfg = config.archiveApps;
stampDir = "/usr/local/share/nix-pkg-stamps";
appScript = a:
let
src = pkgs.fetchurl { inherit (a) url sha256; };
in ''
stamp="${stampDir}/${a.name}"
want="${src}"
if [ "$(cat "$stamp" 2>/dev/null)" != "$want" ]; then
echo "installing ${a.name}..."
tmp=$(mktemp -d)
if /usr/bin/unzip -q "$want" -d "$tmp"; then
if [ -d "$tmp/${a.app}" ]; then
rm -rf "/Applications/${a.app}"
/usr/bin/ditto "$tmp/${a.app}" "/Applications/${a.app}"
mkdir -p "${stampDir}"
echo "$want" > "$stamp"
else
echo "${a.name}: ${a.app} not found in zip, skipping"
fi
else
echo "${a.name}: could not unzip, skipping"
fi
rm -rf "$tmp"
fi
'';
in
{
optiosn.archiveApps = lib.mkOption {
type = lib.types.typesOf (lib.types.attrsOf lib.types.str);
default = [ ];
description = "Apps distributed as .zip archives to install into /Applications";
}
system.activationScripts.postActivation.text =
lib.concatMapStringsSep "\n" appScript cfg;
}