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 = { programs.lazygit = {
@ -334,8 +334,8 @@
# OS settings # OS settings
os = { os = {
open = "open {{filename}}"; open = if pkgs.stdenv.isDarwin then "open {{filename}}" else "xdg-open {{filename}}";
openLink = "open {{link}}"; openLink = if pkgs.stdenv.isDarwin then "open {{link}}" else "xdg-open {{link}}";
}; };
# Disable startup popup # Disable startup popup

View file

@ -1,4 +1,4 @@
{ pkgs, ... }: { pkgs, lib, ... }:
{ {
programs.nixvim = { programs.nixvim = {
@ -265,17 +265,21 @@
} }
} }
-- Unicode-safe file operations for macOS -- Unicode-safe file operations
function open_file_with_system_app() function open_file_with_system_app()
local filepath = vim.fn.expand('%:p') local filepath = vim.fn.expand('%:p')
if filepath ~= "" then if filepath ~= "" then
local escaped_path = vim.fn.shellescape(filepath) 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 else
print("No file to open") print("No file to open")
end end
end end
${lib.optionalString pkgs.stdenv.isDarwin ''
function show_file_in_finder() function show_file_in_finder()
local filepath = vim.fn.expand('%:p') local filepath = vim.fn.expand('%:p')
if filepath ~= "" then if filepath ~= "" then
@ -285,6 +289,7 @@
print("No file to show") print("No file to show")
end end
end end
''}
''; '';
}; };
} }

View file

@ -1,13 +1,13 @@
{ pkgs, ... }: { pkgs, lib, ... }:
{ {
# Papis configuration # 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] [settings]
default-library = main default-library = main
editor = nvim editor = nvim
opentool = open opentool = ${if pkgs.stdenv.isDarwin then "open" else "xdg-open"}
file-browser = open file-browser = ${if pkgs.stdenv.isDarwin then "open" else "xdg-open"}
# Document management # Document management
ref-format = {doc[author]}{doc[year]} ref-format = {doc[author]}{doc[year]}
@ -93,7 +93,8 @@
# Shell functions for papis workflow # Shell functions for papis workflow
programs.zsh.initContent = '' programs.zsh.initContent = ''
# Papis finder function - open document directory in Finder with query support # Papis finder function - open document directory with query support
${lib.optionalString pkgs.stdenv.isDarwin ''
pafinder() { pafinder() {
local result=$(papis list "$@" | head -1) local result=$(papis list "$@" | head -1)
if [ -n "$result" ]; then if [ -n "$result" ]; then
@ -103,6 +104,18 @@
return 1 return 1
fi 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 # Papis add file function - add file to existing document with proper parameter handling
pafile() { pafile() {

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }: { config, pkgs, lib, ... }:
{ {
# Rsync exclude patterns for common files and directories # Rsync exclude patterns for common files and directories
@ -40,9 +40,11 @@
--partial --partial
--partial-dir=.rsync-partial --partial-dir=.rsync-partial
${lib.optionalString pkgs.stdenv.isDarwin ''
# Preserve extended attributes and ACLs (macOS) # Preserve extended attributes and ACLs (macOS)
--extended-attributes --extended-attributes
--acls --acls
''}
# Network optimization # Network optimization
--compress --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 # termscp configuration file
# Generated by Nix - see modules/termscp.nix for customization # Generated by Nix - see modules/termscp.nix for customization

View file

@ -1,4 +1,4 @@
{ config, pkgs, ... }: { config, pkgs, lib, ... }:
let let
projectsConfig = import ../config/projects.nix { homeDirectory = config.home.homeDirectory; }; projectsConfig = import ../config/projects.nix { homeDirectory = config.home.homeDirectory; };
@ -21,16 +21,18 @@ in
shellAliases = { shellAliases = {
ll = "ls -alF"; ll = "ls -alF";
zi = "z -i"; # Interactive selection with fzf 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 # Nix helpers
hm = "home-manager"; hm = "home-manager";
hms = "home-manager switch --flake ~/.config/nix#yanlin"; hms = "home-manager switch --flake ~/.config/nix#yanlin";
hms-offline = "home-manager switch --flake ~/.config/nix#yanlin --option substitute false"; 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 = '' initContent = ''
@ -115,7 +117,8 @@ in
fi fi
} }
# Function to search and open all macOS applications # Function to search and open all macOS applications (macOS only)
${lib.optionalString pkgs.stdenv.isDarwin ''
function app() { function app() {
local app_path local app_path
local file_to_open="$1" local file_to_open="$1"
@ -138,6 +141,7 @@ in
fi fi
fi fi
} }
''}
# Interactive project launcher with fzf # Interactive project launcher with fzf
function proj() { function proj() {