From 3116d34994cdcc8c264781397c62d38a2f0fae71 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Fri, 29 Nov 2024 21:27:08 -0500 Subject: [PATCH] Add nix support to emacs. --- ansible/roles/emacs/files/elisp/lang-nix.el | 22 ++++++++ ansible/roles/emacs/files/init.el | 2 + ansible/roles/emacs/meta/main.yaml | 2 + .../roles/firewall/files/homeserver_pf.conf | 4 ++ ansible/roles/nix/tasks/common.yaml | 55 +++++++++++++++++++ ansible/roles/nix/tasks/freebsd.yaml | 5 ++ ansible/roles/nix/tasks/linux.yaml | 21 +++++++ ansible/roles/nix/tasks/main.yaml | 2 + ansible/roles/nix/tasks/peruser.yaml | 29 ++++++++++ ansible/roles/nix/tasks/peruser_freebsd.yaml | 0 ansible/roles/nix/tasks/peruser_linux.yaml | 0 .../waybar_scripts/waybar_night_mode.bash | 2 +- 12 files changed, 143 insertions(+), 1 deletion(-) create mode 100644 ansible/roles/emacs/files/elisp/lang-nix.el create mode 100644 ansible/roles/nix/tasks/common.yaml create mode 100644 ansible/roles/nix/tasks/freebsd.yaml create mode 100644 ansible/roles/nix/tasks/linux.yaml create mode 100644 ansible/roles/nix/tasks/main.yaml create mode 100644 ansible/roles/nix/tasks/peruser.yaml create mode 100644 ansible/roles/nix/tasks/peruser_freebsd.yaml create mode 100644 ansible/roles/nix/tasks/peruser_linux.yaml diff --git a/ansible/roles/emacs/files/elisp/lang-nix.el b/ansible/roles/emacs/files/elisp/lang-nix.el new file mode 100644 index 0000000..9ba0abd --- /dev/null +++ b/ansible/roles/emacs/files/elisp/lang-nix.el @@ -0,0 +1,22 @@ +(require 'common-lsp) +(require 'util-tree-sitter) + +(use-package nix-mode + :mode (("\\.nix\\'" . nix-mode) + ) + :commands nix-mode + :hook ( + (nix-mode . (lambda () + ;; (eglot-ensure) + ;; (defclass my/eglot-nix (eglot-lsp-server) () + ;; :documentation + ;; "Own eglot server class.") + + ;; (add-to-list 'eglot-server-programs + ;; '(nix-mode . (my/eglot-nix "nixd"))) + ;; (add-hook 'before-save-hook 'eglot-format-buffer nil 'local) + )) + ) + ) + +(provide 'lang-nix) diff --git a/ansible/roles/emacs/files/init.el b/ansible/roles/emacs/files/init.el index 0d5391c..68b1a11 100644 --- a/ansible/roles/emacs/files/init.el +++ b/ansible/roles/emacs/files/init.el @@ -36,4 +36,6 @@ (require 'lang-xml) +(require 'lang-nix) + (load-directory autoload-directory) diff --git a/ansible/roles/emacs/meta/main.yaml b/ansible/roles/emacs/meta/main.yaml index 8e3df65..7501e43 100644 --- a/ansible/roles/emacs/meta/main.yaml +++ b/ansible/roles/emacs/meta/main.yaml @@ -7,3 +7,5 @@ dependencies: when: 'emacs_flavor == "full"' - role: terraform when: 'emacs_flavor == "full"' + - role: nix + when: 'emacs_flavor == "full"' diff --git a/ansible/roles/firewall/files/homeserver_pf.conf b/ansible/roles/firewall/files/homeserver_pf.conf index 1a9db62..aa8fede 100644 --- a/ansible/roles/firewall/files/homeserver_pf.conf +++ b/ansible/roles/firewall/files/homeserver_pf.conf @@ -42,6 +42,10 @@ nat pass on restricted_nat proto {tcp, udp} from 10.215.1.217/32 to 10.215.2.2 p rdr pass on $ext_if inet proto {tcp, udp} from $not_restricted_nat_v4 to any port 8082 -> 10.215.2.2 port 8082 nat pass on restricted_nat proto {tcp, udp} from any to 10.215.2.2 port 8082 -> 10.215.2.1 +# cloak -> dagger old +rdr pass on $ext_if inet proto {tcp, udp} from $not_restricted_nat_v4 to any port 8083 -> 10.215.2.2 port 8083 +nat pass on restricted_nat proto {tcp, udp} from any to 10.215.2.2 port 8083 -> 10.215.2.1 + # -> sftp # TODO: Limit bandwidth for sftp rdr pass on $ext_if inet proto {tcp, udp} from $not_jail_nat_v4 to any port 8022 -> 10.215.1.216 port 22 diff --git a/ansible/roles/nix/tasks/common.yaml b/ansible/roles/nix/tasks/common.yaml new file mode 100644 index 0000000..bef243a --- /dev/null +++ b/ansible/roles/nix/tasks/common.yaml @@ -0,0 +1,55 @@ +# - name: Create directories +# file: +# name: "{{ item }}" +# state: directory +# mode: 0755 +# owner: root +# group: wheel +# loop: +# - /foo/bar + +# - name: Install scripts +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ item.dest }}" +# mode: 0755 +# owner: root +# group: wheel +# loop: +# - src: foo.bash +# dest: /usr/local/bin/foo + +# - name: Install Configuration +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ item.dest }}" +# mode: 0600 +# owner: root +# group: wheel +# loop: +# - src: foo.conf +# dest: /usr/local/etc/foo.conf + +# - name: Clone Source +# git: +# repo: "https://foo.bar/baz.git" +# dest: /foo/bar +# version: "v1.0.2" +# force: true +# diff: false + +- import_tasks: tasks/freebsd.yaml + when: 'os_flavor == "freebsd"' + +- import_tasks: tasks/linux.yaml + when: 'os_flavor == "linux"' + +- include_tasks: + file: tasks/peruser.yaml + apply: + become: yes + become_user: "{{ initialize_user }}" + when: users is defined + loop: "{{ users | dict2items | community.general.json_query('[?value.initialize==`true`].key') }}" + loop_control: + loop_var: initialize_user diff --git a/ansible/roles/nix/tasks/freebsd.yaml b/ansible/roles/nix/tasks/freebsd.yaml new file mode 100644 index 0000000..b417174 --- /dev/null +++ b/ansible/roles/nix/tasks/freebsd.yaml @@ -0,0 +1,5 @@ +# - name: Install packages +# package: +# name: +# - foo +# state: present diff --git a/ansible/roles/nix/tasks/linux.yaml b/ansible/roles/nix/tasks/linux.yaml new file mode 100644 index 0000000..067771c --- /dev/null +++ b/ansible/roles/nix/tasks/linux.yaml @@ -0,0 +1,21 @@ +# - name: Build aur packages +# register: buildaur +# become_user: "{{ build_user.name }}" +# command: "aurutils-sync --no-view {{ item }}" +# args: +# creates: "/var/cache/pacman/custom/{{ item }}-*.pkg.tar.*" +# loop: +# - nixd + +# - name: Update cache +# when: buildaur.changed +# pacman: +# name: [] +# state: present +# update_cache: true + +# - name: Install packages +# package: +# name: +# - nixd +# state: present diff --git a/ansible/roles/nix/tasks/main.yaml b/ansible/roles/nix/tasks/main.yaml new file mode 100644 index 0000000..6805b9d --- /dev/null +++ b/ansible/roles/nix/tasks/main.yaml @@ -0,0 +1,2 @@ +- import_tasks: tasks/common.yaml + # when: foo is defined diff --git a/ansible/roles/nix/tasks/peruser.yaml b/ansible/roles/nix/tasks/peruser.yaml new file mode 100644 index 0000000..111e886 --- /dev/null +++ b/ansible/roles/nix/tasks/peruser.yaml @@ -0,0 +1,29 @@ +- include_role: + name: per_user + +# - name: Create directories +# file: +# name: "{{ account_homedir.stdout }}/{{ item }}" +# state: directory +# mode: 0700 +# owner: "{{ account_name.stdout }}" +# group: "{{ group_name.stdout }}" +# loop: +# - ".config/foo" + +# - name: Copy files +# copy: +# src: "files/{{ item.src }}" +# dest: "{{ account_homedir.stdout }}/{{ item.dest }}" +# mode: 0600 +# owner: "{{ account_name.stdout }}" +# group: "{{ group_name.stdout }}" +# loop: +# - src: foo.conf +# dest: .config/foo/foo.conf + +- import_tasks: tasks/peruser_freebsd.yaml + when: 'os_flavor == "freebsd"' + +- import_tasks: tasks/peruser_linux.yaml + when: 'os_flavor == "linux"' diff --git a/ansible/roles/nix/tasks/peruser_freebsd.yaml b/ansible/roles/nix/tasks/peruser_freebsd.yaml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/nix/tasks/peruser_linux.yaml b/ansible/roles/nix/tasks/peruser_linux.yaml new file mode 100644 index 0000000..e69de29 diff --git a/ansible/roles/waybar/files/waybar_scripts/waybar_night_mode.bash b/ansible/roles/waybar/files/waybar_scripts/waybar_night_mode.bash index 2110334..496fc2a 100644 --- a/ansible/roles/waybar/files/waybar_scripts/waybar_night_mode.bash +++ b/ansible/roles/waybar/files/waybar_scripts/waybar_night_mode.bash @@ -42,7 +42,7 @@ function main { local night_mode_icon night_mode_text night_mode_class night_mode_mode="auto" night_mode_class="" - wlsunset -l 40.7 -L -74.0 & + wlsunset -S 07:00 -s 22:00 & wlsunset_pid=$! while true; do