Skip to content

Commit d95c500

Browse files
committed
fix: vterm remote shell + nextcloud
1 parent eff1e42 commit d95c500

File tree

11 files changed

+408
-150
lines changed

11 files changed

+408
-150
lines changed

SwarselSystems.org

Lines changed: 260 additions & 112 deletions
Large diffs are not rendered by default.

modules/nixos/setup.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,4 +16,5 @@ in
1616
options.swarselsystems.server.spotifyd = lib.mkEnableOption "enable spotifyd on server";
1717
options.swarselsystems.server.mpd = lib.mkEnableOption "enable mpd on server";
1818
options.swarselsystems.server.matrix = lib.mkEnableOption "enable matrix on server";
19+
options.swarselsystems.server.nextcloud = lib.mkEnableOption "enable nextcloid on server";
1920
}

profiles/common/home/emacs.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
};
4848

4949
services.emacs = {
50-
enable = false;
50+
enable = true;
5151
# socketActivation.enable = false;
5252
# startWithUserSession = "graphical";
5353
};

profiles/common/home/zsh.nix

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,36 @@
5151
}
5252
];
5353
initExtra = ''
54-
bindkey "^[[1;5D" backward-word
55-
bindkey "^[[1;5C" forward-word
54+
bindkey "^[[1;5D" backward-word
55+
bindkey "^[[1;5C" forward-word
56+
57+
vterm_printf() {
58+
if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then
59+
# Tell tmux to pass the escape sequences through
60+
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
61+
elif [ "''${TERM%%-*}" = "screen" ]; then
62+
# GNU screen (screen, screen-256color, screen-256color-bce)
63+
printf "\eP\e]%s\007\e\\" "$1"
64+
else
65+
printf "\e]%s\e\\" "$1"
66+
fi
67+
}
68+
vterm_prompt_end() {
69+
vterm_printf "51;A$(whoami)@$(hostname):$(pwd)"
70+
}
71+
setopt PROMPT_SUBST
72+
PROMPT=$PROMPT'%{$(vterm_prompt_end)%}'
73+
74+
vterm_cmd() {
75+
local vterm_elisp
76+
vterm_elisp=""
77+
while [ $# -gt 0 ]; do
78+
vterm_elisp="$vterm_elisp""$(printf '"%s" ' "$(printf "%s" "$1" | sed -e 's|\\|\\\\|g' -e 's|"|\\"|g')")"
79+
shift
80+
done
81+
vterm_printf "51;E$vterm_elisp"
82+
}
5683
57-
vterm_printf() {
58-
if [ -n "$TMUX" ] && ([ "''${TERM%%-*}" = "tmux" ] || [ "''${TERM%%-*}" = "screen" ]); then
59-
# Tell tmux to pass the escape sequences through
60-
printf "\ePtmux;\e\e]%s\007\e\\" "$1"
61-
elif [ "''${TERM%%-*}" = "screen" ]; then
62-
# GNU screen (screen, screen-256color, screen-256color-bce)
63-
printf "\eP\e]%s\007\e\\" "$1"
64-
else
65-
printf "\e]%s\e\\" "$1"
66-
fi
67-
}
6884
'';
6985
};
7086
}

profiles/common/nixos/default.nix

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
# ./yubikey-touch-detector.nix
3636
./safeeyes.nix
3737
./lid.nix
38-
./emacs.nix
3938
];
4039

4140
nix =

profiles/common/nixos/sops.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,10 +47,11 @@ in
4747
WIREGUARDENDPOINT=${config.sops.placeholder.wireguardendpoint}
4848
'';
4949
".authinfo" = {
50+
owner = "swarsel";
5051
path = "${config.users.users.swarsel.home}/.emacs.d/.authinfo";
5152
content = ''
5253
machine stash.swarsel.win:443 port https login ${config.sops.placeholder.stashuser} password ${config.sops.placeholder.stashpass}
53-
machine gitlab.com/api/v4 login ${config.sops.placeholder.githubforgeuser} password glpat-72Wpzs2uuz--LfNHZFzW ${config.sops.placeholder.githubforgepass}
54+
machine gitlab.com/api/v4 login ${config.sops.placeholder.githubforgeuser} password ${config.sops.placeholder.githubforgepass}
5455
machine api.github.com login ${config.sops.placeholder.gitlabforgeuser} password ${config.sops.placeholder.gitlabforgepass}
5556
'';
5657
};

profiles/server/common/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
./spotifyd.nix
2020
./mpd.nix
2121
./matrix.nix
22+
./nextcloud.nix
2223
];
2324

2425
nix =

profiles/server/winters/default.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@
4747
spotifyd = true;
4848
mpd = false;
4949
matrix = true;
50+
nextcloud = true;
5051
};
5152
};
5253

profiles/server1/nginx/nixos.nix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@
7070
recommendedGzipSettings = true;
7171
virtualHosts = {
7272

73+
7374
"stash.swarsel.win" = {
7475
enableACME = true;
7576
forceSSL = true;

programs/emacs/init.el

Lines changed: 109 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1409,6 +1409,8 @@ create a new one."
14091409
"-o ControlMaster=auto -o ControlPersist=yes"))
14101410
)
14111411

1412+
(setq vterm-tramp-shells '(("ssh" "'sh'")))
1413+
14121414
(use-package diff-hl
14131415
:hook
14141416
((prog-mode
@@ -1861,23 +1863,110 @@ create a new one."
18611863
(use-package vterm
18621864
:ensure t)
18631865

1864-
(use-package mmm-mode)
1865-
(setq mmm-global-mode 'maybe)
1866-
(mmm-add-mode-ext-class 'org-mode nil 'org-nix)
1867-
(mmm-add-mode-ext-class 'org-mode nil 'org-elisp)
1868-
1869-
(mmm-add-group
1870-
'org-nix
1871-
'((nix-src-block
1872-
:submode nix-mode
1873-
:face org-block
1874-
:front "#\\+BEGIN_SRC nix.*\n"
1875-
:back "#\\+END_SRC")))
1876-
1877-
(mmm-add-group
1878-
'org-elisp
1879-
'((elisp-src-block
1880-
:submode emacs-lisp-mode
1881-
:face org-block
1882-
:front "#\\+BEGIN_SRC emacs-lisp.*\n"
1883-
:back "#\\+END_SRC")))
1866+
(defun sudo-find-file (file-name)
1867+
"Like find file, but opens the file as root."
1868+
(interactive "FSudo Find File: ")
1869+
(let ((tramp-file-name (concat "/sudo::" (expand-file-name file-name))))
1870+
(find-file tramp-file-name)))
1871+
;;; vterm/config.el -*- lexical-binding: t; -*-
1872+
1873+
;; Original functions overwrites tramp path with a guessed path.
1874+
;; However it breaks if remote fqdn/hostname is not resolvale by local machine
1875+
;; could also break on port forwarding, multihops,
1876+
;; custom protocol such as: docker, vagrant, ...
1877+
;; *if* you try to shell-side configure them.
1878+
;; Easily testable with vagrant ssh port on localhost.
1879+
;; My workflow is to open a tramp dired on / of the remote to get a
1880+
;; "foothold" then open vterms from there.
1881+
(defun vterm--get-directory (path)
1882+
"[OVERLOADED] Get normalized directory to PATH."
1883+
(when path
1884+
(let (directory)
1885+
(if (string-match "^\\(.*?\\)@\\(.*?\\):\\(.*?\\)$" path)
1886+
(progn
1887+
(let ((user (match-string 1 path))
1888+
(host (match-string 2 path))
1889+
(dir (match-string 3 path)))
1890+
(if (and (string-equal user user-login-name)
1891+
(string-equal host (system-name)))
1892+
(progn
1893+
(when (file-directory-p dir)
1894+
(setq directory (file-name-as-directory dir))))
1895+
(setq directory
1896+
;; Bellow is what i altered
1897+
(file-name-as-directory (concat (file-remote-p default-directory) dir))))))
1898+
(when (file-directory-p path)
1899+
(setq directory (file-name-as-directory path))))
1900+
directory)))
1901+
;; Injects the payload to the vterm buffer.
1902+
(defun me/vterm-load-config ()
1903+
"Pass local configuration files to vterm.
1904+
1905+
Allows remote vterm to be shell-side configured,
1906+
without altering remote config.
1907+
Also adds my personal configuration that does not rely
1908+
too much on external packages.
1909+
Prints a reasuring message to proove good faith."
1910+
(interactive)
1911+
(let (;; Bellow messages to reassure other users that look at history
1912+
(reasuring-message (format "Configuring shell of user %s to be emacs comptible"
1913+
user-full-name))
1914+
(reasuring-notice "This action is shell local, it will not affect other shells")
1915+
;; Bellow lies my configuration
1916+
(basic-func-script (f-read-text (concat (getenv "HOME")
1917+
"/.emacs.d/shells/sources/functions.sh")))
1918+
;; Bellow lies the vterm shell-side configuration
1919+
;; Must be sourced last
1920+
(vterm-func-script (f-read-text (concat
1921+
(file-name-directory (find-library-name "vterm"))
1922+
"/etc/emacs-vterm-bash.sh"))))
1923+
(vterm-insert (format "# START: %s\n" reasuring-message))
1924+
(vterm-insert (format "# %s\n" reasuring-notice))
1925+
;; Create one single block in history
1926+
(vterm-insert "{\n")
1927+
(vterm-insert basic-func-script)
1928+
(vterm-insert vterm-func-script)
1929+
(vterm-insert "}\n")
1930+
;; End the single block in history
1931+
(vterm-insert (format "# %s\n" reasuring-notice))
1932+
(vterm-insert (format "# STOP: %s\n" reasuring-message))
1933+
)
1934+
)
1935+
1936+
;; find-file-other-window does not works great on remote:
1937+
;; if given an absolute path on a remote host,
1938+
;; the path will be understood as a local file since no
1939+
;; tramp prefix is present, and bash does not care
1940+
;; about tramp prefixes.
1941+
;; Bellow we solve context before sending it to
1942+
;; ffow
1943+
(defun me/vterm--find-file-other-window-wrapper (file)
1944+
"Help vterm find a FILE."
1945+
(find-file-other-window (me/vterm--ffow-resolver file)))
1946+
(defun me/vterm--ffow-resolver (file)
1947+
"Help vterm resolve FILE."
1948+
(cond
1949+
;; "/sudo::"
1950+
;; doom--sudo-file-path do the trick for us
1951+
((s-starts-with-p "/sudo::" file)
1952+
(sudo-find-file
1953+
(concat (file-remote-p default-directory)
1954+
(substring-no-properties file 7))))
1955+
;; "/" means we want the "Relative root"
1956+
;; try appending the remote prefix if relevent
1957+
((s-starts-with-p "/" file)
1958+
(concat (file-remote-p default-directory) file))
1959+
;; we got a relative path
1960+
;; we don't need to help ffow to find it
1961+
(t
1962+
file)))
1963+
1964+
;; The variable vterm-eval-cmds is a SERIOUSLY SENSIBLE variable !
1965+
;; Do not be the guy that adds RCE into their config !
1966+
1967+
;; Allow customed ffow to be called from vterm
1968+
;; ffow should be as safe as find-file which is already trusted
1969+
;; we append our resolver that only manipulate strings,
1970+
;; Proove me wrong but i think it's safe.
1971+
(add-to-list 'vterm-eval-cmds '("find-file-other-window"
1972+
me/vterm--find-file-other-window-wrapper))

secrets/server/winters/secrets.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ vpnprot: ENC[AES256_GCM,data:/NV2,iv:wVvlcdisq2PdLeNpaxE7cwBsKEJgoi/MAmWoTgHFMbQ
3232
vpnloc: ENC[AES256_GCM,data:U8ModKho4vSHnMo9BOE978V6ZlMeQEoLaFW/,iv:Sw06YsWSZ4tGt/TRhRGkU4KdLBcmZTCY4mGqQbpEh7Q=,tag:kDoTkpzXZKEUIa1CSh3Pwg==,type:str]
3333
#ENC[AES256_GCM,data:yp7ApA4YLSk=,iv:O/SQxKe9EWqExHbeKsTXvbst0pjCxy3yiOjmeCVjmdY=,tag:RMkAOLOLCodnPSDEuImwRw==,type:comment]
3434
swarseluser: ENC[AES256_GCM,data:XvmOHYFNhb/bAYAZ/kmUWbbmRy/WrxSYri/Y5k+SH4N7ZIjuZDHOkWk93ERFuTb77HvhbPX/NRQraUoJoFsxGGg5co/gJnyfRg==,iv:J50PeDcC4PM3+yQ/YQNb8TW4kubwi2kjjSFU0RVFM30=,tag:ydLYkz1YKyguGZZZD/JcLA==,type:str]
35+
nextcloudadminpass: ENC[AES256_GCM,data:ZOCsu4/ijfheBfY9ZR5DBXSB,iv:bNlTLKQblnt2eYJqVgXwCaGAyAw2yhlb9Whsz0LBhm4=,tag:VQAWP/b8IghzXDFLJxXZ4Q==,type:str]
3536
sops:
3637
kms: []
3738
gcp_kms: []
@@ -47,8 +48,8 @@ sops:
4748
SHJMUFJSeGRQcTIyU1U5RXkvQi9NMzQKm8SP9jQ4fuIuddzqP+m6EJg7+zkX53jz
4849
bHaMPuLTaIHaaSDlVYe5stpyPDlZQ0NSGWV+HaIXkLZNfNM71hWYBQ==
4950
-----END AGE ENCRYPTED FILE-----
50-
lastmodified: "2024-09-28T12:53:10Z"
51-
mac: ENC[AES256_GCM,data:Nj6hZlzRJyMB7v54hp2rGCBx02vVD/DR+LAB/l9nT4OIIfQ2mUY3IF+lCSZIwMv6ZsupLHKjAjkgbBWJzOFbcMl3bPP8OTU3sR5Gkf3TjmhyCacUWmSQ1jYhs6T9kcFx1ijyBWVo5cdMG8sJQxtvPeTqzRLruzTiLVoSs/H/iqY=,iv:6qPguq8IZZgZt8OG8JcXQeq/aqgrHZVVS/2FRgH1EB8=,tag:i/80H90klVHBR6QAKBTn8Q==,type:str]
51+
lastmodified: "2024-10-04T08:36:13Z"
52+
mac: ENC[AES256_GCM,data:hQv1wB6bajUwKDIDObgbl15zrTjWjjq2ikEzn4WnnZs5ugqfFbNmqbWeadLhHSGjjUHNJy/9zQkM52Q0t2c4KOWY15F+ZcaQvlLB1pYF7zqOAmf1l9ruVOvuegCsFQBT4rZ0Z9XWrt+gacVtfrQa0IPxNyMWEaTHEIsGqfdaCEc=,iv:Kz1Occpgg2dX51v/UF4Ix2Zg60+uZG9oOrXX5T+ElJg=,tag:fg8FaThsSkLYEEniNo7ihg==,type:str]
5253
pgp:
5354
- created_at: "2024-09-23T20:03:08Z"
5455
enc: |-

0 commit comments

Comments
 (0)