42 lines
1.2 KiB
Nix
42 lines
1.2 KiB
Nix
{ pkgs, lib, config, ... }:
|
|
|
|
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
|
|
{
|
|
options.archiveApps = lib.mkOption {
|
|
type = lib.types.listOf (lib.types.attrsOf lib.types.str);
|
|
default = [ ];
|
|
description = "Apps distributed as .zip archives to install into /Applications";
|
|
};
|
|
|
|
config.system.activationScripts.postActivation.text =
|
|
lib.concatMapStringsSep "\n" appScript cfg;
|
|
}
|