about summary refs log tree commit diff
path: root/misc
diff options
context:
space:
mode:
Diffstat (limited to 'misc')
-rw-r--r--misc/emacs/README10
-rw-r--r--misc/emacs/local.mk1
-rw-r--r--misc/emacs/nix-mode.el95
-rw-r--r--misc/launchd/local.mk5
-rw-r--r--misc/launchd/org.nixos.nix-daemon.plist.in16
-rw-r--r--misc/systemd/local.mk5
-rw-r--r--misc/systemd/nix-daemon.service.in9
-rw-r--r--misc/systemd/nix-daemon.socket.in11
-rw-r--r--misc/upstart/local.mk5
-rw-r--r--misc/upstart/nix-daemon.conf.in5
-rw-r--r--misc/vim/syntax/nix.vim37
11 files changed, 199 insertions, 0 deletions
diff --git a/misc/emacs/README b/misc/emacs/README
new file mode 100644
index 000000000000..8c87f67d5718
--- /dev/null
+++ b/misc/emacs/README
@@ -0,0 +1,10 @@
+The Nix Emacs mode supports syntax highlighting, somewhat sensible
+indenting, and refilling of comments.
+
+To enable Nix mode in Emacs, add something like this to your ~/.emacs
+file:
+
+  (load "/nix/share/emacs/site-lisp/nix-mode.el")
+
+This automatically causes Nix mode to be activated for all files with
+extension `.nix'.
diff --git a/misc/emacs/local.mk b/misc/emacs/local.mk
new file mode 100644
index 000000000000..8e06b881bcdf
--- /dev/null
+++ b/misc/emacs/local.mk
@@ -0,0 +1 @@
+$(eval $(call install-data-in,$(d)/nix-mode.el,$(datadir)/emacs/site-lisp))
diff --git a/misc/emacs/nix-mode.el b/misc/emacs/nix-mode.el
new file mode 100644
index 000000000000..790799d858cc
--- /dev/null
+++ b/misc/emacs/nix-mode.el
@@ -0,0 +1,95 @@
+;;; nix-mode.el --- Major mode for editing Nix expressions
+
+;; Author: Eelco Dolstra
+;; URL: https://github.com/NixOS/nix/tree/master/misc/emacs
+;; Version: 1.0
+
+;;; Commentary:
+
+;;; Code:
+
+(defconst nix-font-lock-keywords
+  '("\\<if\\>" "\\<then\\>" "\\<else\\>" "\\<assert\\>" "\\<with\\>"
+    "\\<let\\>" "\\<in\\>" "\\<rec\\>" "\\<inherit\\>" "\\<or\\>"
+    ("\\<true\\>" . font-lock-builtin-face)
+    ("\\<false\\>" . font-lock-builtin-face)
+    ("\\<null\\>" . font-lock-builtin-face)
+    ("\\<import\\>" . font-lock-builtin-face)
+    ("\\<derivation\\>" . font-lock-builtin-face)
+    ("\\<baseNameOf\\>" . font-lock-builtin-face)
+    ("\\<toString\\>" . font-lock-builtin-face)
+    ("\\<isNull\\>" . font-lock-builtin-face)
+    ("[a-zA-Z][a-zA-Z0-9\\+-\\.]*:[a-zA-Z0-9%/\\?:@&=\\+\\$,_\\.!~\\*'-]+"
+     . font-lock-constant-face)
+    ("\\<\\([a-zA-Z_][a-zA-Z0-9_'\-\.]*\\)[ \t]*="
+     (1 font-lock-variable-name-face nil nil))
+    ("<[a-zA-Z0-9._\\+-]+\\(/[a-zA-Z0-9._\\+-]+\\)*>"
+     . font-lock-constant-face)
+    ("[a-zA-Z0-9._\\+-]*\\(/[a-zA-Z0-9._\\+-]+\\)+"
+     . font-lock-constant-face))
+  "Font lock keywords for nix.")
+
+(defvar nix-mode-syntax-table
+  (let ((table (make-syntax-table)))
+    (modify-syntax-entry ?/ ". 14" table)
+    (modify-syntax-entry ?* ". 23" table)
+    (modify-syntax-entry ?# "< b" table)
+    (modify-syntax-entry ?\n "> b" table)
+    table)
+  "Syntax table for Nix mode.")
+
+(defun nix-indent-line ()
+  "Indent current line in a Nix expression."
+  (interactive)
+  (indent-relative-maybe))
+
+
+;;;###autoload
+(define-derived-mode nix-mode prog-mode "Nix"
+  "Major mode for editing Nix expressions.
+
+The following commands may be useful:
+
+  '\\[newline-and-indent]'
+    Insert a newline and move the cursor to align with the previous
+    non-empty line.
+
+  '\\[fill-paragraph]'
+    Refill a paragraph so that all lines are at most `fill-column'
+    lines long.  This should do the right thing for comments beginning
+    with `#'.  However, this command doesn't work properly yet if the
+    comment is adjacent to code (i.e., no intervening empty lines).
+    In that case, select the text to be refilled and use
+    `\\[fill-region]' instead.
+
+The hook `nix-mode-hook' is run when Nix mode is started.
+
+\\{nix-mode-map}
+"
+  (set-syntax-table nix-mode-syntax-table)
+
+  ;; Font lock support.
+  (setq font-lock-defaults '(nix-font-lock-keywords nil nil nil nil))
+
+  ;; Automatic indentation [C-j].
+  (set (make-local-variable 'indent-line-function) 'nix-indent-line)
+
+  ;; Indenting of comments.
+  (set (make-local-variable 'comment-start) "# ")
+  (set (make-local-variable 'comment-end) "")
+  (set (make-local-variable 'comment-start-skip) "\\(^\\|\\s-\\);?#+ *")
+
+  ;; Filling of comments.
+  (set (make-local-variable 'adaptive-fill-mode) t)
+  (set (make-local-variable 'paragraph-start) "[ \t]*\\(#+[ \t]*\\)?$")
+  (set (make-local-variable 'paragraph-separate) paragraph-start))
+
+
+;;;###autoload
+(progn
+  (add-to-list 'auto-mode-alist '("\\.nix\\'" . nix-mode))
+  (add-to-list 'auto-mode-alist '("\\.nix.in\\'" . nix-mode)))
+
+(provide 'nix-mode)
+
+;;; nix-mode.el ends here
diff --git a/misc/launchd/local.mk b/misc/launchd/local.mk
new file mode 100644
index 000000000000..0ba722efbf19
--- /dev/null
+++ b/misc/launchd/local.mk
@@ -0,0 +1,5 @@
+ifeq ($(OS), Darwin)
+
+  $(eval $(call install-data-in, $(d)/org.nixos.nix-daemon.plist, $(prefix)/Library/LaunchDaemons))
+
+endif
diff --git a/misc/launchd/org.nixos.nix-daemon.plist.in b/misc/launchd/org.nixos.nix-daemon.plist.in
new file mode 100644
index 000000000000..66fcd155ee9b
--- /dev/null
+++ b/misc/launchd/org.nixos.nix-daemon.plist.in
@@ -0,0 +1,16 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+  <dict>
+    <key>Label</key>
+    <string>org.nixos.nix-daemon</string>
+    <key>RunAtLoad</key>
+    <true/>
+    <key>Program</key>
+    <string>@bindir@/nix-daemon</string>
+    <key>StandardErrorPath</key>
+    <string>/var/log/nix-daemon.log</string>
+    <key>StandardOutPath</key>
+    <string>/dev/null</string>
+  </dict>
+</plist>
diff --git a/misc/systemd/local.mk b/misc/systemd/local.mk
new file mode 100644
index 000000000000..004549fd2776
--- /dev/null
+++ b/misc/systemd/local.mk
@@ -0,0 +1,5 @@
+ifeq ($(OS), Linux)
+
+  $(foreach n, nix-daemon.socket nix-daemon.service, $(eval $(call install-file-in, $(d)/$(n), $(prefix)/lib/systemd/system, 0644)))
+
+endif
diff --git a/misc/systemd/nix-daemon.service.in b/misc/systemd/nix-daemon.service.in
new file mode 100644
index 000000000000..5fc04a3f5713
--- /dev/null
+++ b/misc/systemd/nix-daemon.service.in
@@ -0,0 +1,9 @@
+[Unit]
+Description=Nix Daemon
+RequiresMountsFor=@storedir@
+RequiresMountsFor=@localstatedir@
+ConditionPathIsReadWrite=@localstatedir@/nix/daemon-socket
+
+[Service]
+ExecStart=@@bindir@/nix-daemon nix-daemon --daemon
+KillMode=process
diff --git a/misc/systemd/nix-daemon.socket.in b/misc/systemd/nix-daemon.socket.in
new file mode 100644
index 000000000000..9ed39ffe6eb2
--- /dev/null
+++ b/misc/systemd/nix-daemon.socket.in
@@ -0,0 +1,11 @@
+[Unit]
+Description=Nix Daemon Socket
+Before=multi-user.target
+RequiresMountsFor=@storedir@
+ConditionPathIsReadWrite=@localstatedir@/nix/daemon-socket
+
+[Socket]
+ListenStream=@localstatedir@/nix/daemon-socket/socket
+
+[Install]
+WantedBy=sockets.target
diff --git a/misc/upstart/local.mk b/misc/upstart/local.mk
new file mode 100644
index 000000000000..a73dc061e4fc
--- /dev/null
+++ b/misc/upstart/local.mk
@@ -0,0 +1,5 @@
+ifeq ($(OS), Linux)
+
+  $(foreach n, nix-daemon.conf, $(eval $(call install-file-in, $(d)/$(n), $(sysconfdir)/init, 0644)))
+
+endif
diff --git a/misc/upstart/nix-daemon.conf.in b/misc/upstart/nix-daemon.conf.in
new file mode 100644
index 000000000000..0e806edbd770
--- /dev/null
+++ b/misc/upstart/nix-daemon.conf.in
@@ -0,0 +1,5 @@
+description "Nix Daemon"
+start on filesystem
+stop on shutdown
+respawn
+exec @bindir@/nix-daemon --daemon
diff --git a/misc/vim/syntax/nix.vim b/misc/vim/syntax/nix.vim
new file mode 100644
index 000000000000..ddddea5f0596
--- /dev/null
+++ b/misc/vim/syntax/nix.vim
@@ -0,0 +1,37 @@
+" Vim syntax file
+" Language:	nix
+" Maintainer:	Marc Weber <marco-oweber@gmx.de>
+"               Modify and commit if you feel that way
+" Last Change:	2007 Dec
+
+" Quit when a (custom) syntax file was already loaded
+if exists("b:current_syntax")
+  finish
+endif
+
+syn keyword	nixKeyword	let throw inherit import true false null with
+syn keyword	nixConditional	if else then
+syn keyword     nixBrace        ( ) { } =
+syn keyword     nixBuiltin         __currentSystem __currentTime __isFunction __getEnv __trace __toPath __pathExists 
+  \ __readFile __toXML __toFile __filterSource __attrNames __getAttr __hasAttr __isAttrs __listToAttrs __isList 
+  \ __head __tail __add __sub __lessThan __substring __stringLength
+
+syn match nixAttr "\w\+\ze\s*="
+syn match nixFuncArg "\zs\w\+\ze\s*:"
+syn region nixStringParam start=+\${+ end=+}+
+syn region nixMultiLineComment start=+/\*+ skip=+\\"+ end=+\*/+
+syn match  nixEndOfLineComment "#.*$"
+syn region nixStringIndented start=+''+ skip=+'''\|''${\|"+ end=+''+ contains=nixStringParam
+syn region nixString         start=+"+ skip=+\\"+ end=+"+ contains=nixStringParam
+
+hi def link nixKeyword       Keyword
+hi def link nixConditional   Conditional
+hi def link nixBrace         Special
+hi def link nixString        String
+hi def link nixStringIndented String
+hi def link nixBuiltin       Special
+hi def link nixStringParam   Macro
+hi def link nixMultiLineComment Comment
+hi def link nixEndOfLineComment Comment
+hi def link nixAttr        Identifier
+hi def link nixFuncArg     Identifier