.dotfiles/nix/utils.nix
Martin Larsson de7f2ff31f Update Nix flake, refactor Darwin app aliases and use it for system and
home config. Remove qutebrowser, mousecat, move some apps from brew ->
nixpkgs, add firefox to mac
2025-07-13 16:25:17 +02:00

49 lines
1.3 KiB
Nix

rec {
mk_symlinks =
{
config,
basePath ? "${config.home.homeDirectory}/dev/git/.dotfiles",
dotfiles ? [ ],
}:
builtins.listToAttrs (
map (file: {
name = builtins.elemAt file 0;
value = {
source = config.lib.file.mkOutOfStoreSymlink "${basePath}/${builtins.elemAt file 1}";
};
}) dotfiles
);
mkAppAliasSystem = args: args.pkgs.lib.mkForce (mkAppAliasScriptContent args);
mkAppAliasHome =
args: args.lib.hm.dag.entryAfter [ "writeBoundary" ] (mkAppAliasScriptContent args);
# Darwin System / Home Manager expects activation scripts in different formats
# This only return the script body, use the other two functions in the config.
mkAppAliasScriptContent =
{
derivationName,
appsPath,
outputDir,
pkgs,
lib,
}:
let
env = pkgs.buildEnv {
name = derivationName;
paths = appsPath;
pathsToLink = "/Applications";
};
in
''
echo "Setting up macOS .app aliases..." >&2
rm -rf "${outputDir}"
mkdir -p "${outputDir}"
find ${env}/Applications -maxdepth 1 -type l -exec readlink '{}' + |
while read -r src; do
app_name=$(basename "$src")
${pkgs.mkalias}/bin/mkalias "$src" "${outputDir}/$app_name"
done
'';
}