1
0
Fork 0

darwin: Use mkalias to link apps

This commit is contained in:
Daniel Kempkens 2023-10-01 17:34:28 +02:00
parent a09022e129
commit 5f9bbb9891
Signed by: daniel
SSH key fingerprint: SHA256:Ks/MyhQYcPRQiwMKLAKquWCdCPe3JXlb1WttgnAoSeM
4 changed files with 62 additions and 2 deletions

View file

@ -313,6 +313,26 @@
"type": "github"
}
},
"mkalias": {
"inputs": {
"nixpkgs": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1678761502,
"narHash": "sha256-tL3C/b2BPOGQpV287wECDCDWmKwwPvezAAN3qz7N07M=",
"owner": "reckenrode",
"repo": "mkalias",
"rev": "8a5478cdb646f137ebc53cb9d235f8e5892ea00a",
"type": "github"
},
"original": {
"owner": "reckenrode",
"repo": "mkalias",
"type": "github"
}
},
"neovim-flake": {
"inputs": {
"flake-utils": "flake-utils_2",
@ -528,6 +548,7 @@
"flake-parts": "flake-parts",
"flake-root": "flake-root",
"home-manager": "home-manager",
"mkalias": "mkalias",
"nifoc-overlay": "nifoc-overlay",
"nix-darwin": "nix-darwin",
"nixos-hardware": "nixos-hardware",

View file

@ -62,6 +62,11 @@
url = "github:serokell/deploy-rs";
inputs.nixpkgs.follows = "nixpkgs";
};
mkalias = {
url = "github:reckenrode/mkalias";
inputs.nixpkgs.follows = "nixpkgs";
};
};
outputs = inputs@{ flake-parts, ... }:

View file

@ -1,4 +1,4 @@
{ pkgs, ... }:
{ pkgs, lib, config, ... }:
{
imports = [
@ -42,6 +42,8 @@
../programs/yt-dlp.nix
];
disabledModules = [ "targets/darwin/linkapps.nix" ];
home = {
stateVersion = "22.11";
@ -75,5 +77,35 @@
xxHash
xz
];
activation.aliasApplications = lib.mkIf pkgs.stdenv.hostPlatform.isDarwin (
let
apps = pkgs.buildEnv {
name = "home-manager-applications";
paths = config.home.packages;
pathsToLink = "/Applications";
};
lastAppsFile = "${config.xdg.stateHome}/nix/.apps";
in
lib.hm.dag.entryAfter [ "writeBoundary" ] ''
last_apps=$(cat "${lastAppsFile}" 2>/dev/null || echo "")
next_apps=$(readlink -f ${apps}/Applications/* | sort)
if [ "$last_apps" != "$next_apps" ]; then
echo "Apps have changed. Updating macOS aliases..."
apps_path="$HOME/Applications/Home Manager Apps"
$DRY_RUN_CMD mkdir -p "$apps_path"
$DRY_RUN_CMD ${pkgs.fd}/bin/fd \
-t l -d 1 . ${apps}/Applications \
-x $DRY_RUN_CMD "${pkgs.mkalias}/bin/mkalias" \
-L {} "$apps_path/{/}"
[ -z "$DRY_RUN_CMD" ] && echo "$next_apps" > "${lastAppsFile}"
fi
''
);
};
}

View file

@ -4,8 +4,9 @@ let
default-system = "aarch64-darwin";
overlay-x86 = _: _: { pkgs-x86 = import nixpkgs { system = "x86_64-darwin"; }; };
overlay-agenix = inputs.agenix.overlays.default;
overlay-agenix = agenix.overlays.default;
overlay-attic = inputs.attic.overlays.default;
overlay-mkalias = _: _: { inherit (inputs.mkalias.packages.${default-system}) mkalias; };
overlay-nifoc = inputs.nifoc-overlay.overlay;
nixpkgsConfig = {
@ -13,6 +14,7 @@ let
overlay-x86
overlay-agenix
overlay-attic
overlay-mkalias
overlay-nifoc
];