Wrap macos-only config behind platform detection

This commit is contained in:
Yan Lin 2025-08-29 21:23:13 +02:00
parent d03e84b14a
commit 6691d3c037
6 changed files with 85 additions and 61 deletions

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
{
programs.lazygit = {
@ -334,8 +334,8 @@
# OS settings
os = {
open = "open {{filename}}";
openLink = "open {{link}}";
open = if pkgs.stdenv.isDarwin then "open {{filename}}" else "xdg-open {{filename}}";
openLink = if pkgs.stdenv.isDarwin then "open {{link}}" else "xdg-open {{link}}";
};
# Disable startup popup

View file

@ -1,4 +1,4 @@
{ pkgs, ... }:
{ pkgs, lib, ... }:
{
programs.nixvim = {
@ -265,26 +265,31 @@
}
}
-- Unicode-safe file operations for macOS
-- Unicode-safe file operations
function open_file_with_system_app()
local filepath = vim.fn.expand('%:p')
if filepath ~= "" then
local escaped_path = vim.fn.shellescape(filepath)
vim.fn.system('open ' .. escaped_path)
${if pkgs.stdenv.isDarwin then
"vim.fn.system('open ' .. escaped_path)"
else
"vim.fn.system('xdg-open ' .. escaped_path)"}
else
print("No file to open")
end
end
function show_file_in_finder()
local filepath = vim.fn.expand('%:p')
if filepath ~= "" then
local escaped_path = vim.fn.shellescape(filepath)
vim.fn.system('open -R ' .. escaped_path)
else
print("No file to show")
${lib.optionalString pkgs.stdenv.isDarwin ''
function show_file_in_finder()
local filepath = vim.fn.expand('%:p')
if filepath ~= "" then
local escaped_path = vim.fn.shellescape(filepath)
vim.fn.system('open -R ' .. escaped_path)
else
print("No file to show")
end
end
end
''}
'';
};
}

View file

@ -1,13 +1,13 @@
{ pkgs, ... }:
{ pkgs, lib, ... }:
{
# Papis configuration
home.file."Library/Application Support/papis/config".text = ''
home.file.${if pkgs.stdenv.isDarwin then "Library/Application Support/papis/config" else ".config/papis/config"}.text = ''
[settings]
default-library = main
editor = nvim
opentool = open
file-browser = open
opentool = ${if pkgs.stdenv.isDarwin then "open" else "xdg-open"}
file-browser = ${if pkgs.stdenv.isDarwin then "open" else "xdg-open"}
# Document management
ref-format = {doc[author]}{doc[year]}
@ -93,16 +93,29 @@
# Shell functions for papis workflow
programs.zsh.initContent = ''
# Papis finder function - open document directory in Finder with query support
pafinder() {
local result=$(papis list "$@" | head -1)
if [ -n "$result" ]; then
open -R "$result"
else
echo "No documents found"
return 1
fi
}
# Papis finder function - open document directory with query support
${lib.optionalString pkgs.stdenv.isDarwin ''
pafinder() {
local result=$(papis list "$@" | head -1)
if [ -n "$result" ]; then
open -R "$result"
else
echo "No documents found"
return 1
fi
}
''}
${lib.optionalString (!pkgs.stdenv.isDarwin) ''
pafinder() {
local result=$(papis list "$@" | head -1)
if [ -n "$result" ]; then
xdg-open "$(dirname "$result")"
else
echo "No documents found"
return 1
fi
}
''}
# Papis add file function - add file to existing document with proper parameter handling
pafile() {

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
{
# Rsync exclude patterns for common files and directories
@ -40,9 +40,11 @@
--partial
--partial-dir=.rsync-partial
# Preserve extended attributes and ACLs (macOS)
--extended-attributes
--acls
${lib.optionalString pkgs.stdenv.isDarwin ''
# Preserve extended attributes and ACLs (macOS)
--extended-attributes
--acls
''}
# Network optimization
--compress

View file

@ -1,7 +1,7 @@
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
{
home.file."Library/Application Support/termscp/config.toml".text = ''
home.file.${if pkgs.stdenv.isDarwin then "Library/Application Support/termscp/config.toml" else ".config/termscp/config.toml"}.text = ''
# termscp configuration file
# Generated by Nix - see modules/termscp.nix for customization

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }:
{ config, pkgs, lib, ... }:
let
projectsConfig = import ../config/projects.nix { homeDirectory = config.home.homeDirectory; };
@ -21,16 +21,18 @@ in
shellAliases = {
ll = "ls -alF";
zi = "z -i"; # Interactive selection with fzf
preview = "open -a Preview";
slide = "open -a SlidePilot";
pixel = "open -a 'Pixelmator Pro'";
inkscape = "open -a Inkscape";
# Nix helpers
hm = "home-manager";
hms = "home-manager switch --flake ~/.config/nix#yanlin";
hms-offline = "home-manager switch --flake ~/.config/nix#yanlin --option substitute false";
} // lib.optionalAttrs pkgs.stdenv.isDarwin {
# macOS-specific app aliases
preview = "open -a Preview";
slide = "open -a SlidePilot";
pixel = "open -a 'Pixelmator Pro'";
inkscape = "open -a Inkscape";
};
initContent = ''
@ -115,29 +117,31 @@ in
fi
}
# Function to search and open all macOS applications
function app() {
local app_path
local file_to_open="$1"
app_path=$( (find -L /Applications -name "*.app" -maxdepth 2 2>/dev/null; \
find -L ~/Applications -name "*.app" -maxdepth 3 2>/dev/null; \
find /System/Applications -name "*.app" -maxdepth 2 2>/dev/null; \
find /System/Applications/Utilities -name "*.app" -maxdepth 1 2>/dev/null) |
sort | uniq |
fzf --header="Select app to open''${file_to_open:+ file: $file_to_open}" \
--preview 'basename {} .app' \
--preview-window=up:1 \
--height=40%)
if [[ -n "$app_path" ]]; then
if [[ -n "$file_to_open" ]]; then
open -a "$app_path" "$file_to_open"
else
open "$app_path"
# Function to search and open all macOS applications (macOS only)
${lib.optionalString pkgs.stdenv.isDarwin ''
function app() {
local app_path
local file_to_open="$1"
app_path=$( (find -L /Applications -name "*.app" -maxdepth 2 2>/dev/null; \
find -L ~/Applications -name "*.app" -maxdepth 3 2>/dev/null; \
find /System/Applications -name "*.app" -maxdepth 2 2>/dev/null; \
find /System/Applications/Utilities -name "*.app" -maxdepth 1 2>/dev/null) |
sort | uniq |
fzf --header="Select app to open''${file_to_open:+ file: $file_to_open}" \
--preview 'basename {} .app' \
--preview-window=up:1 \
--height=40%)
if [[ -n "$app_path" ]]; then
if [[ -n "$file_to_open" ]]; then
open -a "$app_path" "$file_to_open"
else
open "$app_path"
fi
fi
fi
}
}
''}
# Interactive project launcher with fzf
function proj() {