bring back nix-darwin hosts compatability

This commit is contained in:
Yan Lin 2025-11-13 10:40:27 +01:00
parent 1b6a0430d2
commit 0bf4fb87c6
13 changed files with 579 additions and 31 deletions

44
modules/homebrew.nix Normal file
View file

@ -0,0 +1,44 @@
{ config, pkgs, ... }:
{
# Homebrew configuration for package management
homebrew = {
enable = true;
onActivation = {
autoUpdate = true;
cleanup = "zap"; # Removes unlisted formulae/casks
upgrade = true;
};
brews = [
# Command-line tools go here
];
casks = [
# GUI applications - manually installed apps now managed by Homebrew
"keepassxc"
"keycastr"
"inkscape"
"firefox"
"obsidian"
"snipaste"
"ghostty"
"slidepilot"
"tencent-meeting"
"ovito"
"microsoft-powerpoint"
"microsoft-word"
"microsoft-excel"
"rectangle"
];
taps = [
# Additional repositories if needed
];
};
# nix-homebrew configuration for declarative Homebrew installation
nix-homebrew = {
enable = true;
enableRosetta = true; # Apple Silicon support
user = "yanlin";
autoMigrate = true; # Migrate existing Homebrew if present
};
}

View file

@ -334,8 +334,8 @@
# OS settings
os = {
open = "xdg-open {{filename}}";
openLink = "xdg-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

@ -262,12 +262,21 @@ in
action = ":lua open_file_with_system_app()<CR>";
options = { desc = "Open file with system default app"; };
}
] ++ (if pkgs.stdenv.isDarwin then [
{
mode = "n";
key = "<leader>f";
action = ":lua show_file_in_file_manager()<CR>";
options = { desc = "Show current file in Finder"; };
}
] else [
{
mode = "n";
key = "<leader>f";
action = ":!thunar %:h &<CR><CR>";
options = { desc = "Open current file directory in file manager"; };
}
]) ++ [
# Markdown rendering
{
@ -307,11 +316,20 @@ in
})
-- Dictionary completion setup
require("cmp_dictionary").setup({
paths = { "${pkgs.scowl}/share/dict/wamerican.txt" }, -- Nix-provided dictionary
exact_length = 2, -- Minimum length before completion
first_case_insensitive = true, -- Case insensitive matching
})
${lib.optionalString pkgs.stdenv.isDarwin ''
require("cmp_dictionary").setup({
paths = { "/usr/share/dict/words" }, -- Standard dictionary path on macOS
exact_length = 2, -- Minimum length before completion
first_case_insensitive = true, -- Case insensitive matching
})
''}
${lib.optionalString (!pkgs.stdenv.isDarwin) ''
require("cmp_dictionary").setup({
paths = { "${pkgs.scowl}/share/dict/wamerican.txt" }, -- Nix-provided dictionary on NixOS
exact_length = 2, -- Minimum length before completion
first_case_insensitive = true, -- Case insensitive matching
})
''}
-- Jupytext setup for Jupyter notebook viewing
require("jupytext").setup({
@ -352,18 +370,21 @@ in
}
-- OSC-52 clipboard integration (matches tmux setup, works with Ghostty)
-- This enables clipboard functionality across SSH and tmux
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
-- This enables clipboard functionality across SSH, tmux, and multi-platform
-- Only enabled on Linux; macOS uses native clipboard with "unnamedplus"
${lib.optionalString (!pkgs.stdenv.isDarwin) ''
vim.g.clipboard = {
name = 'OSC 52',
copy = {
['+'] = require('vim.ui.clipboard.osc52').copy('+'),
['*'] = require('vim.ui.clipboard.osc52').copy('*'),
},
paste = {
['+'] = require('vim.ui.clipboard.osc52').paste('+'),
['*'] = require('vim.ui.clipboard.osc52').paste('*'),
},
}
''}
-- Close all buffers except current (preserving NvimTree and other special buffers)
function close_other_buffers()
@ -388,13 +409,28 @@ in
function open_file_with_system_app()
local filepath = vim.fn.expand('%:p')
if filepath ~= "" then
-- Use jobstart for async execution (detach = true prevents blocking)
vim.fn.jobstart({'xdg-open', filepath}, {detach = true})
local escaped_path = vim.fn.shellescape(filepath)
${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
${lib.optionalString pkgs.stdenv.isDarwin ''
function show_file_in_file_manager()
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
''}
-- Render-markdown setup (off by default, toggle with <space>+m)
require("render-markdown").setup({
enabled = false, -- Off by default, use <space>+m to toggle

View file

@ -1,5 +1,10 @@
{ pkgs, lib, ... }:
let
# Platform-aware papis config directory
papisConfigDir = if pkgs.stdenv.isDarwin then "Library/Application Support/papis" else ".config/papis";
in
{
# Install papis package
home.packages = [
@ -8,11 +13,11 @@
}))
];
# Papis configuration
home.file.".config/papis/config".text = ''
home.file."${papisConfigDir}/config".text = ''
[settings]
default-library = main
editor = nvim
opentool = evince
opentool = ${if pkgs.stdenv.isDarwin then "open -a Preview" else "evince"}
# Document management
ref-format = {doc[author]}{doc[year]}
@ -43,7 +48,7 @@
'';
# Papis bibliography template
home.file.".config/papis/templates/bibitem.template".text = ''
home.file."${papisConfigDir}/templates/bibitem.template".text = ''
{doc[title]} ({doc[year]}). {doc[author]}.
Venue: {doc[journal]} {doc[booktitle]} {doc[eprinttype]} {doc[eprint]} {doc[eventtitle]}
Tags: {doc[tags]}
@ -52,7 +57,7 @@
'';
# Papis BibTeX template
home.file.".config/papis/templates/bibtex.template".text = ''
home.file."${papisConfigDir}/templates/bibtex.template".text = ''
@{doc[type]}{{{doc[ref]},
author = {{{doc[author]}}},
title = {{{doc[title]}}},
@ -68,23 +73,23 @@
'';
# Papis citation template
home.file.".config/papis/templates/citation.template".text = ''
home.file."${papisConfigDir}/templates/citation.template".text = ''
{doc[author]}. "{doc[title]}." {doc[journal]}{doc[booktitle]} ({doc[year]}).
'';
# Shell aliases for papis workflow
programs.zsh.shellAliases = {
# Bibliography formatting
pals = "papis list --template \"$HOME/.config/papis/templates/bibitem.template\"";
pals = "papis list --template \"$HOME/${papisConfigDir}/templates/bibitem.template\"";
# Add new entry with bibtex
paadd = "papis add --from bibtex";
# BibTeX export
pabib = "papis list --template \"$HOME/.config/papis/templates/bibtex.template\"";
pabib = "papis list --template \"$HOME/${papisConfigDir}/templates/bibtex.template\"";
# Citation formatting
pacite = "papis list --template \"$HOME/.config/papis/templates/citation.template\"";
pacite = "papis list --template \"$HOME/${papisConfigDir}/templates/citation.template\"";
# File operations
paurl = "papis addto -u";

View file

@ -23,6 +23,12 @@
--partial
--partial-dir=.rsync-partial
${lib.optionalString pkgs.stdenv.isDarwin ''
# Preserve extended attributes and ACLs (macOS)
--extended-attributes
--acls
''}
# Network optimization
--compress
--compress-level=6

View file

@ -114,6 +114,11 @@ in
};
};
# Override the launchd agent to add RunAtLoad on macOS
launchd.agents.syncthing = lib.mkIf (pkgs.stdenv.isDarwin && config.services.syncthing.enable) {
config.RunAtLoad = true;
};
# Deploy .stignore files to synced folders (only for enabled folders)
home.file = lib.mkMerge [
(lib.mkIf (lib.elem "Credentials" cfg.enabledFolders) {

View file

@ -3,7 +3,7 @@
{
# Install termscp package
home.packages = [ pkgs.termscp ];
home.file.".config/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