#!/usr/bin/env bash # Droidnix: Emacs configuration setup for Nix/Org tangling, HTML export # For NixOS systems - assumes Emacs is already installed via Nix/NixOS set -euo pipefail # Create a minimal Emacs config for package installation TEMP_CONFIG=$(mktemp /tmp/droidnix-emacs-setup.XXXXXX.el) cat > "$TEMP_CONFIG" << 'EOF' ;; Minimal config for installing packages (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) EOF # Install packages in batch mode with error handling echo "Installing Emacs packages..." emacs --batch \ --load "$TEMP_CONFIG" \ --eval "(package-refresh-contents)" \ --eval "(package-install 'use-package)" \ --eval "(package-install 'org)" \ --eval "(package-install 'org-plus-contrib)" \ --eval "(package-install 'nix-mode)" \ --eval "(package-install 'htmlize)" \ --eval "(package-install 'catppuccin-theme)" \ --eval "(package-install 'org-bullets)" \ --eval "(package-install 'magit)" \ --eval "(package-install 'company)" \ --eval "(package-install 'flycheck)" \ --eval "(package-install 'doom-modeline)" \ --eval "(package-install 'which-key)" \ --eval "(package-install 'projectile)" \ --eval "(package-install 'ivy)" \ --eval "(package-install 'counsel)" \ --eval "(package-install 'all-the-icons)" \ --eval "(package-install 'doom-themes)" \ --eval "(package-install 'treemacs)" \ --eval "(package-install 'lsp-mode)" \ --eval "(package-install 'ob-shell)" \ --eval "(package-install 'ob-nix)" \ --eval "(package-install 'dashboard)" # Create a post-install config for interactive use USER_EMACSCONFIG="${HOME}/.emacs.d/init.el" if [ ! -f "$USER_EMACSCONFIG" ]; then mkdir -p "${HOME}/.emacs.d" cat > "$USER_EMACSCONFIG" << 'EOF' ;; Droidnix Emacs Configuration for NixOS (require 'package) (add-to-list 'package-archives '("melpa" . "https://melpa.org/packages/") t) (package-initialize) ;; Basic UI improvements (tool-bar-mode -1) ; Disable toolbar (menu-bar-mode -1) ; Disable menu bar (scroll-bar-mode -1) ; Disable scroll bar (setq inhibit-startup-message t) ; Disable startup message (setq make-backup-files nil) ; Disable backup files (setq auto-save-default nil) ; Disable auto-save files ;; Enable Catppuccin Mocha theme (when (fboundp 'load-theme) (ignore-errors (load-theme 'catppuccin-mocha t) (setq catppuccin-disable-term-colors nil) (setq catppuccin-enable-bold t) (setq catppuccin-enable-italic t))) ;; Enable Doom Modeline (when (fboundp 'doom-modeline-mode) (doom-modeline-mode 1)) ;; Enable All The Icons (when (fboundp 'all-the-icons-install-fonts) (all-the-icons-install-fonts) (global-all-the-icons-mode)) ;; Enable Treemacs (when (fboundp 'treemacs) (treemacs-mode) (setq treemacs-width 30) (setq treemacs-position 'left) (setq treemacs-space-between-root-nodes nil) (setq treemacs-indent-level 2) (setq treemacs-file-follow-delay 0.1) (setq treemacs-git-icon-enabled t) (setq treemacs-project-follow t) (setq treemacs-display-project-root t) (setq treemacs-show-hidden-files t)) ;; Enable Company for autocomplete (when (fboundp 'company-mode) (global-company-mode) (setq company-idle-delay 0.1) (setq company-minimum-prefix-length 1)) ;; Enable Flycheck for syntax checking (when (fboundp 'flycheck-mode) (global-flycheck-mode) (setq flycheck-check-syntax-automatically '(save mode-enabled)) (setq flycheck-display-errors-delay 0.5)) ;; Enable Ivy + Counsel for better completion (when (fboundp 'ivy-mode) (ivy-mode 1) (setq ivy-use-virtual-buffers t) (setq ivy-count-format "(%d/%d) ") (setq ivy-height 10) (when (fboundp 'counsel-mode) (counsel-mode 1))) ;; Enable Projectile for project management (when (fboundp 'projectile-mode) (projectile-mode +1) (define-key projectile-mode-map (kbd "C-c p") 'projectile-command-map) (setq projectile-completion-system 'ivy) (setq projectile-switch-project-action 'projectile-dired)) ;; Enable Which Key for keybindings help (when (fboundp 'which-key-mode) (which-key-mode 1) (setq which-key-idle-delay 0.5) (setq which-key-show-major-modes nil)) ;; Configure Org Mode (require 'org) (require 'ob-shell) ; Required for shell code blocks (require 'ob-nix) ; Required for nix code blocks (org-babel-do-load-languages 'org-babel-load-languages '((emacs-lisp . t) (nix . t) (shell . t) (python . t) (dockerfile . t))) (setq org-babel-tangle-lang-exts '(("nix" . "nix"))) (setq org-src-fontify-natively t) (setq org-src-tab-act-as-tab t) (setq org-edit-src-content-indentation 0) (setq org-startup-indented t) (setq org-startup-folded nil) (setq org-ellipsis "⤵") (setq org-hide-emphasis-markers t) (setq org-image-actual-width nil) (setq org-html-htmlize-output-type 'css) (setq org-export-with-toc nil) (setq org-todo-keywords '("TODO" "DOING" "|" "DONE" "CANCELED")) (setq org-log-done 'time) (setq org-directory "~/org") (when (fboundp 'org-bullets-mode) (add-hook 'org-mode-hook (lambda () (org-bullets-mode 1)))) ;; Enable Magit for Git (when (fboundp 'magit-version) (setq magit-display-buffer-function 'magit-display-buffer-fullscreen) (setq magit-last-seen-setup-instruction "1.4.0")) ;; Enable LSP Mode for language server support (when (fboundp 'lsp-mode) (lsp-mode 1) (setq lsp-keymap-prefix "C-c l") (setq lsp-enable-snippets nil) (setq lsp-enable-indentation nil) (setq lsp-enable-on-type-formatting nil) (setq lsp-lens-enable nil) (setq lsp-signature-auto-activate nil)) ;; Enable Dashboard (when (fboundp 'dashboard-refresh-buffer) (dashboard-mode 1) (setq dashboard-items '((recents . 5) (projects . 5) (agenda . 5) (bookmarks . 5))) (setq dashboard-center-content t) (setq dashboard-banner-logo-title "Droidnix Configuration")) ;; Enable Nix Mode (when (fboundp 'nix-mode) (setq auto-mode-alist (cons '("\\.nix\\'" . nix-mode) auto-mode-alist)) (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))) ;; Custom keybindings (global-set-key (kbd "C-c t") 'treemacs) (global-set-key (kbd "C-c p") 'projectile-command-map) (global-set-key (kbd "C-c g") 'magit-status) (global-set-key (kbd "C-c d") 'dashboard-refresh-buffer) (global-set-key (kbd "C-c b") 'ivy-switch-buffer) (global-set-key (kbd "C-c f") 'find-file) (global-set-key (kbd "C-c s") 'save-buffer) (global-set-key (kbd "C-c q") 'kill-buffer) (global-set-key (kbd "C-c w") 'widen) (global-set-key (kbd "C-c n") 'narrow-to-region) ;; Nix-specific configurations (setq nix-indent-width 2) (setq nix-continuation-indent-width 4) ;; HTML export settings for Org (setq org-html-head-include-default-style nil) (setq org-html-head-extra " ") ;; Function to wrap tree output in div for HTML export (defun my/org-wrap-tree-in-div () "Wrap the Nix tree output in a div with class 'tree' for HTML export." (interactive) (save-excursion (goto-char (point-min)) (when (re-search-forward "#+RESULTS:\n#+BEGIN_EXAMPLE\n\\(.*?\n\\)#+END_EXAMPLE" nil t) (goto-char (match-beginning 1)) (insert "#+HTML: