This repository has been archived by the owner on May 12, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathnixops-tramp.el
110 lines (90 loc) · 3.94 KB
/
nixops-tramp.el
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
;;; nixops-tramp.el --- TRAMP integration for nixops deployments -*- lexical-binding: t -*-
;; Copyright (C) 2017 Mario Rodas <[email protected]>
;; Author: Mario Rodas <[email protected]>
;; URL:
;; Keywords: nixops, convenience
;; Version: 0.1
;; Package-Requires: ((emacs "24") (cl-lib "0.5"))
;; This file is NOT part of GNU Emacs.
;;; License:
;; This program is free software; you can redistribute it and/or modify
;; it under the terms of the GNU General Public License as published by
;; the Free Software Foundation, either version 3 of the License, or
;; (at your option) any later version.
;; This program is distributed in the hope that it will be useful,
;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;; GNU General Public License for more details.
;; You should have received a copy of the GNU General Public License
;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;; Commentary:
;;
;; `nixops-tramp.el' offers a TRAMP method for [nixops][] deployments.
;;
;; ## Usage
;;
;; Offers the TRAMP method `nixops` to access nixops deployments
;;
;; C-x C-f /nixops:machine@deployment:/path/to/file
;;
;; where
;; machine (required) is the name of the machine you want to use
;; deployment (required) is the name of the nixops deployment
;;
;; [nixops]: https://github.com/NixOS/nixops "NixOS cloud provisioning and deployment tool"
;;; Code:
(eval-when-compile (require 'cl-lib))
(require 'tramp)
(defgroup nixops-tramp nil
"TRAMP integration for nixops deployments."
:prefix "nixops-tramp-"
:group 'applications)
(defcustom nixops-tramp-nixops-executable "nixops"
"Path to nixops executable."
:type 'string
:group 'nixops-tramp)
(defcustom nixops-tramp-nixops-ssh-options nil
"List of nixops ssh options."
:type '(repeat string)
:group 'nixops-tramp)
(defcustom nixops-tramp-nixops-scp-options nil
"List of nixops scp options."
:type '(repeat string)
:group 'nixops-tramp)
;;;###autoload
(defconst nixops-tramp-method "nixops"
"Method to connect nixops machines.")
;;;###autoload
(defconst nixops-tramp-completion-function-alist
'((nixops-tramp-machines-and-deployments ""))
"Default list of (FUNCTION FILE) pairs to be examined for nixops method.")
(defun nixops-tramp-machines-and-deployments (&optional _ignored)
"Return a list of (machine deployment) tuples allowed to access.
TRAMP calls this function with a filename which is IGNORED."
(cl-loop for line in (ignore-errors (process-lines nixops-tramp-nixops-executable "info" "--all" "--plain"))
collect (cl-multiple-value-bind (_resource-id deployment machine _status _type _ip-address)
(split-string line "[\t]+" 'omit-nulls)
(list machine deployment))))
;;;###autoload
(defun nixops-tramp-add-method ()
"Add nixops tramp method."
(add-to-list 'tramp-methods
`(,nixops-tramp-method
(tramp-login-program ,nixops-tramp-nixops-executable)
(tramp-login-args (("ssh") ,nixops-tramp-nixops-ssh-options
("-d") ("%h") ("%u") ("-p" "%p")
("%c") ("-e" "none")))
(tramp-remote-shell "/bin/sh")
(tramp-remote-shell-login ("-l"))
(tramp-remote-shell-args ("-c"))
(tramp-copy-program ,nixops-tramp-nixops-executable)
(tramp-copy-args (("scp") (,nixops-tramp-nixops-scp-options ("-d") ("%h") ("%u"))))
(tramp-copy-keep-date t)
(tramp-copy-recursive t))))
;;;###autoload
(eval-after-load 'tramp
'(progn
(nixops-tramp-add-method)
(tramp-set-completion-function nixops-tramp-method nixops-tramp-completion-function-alist)))
(provide 'nixops-tramp)
;;; nixops-tramp.el ends here