From a1f4bae2a69b07826248a92c093954c41d23fe0f Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Mon, 4 Nov 2024 04:37:29 +0300 Subject: [PATCH] Purge nixfmt! --- .editorconfig | 4 - .readme/keyboard/Readme.md | 3 - .readme/keyboard/alt/keyboard-layout.json | 151 ---- .../keyboard/app/firefox/keyboard-layout.json | 165 ---- .../app/jetbrains/keyboard-layout.json | 162 ---- .../app/nautilus/keyboard-layout.json | 167 ---- .../keyboard/app/tmux/keyboard-layout.json | 160 ---- .readme/keyboard/main/keyboard-layout.json | 142 --- .readme/keyboard/media/keyboard-layout.json | 139 --- .readme/keyboard/number/keyboard-layout.json | 144 --- .readme/keyboard/sway/keyboard-layout.json | 158 ---- .readme/keyboard/system/keyboard-layout.json | 174 ---- .treefmt.toml | 16 - Makefile | 3 - Readme.md | 68 +- config/Setting.nix | 68 -- config/Style.nix | 123 --- config/Stylix.nix | 42 - config/Wallpaper.nix | 21 - container/Change.nix | 99 +- container/Chat.nix | 143 ++- container/Cloud.nix | 156 ++-- container/Ddns.nix | 114 ++- container/Dns.nix | 265 +++--- container/Download.nix | 121 ++- container/Frkn.nix | 228 +++-- container/Git.nix | 216 +++-- container/Hdd.nix | 79 -- container/Home.nix | 104 ++- container/Iot.nix | 226 +++-- container/Jobber.nix | 144 +-- container/Mail.nix | 430 +++++---- container/Office.nix | 177 ++-- container/Paper.nix | 193 ++-- container/Pass.nix | 114 ++- container/Paste.nix | 250 +++--- container/Postgres.nix | 177 ++-- container/Print.nix | 132 ++- container/Proxy.nix | 154 ++-- container/Rabbitmq.nix | 101 +-- container/Read.nix | 110 ++- container/Redis.nix | 71 +- container/Search.nix | 275 +++--- container/Status.nix | 119 ++- container/Stock.nix | 117 ++- container/Vpn.nix | 182 ++-- container/Watch.nix | 171 ++-- container/Yt.nix | 117 ++- container/default.nix | 112 ++- container/proxy/host/Camera.nix | 49 +- container/proxy/host/Change.nix | 51 +- container/proxy/host/Chat.nix | 49 +- container/proxy/host/Cloud.nix | 55 +- container/proxy/host/Download.nix | 49 +- container/proxy/host/Git.nix | 53 +- container/proxy/host/Hdd.nix | 27 - container/proxy/host/Home.nix | 49 +- container/proxy/host/Iot.nix | 59 +- container/proxy/host/Mail.nix | 49 +- container/proxy/host/Office.nix | 51 +- container/proxy/host/Paper.nix | 49 +- container/proxy/host/Pass.nix | 49 +- container/proxy/host/Paste.nix | 45 +- container/proxy/host/Print.nix | 55 +- container/proxy/host/Printer.nix | 53 +- container/proxy/host/Read.nix | 49 +- container/proxy/host/Resume.nix | 40 +- container/proxy/host/Router.nix | 53 +- container/proxy/host/Search.nix | 49 +- container/proxy/host/Status.nix | 61 +- container/proxy/host/Stock.nix | 49 +- container/proxy/host/Watch.nix | 49 +- container/proxy/host/Yt.nix | 63 +- flake.nix | 500 +++-------- home/Android.nix | 82 +- home/HomeManager.nix | 70 -- home/NixOs.nix | 92 +- home/android/default.nix | 23 +- home/config/btop/default.nix | 346 ++----- home/config/chromium/default.nix | 183 ++-- home/config/dconf/Accessibility.nix | 9 +- home/config/dconf/Gtk.nix | 51 +- home/config/dconf/Input.nix | 64 +- home/config/dconf/Interface.nix | 18 +- home/config/dconf/Key.nix | 244 +++-- home/config/dconf/Media.nix | 13 +- home/config/dconf/Nautilus.nix | 37 +- home/config/dconf/Power.nix | 19 +- home/config/dconf/Privacy.nix | 28 +- home/config/dconf/Session.nix | 10 +- home/config/dconf/Shell.nix | 25 +- home/config/dconf/Software.nix | 15 +- home/config/dconf/Sound.nix | 13 +- home/config/dconf/Wm.nix | 56 +- home/config/default.nix | 112 ++- home/config/editorconfig/default.nix | 56 +- home/config/foot/default.nix | 57 +- home/config/fuzzel/default.nix | 74 +- home/config/git/default.nix | 26 +- home/config/gtk/3/default.nix | 10 - home/config/jetbrains/default.nix | 44 +- home/config/keyd/default.nix | 6 +- home/config/keyd/module/Chromium.nix | 56 +- home/config/keyd/module/DRG.nix | 64 +- home/config/keyd/module/Disable.nix | 52 +- home/config/keyd/module/Firefox.nix | 50 +- home/config/keyd/module/Jetbrains.nix | 54 +- home/config/keyd/module/Nautilus.nix | 52 +- home/config/mako/default.nix | 52 +- home/config/mangohud/default.nix | 84 +- home/config/nvim/default.nix | 179 ++-- home/config/nvim/module/config/Autoread.nix | 17 +- home/config/nvim/module/config/Etc.nix | 59 +- home/config/nvim/module/config/Highlight.nix | 95 +- home/config/nvim/module/config/Notify.nix | 31 +- home/config/nvim/module/config/Search.nix | 17 +- home/config/nvim/module/config/Tab.nix | 28 +- home/config/nvim/module/key/Autocomplete.nix | 15 +- home/config/nvim/module/key/Buffer.nix | 27 +- home/config/nvim/module/key/Cmd.nix | 19 +- home/config/nvim/module/key/Colorscheme.nix | 47 +- home/config/nvim/module/key/Comment.nix | 11 +- home/config/nvim/module/key/Filetree.nix | 11 +- home/config/nvim/module/key/Gitsigns.nix | 11 +- home/config/nvim/module/key/Leader.nix | 17 +- home/config/nvim/module/key/Navigation.nix | 64 +- home/config/nvim/module/key/Prompt.nix | 11 +- home/config/nvim/module/key/Rekey.nix | 87 +- home/config/nvim/module/key/Save.nix | 31 +- home/config/nvim/module/key/Sort.nix | 11 +- home/config/nvim/module/key/TabWidth.nix | 39 +- home/config/nvim/module/key/Telescope.nix | 24 +- home/config/nvim/module/key/Terminal.nix | 15 +- home/config/nvim/module/key/Trouble.nix | 20 +- home/config/nvim/module/plugin/Align.nix | 19 +- home/config/nvim/module/plugin/Autoclose.nix | 33 +- home/config/nvim/module/plugin/Bufferline.nix | 9 +- .../nvim/module/plugin/Closebuffers.nix | 21 +- home/config/nvim/module/plugin/Colorizer.nix | 13 +- home/config/nvim/module/plugin/Dressing.nix | 9 +- home/config/nvim/module/plugin/Filetree.nix | 67 +- home/config/nvim/module/plugin/Fold.nix | 13 +- home/config/nvim/module/plugin/Gen.nix | 14 +- home/config/nvim/module/plugin/Gitsigns.nix | 85 +- home/config/nvim/module/plugin/Gruvbox.nix | 33 +- home/config/nvim/module/plugin/Indent.nix | 19 +- home/config/nvim/module/plugin/Init.nix | 97 +- home/config/nvim/module/plugin/Telescope.nix | 31 +- home/config/nvim/module/plugin/Todo.nix | 109 ++- home/config/nvim/module/plugin/Treesitter.nix | 49 +- home/config/nvim/module/plugin/Trouble.nix | 9 +- home/config/nvim/module/plugin/lsp/Go.nix | 11 +- .../config/nvim/module/plugin/lsp/Haskell.nix | 15 +- home/config/nvim/module/plugin/lsp/Kotlin.nix | 11 +- home/config/nvim/module/plugin/lsp/Lua.nix | 11 +- home/config/nvim/module/plugin/lsp/Nix.nix | 31 +- home/config/nvim/module/plugin/lsp/Python.nix | 11 +- home/config/nvim/module/plugin/lsp/Rust.nix | 35 +- home/config/nvim/module/plugin/lsp/Tex.nix | 109 ++- home/config/ssh/default.nix | 55 +- home/config/swappy/default.nix | 29 +- home/config/sway/default.nix | 69 +- home/config/sway/module/Display.nix | 11 +- home/config/sway/module/Font.nix | 16 +- home/config/sway/module/Input.nix | 82 +- home/config/sway/module/Keyd.nix | 9 +- home/config/sway/module/Launcher.nix | 17 +- home/config/sway/module/Mod.nix | 11 +- home/config/sway/module/Mouse.nix | 13 +- home/config/sway/module/Navigation.nix | 31 +- home/config/sway/module/Notification.nix | 15 +- home/config/sway/module/Resize.nix | 22 +- home/config/sway/module/ScratchPad.nix | 87 +- home/config/sway/module/Screenshot.nix | 265 +++--- home/config/sway/module/Session.nix | 17 +- home/config/sway/module/Sound.nix | 38 +- home/config/sway/module/Style.nix | 33 +- home/config/sway/module/System.nix | 44 +- home/config/sway/module/Terminal.nix | 11 +- home/config/sway/module/Tiling.nix | 54 +- home/config/sway/module/TitleBar.nix | 23 +- home/config/sway/module/Waybar.nix | 15 +- home/config/sway/module/Workspace.nix | 67 +- home/config/template/Android.nix | 123 +-- home/config/template/DevShell.nix | 39 +- home/config/template/FHSEnv.nix | 37 +- home/config/template/Latex.nix | 106 ++- home/config/template/Rust.nix | 70 +- home/config/tmux/default.nix | 7 +- home/config/tmux/module/Config.nix | 15 +- home/config/tmux/module/Copy.nix | 27 +- home/config/tmux/module/Env.nix | 19 +- home/config/tmux/module/Scroll.nix | 11 +- home/config/tmux/module/Session.nix | 19 +- home/config/tmux/module/Split.nix | 70 +- home/config/tmux/module/Status.nix | 44 +- home/config/tmux/module/Window.nix | 23 +- home/config/waybar/config/default.nix | 356 ++++---- home/config/waybar/default.nix | 9 +- home/config/waybar/style/Common.nix | 18 +- home/config/waybar/style/Plugin.nix | 139 +-- home/config/waybar/style/Window.nix | 28 +- home/config/yazi/default.nix | 19 +- home/config/yazi/module/Init.nix | 20 +- home/config/yazi/module/Keymap.nix | 82 +- home/config/yazi/module/Theme.nix | 206 ++--- home/config/yazi/module/Yazi.nix | 315 +++---- home/program/bash/default.nix | 66 +- home/program/bash/module/Archive.nix | 843 +++++++++--------- home/program/bash/module/Ask.nix | 47 +- home/program/bash/module/Autocomplete.nix | 141 ++- home/program/bash/module/Battery.nix | 29 +- home/program/bash/module/Brightness.nix | 37 +- home/program/bash/module/Cd.nix | 125 ++- home/program/bash/module/Color.nix | 51 +- home/program/bash/module/Copypaste.nix | 23 +- home/program/bash/module/Cp.nix | 93 +- home/program/bash/module/Curl.nix | 17 +- home/program/bash/module/Date.nix | 23 +- home/program/bash/module/Disk.nix | 115 ++- home/program/bash/module/Docker.nix | 165 ++-- home/program/bash/module/Dvd.nix | 73 +- home/program/bash/module/Ffmpeg.nix | 183 ++-- home/program/bash/module/File.nix | 17 +- home/program/bash/module/Find.nix | 17 +- home/program/bash/module/Fix.nix | 41 +- home/program/bash/module/Git.nix | 523 ++++++----- home/program/bash/module/Gpg.nix | 149 ++-- home/program/bash/module/Group.nix | 113 ++- home/program/bash/module/Help.nix | 47 +- home/program/bash/module/Ls.nix | 119 ++- home/program/bash/module/Name.nix | 797 +++++++++-------- home/program/bash/module/Nix.nix | 131 ++- home/program/bash/module/Notify.nix | 27 +- home/program/bash/module/Own.nix | 65 +- home/program/bash/module/Pack.nix | 349 ++++---- home/program/bash/module/Parse.nix | 283 +++--- home/program/bash/module/Permission.nix | 23 +- home/program/bash/module/Ps.nix | 27 +- home/program/bash/module/Ps1.nix | 277 +++--- home/program/bash/module/Random.nix | 25 +- home/program/bash/module/Recursive.nix | 131 ++- home/program/bash/module/Reload.nix | 15 +- home/program/bash/module/Shopt.nix | 47 +- home/program/bash/module/Su.nix | 59 +- home/program/bash/module/Tmux.nix | 153 ++-- home/program/bash/module/Transcode.nix | 173 ++-- home/program/bash/module/Try.nix | 43 +- home/program/bash/module/Util.nix | 261 +++--- home/program/bash/module/Vdl.nix | 71 +- home/program/bash/module/Vi.nix | 15 +- home/program/bash/module/Watch.nix | 47 +- home/program/bash/module/Zapret.nix | 19 +- home/program/chromium/default.nix | 143 ++- home/program/default.nix | 56 +- home/program/firefox/default.nix | 781 ++++++++-------- home/user/x86_64-linux/root/default.nix | 9 - home/user/x86_64-linux/voronind/default.nix | 9 - home/variable/default.nix | 39 +- home/xdg/default.nix | 35 +- host/x86_64-linux/dasha/Filesystem.nix | 39 +- host/x86_64-linux/dasha/default.nix | 71 +- host/x86_64-linux/desktop/Filesystem.nix | 59 +- host/x86_64-linux/desktop/default.nix | 110 ++- host/x86_64-linux/home/Backup.nix | 188 ++-- host/x86_64-linux/home/Container.nix | 163 ++-- host/x86_64-linux/home/Filesystem.nix | 65 +- host/x86_64-linux/home/Network.nix | 231 +++-- host/x86_64-linux/home/Photoprocess.nix | 156 ++-- host/x86_64-linux/home/default.nix | 124 ++- host/x86_64-linux/laptop/Filesystem.nix | 19 +- host/x86_64-linux/laptop/default.nix | 65 +- host/x86_64-linux/live/default.nix | 31 +- host/x86_64-linux/work/Fprint.nix | 22 +- host/x86_64-linux/work/default.nix | 72 +- lib/Container.nix | 136 ++- lib/Util.nix | 50 +- module/AmdCompute.nix | 33 +- module/AmdCpu.nix | 61 +- module/AmdGpu.nix | 57 +- module/AutoUpdateSigned.nix | 130 +-- module/Bluetooth.nix | 29 +- module/Brightness.nix | 19 +- module/DisplayManager.nix | 31 +- module/Distrobox.nix | 38 +- module/Docker.nix | 75 +- module/Dpi.nix | 14 + module/Ftpd.nix | 67 +- module/Gnome.nix | 108 ++- module/Hwmon.nix | 18 + module/IntelCpu.nix | 59 +- module/Kernel.nix | 153 ++-- module/Keyboard.nix | 18 + module/Keyd.nix | 186 ++-- module/Ld.nix | 68 -- module/Ollama.nix | 115 +-- module/Package.nix | 181 ++-- module/Podman.nix | 41 +- module/Polkit.nix | 59 +- module/Portal.nix | 51 +- module/PowerlimitThinkpad.nix | 152 ++-- module/Powersave.nix | 141 ++- module/Print.nix | 40 +- module/Realtime.nix | 33 +- module/RemoteBuild.nix | 201 +++-- module/Sound.nix | 39 +- module/Style.nix | 115 +++ module/Sway.nix | 83 +- module/Tablet.nix | 25 +- module/VirtManager.nix | 41 +- module/Wallpaper.nix | 20 + module/Waybar.nix | 29 +- module/Wayland.nix | 63 +- module/Zapret.nix | 285 +++--- overlay/Example.nix | 43 +- overlay/Keyd.nix | 81 +- overlay/Nix.nix | 14 +- package/applefont/default.nix | 110 ++- package/darkreader/default.nix | 57 +- package/default.nix | 281 +++--- package/homer/Config.nix | 202 ++--- package/homer/default.nix | 54 +- package/jobber/default.nix | 11 +- package/print/default.nix | 86 +- package/privatebin/Config.nix | 325 +------ package/privatebin/default.nix | 67 +- package/swayscript/default.nix | 8 +- package/swayscript/script/DisplayWidget.nix | 195 ++-- package/swayscript/script/Reload.nix | 45 +- package/swayscript/script/Scratchpad.nix | 25 +- package/swayscript/script/Sound.nix | 27 +- package/swayscript/script/Util.nix | 27 +- package/swayscript/script/Vpn.nix | 31 +- package/yamusicdownload/default.nix | 44 +- package/ytdlp/default.nix | 64 +- secret/default.nix | 142 ++- system/Bootloader.nix | 70 +- system/Crypto.nix | 48 +- system/Dbus.nix | 5 +- system/Filesystem.nix | 35 +- system/Firewall.nix | 5 +- system/Font.nix | 24 +- system/Fstrim.nix | 5 +- system/Locale.nix | 34 +- system/Network.nix | 12 +- system/Nix.nix | 48 +- system/Shell.nix | 8 +- system/Sshd.nix | 71 +- system/Stylix.nix | 33 + system/Systemd.nix | 37 +- system/Users.nix | 11 +- system/Vm.nix | 52 +- system/Zram.nix | 5 +- user/Dasha.nix | 61 +- user/Root.nix | 54 +- user/Voronind.nix | 67 +- 356 files changed, 13267 insertions(+), 16348 deletions(-) delete mode 100644 .readme/keyboard/Readme.md delete mode 100644 .readme/keyboard/alt/keyboard-layout.json delete mode 100644 .readme/keyboard/app/firefox/keyboard-layout.json delete mode 100644 .readme/keyboard/app/jetbrains/keyboard-layout.json delete mode 100644 .readme/keyboard/app/nautilus/keyboard-layout.json delete mode 100644 .readme/keyboard/app/tmux/keyboard-layout.json delete mode 100644 .readme/keyboard/main/keyboard-layout.json delete mode 100644 .readme/keyboard/media/keyboard-layout.json delete mode 100644 .readme/keyboard/number/keyboard-layout.json delete mode 100644 .readme/keyboard/sway/keyboard-layout.json delete mode 100644 .readme/keyboard/system/keyboard-layout.json delete mode 100644 .treefmt.toml delete mode 100644 config/Setting.nix delete mode 100644 config/Style.nix delete mode 100644 config/Stylix.nix delete mode 100644 config/Wallpaper.nix delete mode 100644 container/Hdd.nix delete mode 100644 container/proxy/host/Hdd.nix delete mode 100644 home/HomeManager.nix delete mode 100644 home/config/gtk/3/default.nix delete mode 100644 home/user/x86_64-linux/root/default.nix delete mode 100644 home/user/x86_64-linux/voronind/default.nix create mode 100644 module/Dpi.nix create mode 100644 module/Hwmon.nix create mode 100644 module/Keyboard.nix delete mode 100644 module/Ld.nix create mode 100644 module/Style.nix create mode 100644 module/Wallpaper.nix create mode 100644 system/Stylix.nix diff --git a/.editorconfig b/.editorconfig index 2b92926..75c6baf 100644 --- a/.editorconfig +++ b/.editorconfig @@ -5,9 +5,5 @@ indent_style = tab insert_final_newline = true trim_trailing_whitespace = true -[*.nix] -indent_style = space -indent_size = 2 - [*.md] trim_trailing_whitespace = false diff --git a/.readme/keyboard/Readme.md b/.readme/keyboard/Readme.md deleted file mode 100644 index 08edc29..0000000 --- a/.readme/keyboard/Readme.md +++ /dev/null @@ -1,3 +0,0 @@ -# Keyd layouts. - -http://www.keyboard-layout-editor.com diff --git a/.readme/keyboard/alt/keyboard-layout.json b/.readme/keyboard/alt/keyboard-layout.json deleted file mode 100644 index 2f72aee..0000000 --- a/.readme/keyboard/alt/keyboard-layout.json +++ /dev/null @@ -1,151 +0,0 @@ -[ - [ - { - "c": "#8ec07c" - }, - "Esc", - { - "c": "#cccccc" - }, - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - "_\n-", - "+\n=", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - "Q", - { - "c": "#8ec07c" - }, - "Page Up", - { - "c": "#cccccc" - }, - "E", - "R", - "T", - "Y", - "U", - "I", - "O", - "P", - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "c": "#8ec07c", - "w": 1.75 - }, - "Caps Lock", - "Home", - "Page Down", - "End", - { - "c": "#cccccc" - }, - "F", - "G", - { - "c": "#8ec07c" - }, - "Left", - "Down", - "Up", - "Right", - { - "c": "#cccccc" - }, - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - "Z", - { - "c": "#8ec07c" - }, - "Cut", - "Copy", - "Paste", - { - "c": "#cccccc" - }, - "B", - "N", - "M", - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "c": "#d79921", - "w": 1.25 - }, - "Alterna-tive keys", - { - "c": "#cccccc", - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Alt", - { - "a": 7, - "w": 6.25 - }, - "", - { - "a": 4, - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "c": "#8ec07c", - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/app/firefox/keyboard-layout.json b/.readme/keyboard/app/firefox/keyboard-layout.json deleted file mode 100644 index 7598d81..0000000 --- a/.readme/keyboard/app/firefox/keyboard-layout.json +++ /dev/null @@ -1,165 +0,0 @@ -[ - [ - "~\n`", - "!\n1\n\n\n\n\nTab 1", - "@\n2\n\n\n\n\nTab 2", - "#\n3\n\n\n\n\nTab 3", - "$\n4\n\n\n\n\nTab 4", - "%\n5\n\n\n\n\nTab 5", - "^\n6\n\n\n\n\nTab 6", - "&\n7\n\n\n\n\nTab 7", - "*\n8\n\n\n\n\nTab 8", - "(\n9\n\n\n\n\nTab 9", - ")\n0\n\n\n\n\nTab 10", - "_\n-", - "+\n=", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - { - "c": "#8ec07c" - }, - "Prev Tab / Move", - "Up", - "Next Tab / Move", - "Full Refresh", - { - "c": "#cccccc" - }, - "T", - "Y", - { - "c": "#8ec07c" - }, - "Restore Tab", - { - "c": "#cccccc" - }, - "I", - "O", - { - "c": "#8ec07c" - }, - "Fill Pass-word", - { - "c": "#cccccc" - }, - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "c": "#8ec07c", - "w": 1.75 - }, - "New Tab", - "Go Back", - "Down", - "Go Fwd", - "Find", - { - "c": "#cccccc" - }, - "G", - "H", - "J", - "K", - { - "c": "#8ec07c" - }, - "Toggle Dark Mode", - { - "c": "#cccccc" - }, - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "c": "#8ec07c", - "w": 2.25 - }, - "Alternative Action (after slash)", - { - "c": "#cccccc" - }, - "Z", - { - "c": "#8ec07c" - }, - "Close Tab", - { - "c": "#cccccc" - }, - "C", - "V", - "B", - { - "c": "#8ec07c" - }, - "Find Next / Prev", - { - "c": "#cccccc" - }, - "M", - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "c": "#d79921", - "w": 1.25 - }, - "App Controls", - { - "c": "#8ec07c", - "w": 6.25 - }, - "Toggle Address Bar", - { - "c": "#cccccc", - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/app/jetbrains/keyboard-layout.json b/.readme/keyboard/app/jetbrains/keyboard-layout.json deleted file mode 100644 index 40ddcff..0000000 --- a/.readme/keyboard/app/jetbrains/keyboard-layout.json +++ /dev/null @@ -1,162 +0,0 @@ -[ - [ - "~\n`", - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - "_\n-", - { - "c": "#8ec07c" - }, - "Reformat", - { - "c": "#cccccc", - "w": 2 - }, - "Backspace" - ], - [ - { - "c": "#8ec07c", - "w": 1.5 - }, - "Step Over (Tap) / Step Into (Hold)", - "Prev Tab", - { - "c": "#cccccc" - }, - "W", - { - "c": "#8ec07c" - }, - "Next Tab", - "Run", - { - "c": "#cccccc" - }, - "T", - "Y", - "U", - { - "c": "#8ec07c" - }, - "Impl-ement", - "Over-ride", - { - "c": "#cccccc" - }, - "P", - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "c": "#8ec07c", - "w": 1.75 - }, - "New Scratch", - "Attach Debug-ger", - "Refac-tor", - "Run Debug", - "Find", - "Go to Defini-tion", - { - "c": "#cccccc" - }, - "H", - "J", - "K", - "L", - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - { - "c": "#8ec07c" - }, - "Stop App", - "Close Tab", - "Close Bottom Panel", - "Show Doc", - { - "c": "#cccccc" - }, - "B", - { - "c": "#8ec07c" - }, - "Inline", - "Settings", - { - "c": "#cccccc" - }, - "<\n,", - { - "c": "#8ec07c" - }, - "Toggle Break-point\n.", - "Toggle Com-ment", - { - "c": "#cccccc", - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "c": "#d79921", - "w": 1.25 - }, - "App Controls", - { - "c": "#cccccc", - "a": 7, - "w": 6.25 - }, - "", - { - "a": 4, - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/app/nautilus/keyboard-layout.json b/.readme/keyboard/app/nautilus/keyboard-layout.json deleted file mode 100644 index bbbbba0..0000000 --- a/.readme/keyboard/app/nautilus/keyboard-layout.json +++ /dev/null @@ -1,167 +0,0 @@ -[ - [ - "~\n`", - { - "c": "#8ec07c" - }, - "List View", - "Grid View", - { - "c": "#cccccc" - }, - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - "_\n-", - "+\n=", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - { - "c": "#8ec07c" - }, - "Prev Tab / Move", - { - "c": "#cccccc" - }, - "W", - { - "c": "#8ec07c" - }, - "Next Tab / Move", - "Refresh Dir", - "New window", - "Copy Selection", - { - "c": "#cccccc" - }, - "U", - { - "c": "#8ec07c" - }, - "Invert Selec-tion", - { - "c": "#cccccc" - }, - "O", - "P", - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "\\" - ], - [ - { - "c": "#8ec07c", - "w": 1.75 - }, - "New Tab", - "Create Dir", - "Rename", - "Delete", - "Search Dir", - { - "c": "#cccccc" - }, - "G", - { - "c": "#8ec07c" - }, - "Toggle Hidden Files", - { - "c": "#cccccc" - }, - "J", - "K", - "L", - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - "Z", - { - "c": "#8ec07c" - }, - "Close Tab", - { - "c": "#cccccc" - }, - "C", - { - "c": "#8ec07c" - }, - "File Info", - "Go Back", - { - "c": "#cccccc" - }, - "N", - "M", - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "c": "#d79921", - "w": 1.25 - }, - "App Controls", - { - "c": "#8ec07c", - "w": 6.25 - }, - "Focus Navigation Bar", - { - "c": "#cccccc", - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/app/tmux/keyboard-layout.json b/.readme/keyboard/app/tmux/keyboard-layout.json deleted file mode 100644 index 0f52bc5..0000000 --- a/.readme/keyboard/app/tmux/keyboard-layout.json +++ /dev/null @@ -1,160 +0,0 @@ -[ - [ - "~\n`", - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - { - "c": "#8ec07c" - }, - "Split / Align Vertical", - "Equalize Splits", - { - "c": "#cccccc", - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - { - "c": "#8ec07c" - }, - "Prev Window", - "Up", - "Next Window", - "Reload Settings", - { - "c": "#cccccc" - }, - "T", - { - "c": "#8ec07c" - }, - "Copy Selection", - { - "c": "#cccccc" - }, - "U", - "I", - "O", - { - "c": "#8ec07c" - }, - "Paste", - { - "c": "#cccccc" - }, - "{\n[", - "}\n]", - { - "c": "#8ec07c", - "w": 1.5 - }, - "Split / Align Horizontal" - ], - [ - { - "w": 1.75 - }, - "New Window", - "Left", - "Down", - "Right", - "Toggle Status Bar", - "Select Session", - "Resize Left", - "Resize/ Scroll Down", - "Resize/ Scroll Up", - "Resize Right", - { - "c": "#cccccc" - }, - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - { - "c": "#8ec07c" - }, - "Detach Session/Others", - "Close Window", - "Close Pane", - "Select", - { - "c": "#cccccc" - }, - "B", - "N", - "M", - { - "c": "#8ec07c" - }, - "Prev Session", - "Next Session", - { - "c": "#cccccc" - }, - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "c": "#d79921", - "w": 1.25 - }, - "App Controls", - { - "c": "#cccccc", - "a": 7, - "w": 6.25 - }, - "", - { - "a": 4, - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/main/keyboard-layout.json b/.readme/keyboard/main/keyboard-layout.json deleted file mode 100644 index 84da45d..0000000 --- a/.readme/keyboard/main/keyboard-layout.json +++ /dev/null @@ -1,142 +0,0 @@ -[ - [ - { - "c": "#d79921", - "sm": "alps" - }, - "System Controls", - { - "c": "#cccccc" - }, - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - "_\n-", - "+\n=", - { - "c": "#8ec07c", - "w": 2 - }, - "Delete" - ], - [ - { - "c": "#cccccc", - "w": 1.5 - }, - "Tab", - "Q", - "W", - "E", - "R", - "T", - "Y", - "U", - "I", - "O", - "P", - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "c": "#8ec07c", - "w": 1.75 - }, - "Ctrl / Esc", - { - "c": "#cccccc" - }, - "A", - "S", - "D", - { - "n": true - }, - "F", - "G", - "H", - { - "n": true - }, - "J", - "K", - "L", - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - "Z", - "X", - "C", - "V", - "B", - "N", - "M", - "<\n,", - ">\n.", - "?\n/", - { - "c": "#8ec07c", - "w": 2.75 - }, - "Backspace" - ], - [ - { - "c": "#d79921", - "w": 1.25 - }, - "Alterna-tive Keys", - { - "w": 1.25 - }, - "WM Controls", - { - "w": 1.25 - }, - "App Controls", - { - "w": 6.25 - }, - "Neovim", - { - "c": "#8ec07c", - "w": 1.25 - }, - "Language Switch", - { - "c": "#d79921", - "w": 1.25 - }, - "Extra Numbers", - { - "w": 1.25 - }, - "Media Controls", - { - "c": "#cccccc", - "d": true - }, - "Fn" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/media/keyboard-layout.json b/.readme/keyboard/media/keyboard-layout.json deleted file mode 100644 index a897fe1..0000000 --- a/.readme/keyboard/media/keyboard-layout.json +++ /dev/null @@ -1,139 +0,0 @@ -[ - [ - "~\n`", - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - "_\n-", - "+\n=", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - { - "c": "#8ec07c" - }, - "Prev Song", - "Volume Up", - "Next Song", - { - "c": "#cccccc" - }, - "R", - "T", - "Y", - "U", - "I", - "O", - "P", - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "w": 1.75 - }, - "Caps Lock", - { - "c": "#8ec07c" - }, - "Seek Back", - "Volume Down", - "Seek Fwd", - { - "c": "#cccccc" - }, - "F", - "G", - "H", - "J", - "K", - "L", - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - { - "c": "#8ec07c" - }, - "Mute Sound", - "Stop", - "Cycle Sound Device", - "Mute Mic", - { - "c": "#cccccc" - }, - "B", - "N", - "M", - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Alt", - { - "c": "#8ec07c", - "w": 6.25 - }, - "Play / Pause", - { - "c": "#cccccc", - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "c": "#d79921", - "w": 1.25 - }, - "Media Controls (RCtrl)" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/number/keyboard-layout.json b/.readme/keyboard/number/keyboard-layout.json deleted file mode 100644 index 405ec07..0000000 --- a/.readme/keyboard/number/keyboard-layout.json +++ /dev/null @@ -1,144 +0,0 @@ -[ - [ - "~\n`", - { - "c": "#8ec07c" - }, - "=", - "/", - "*", - "-", - { - "c": "#cccccc" - }, - "f17", - "f18", - "f19", - "f20", - "f21", - "f22", - "f23", - "f24", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - { - "c": "#8ec07c" - }, - "7", - "8", - "9", - "+", - { - "c": "#cccccc" - }, - "T", - "Y", - "U", - "I", - "O", - "P", - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "w": 1.75 - }, - "Caps Lock", - { - "c": "#8ec07c" - }, - "4", - "5", - "6", - "Enter", - { - "c": "#cccccc" - }, - "G", - "H", - "J", - "K", - "L", - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "c": "#8ec07c", - "w": 2.25 - }, - "Backspace", - "1", - "2", - "3", - ". (dot)", - { - "c": "#cccccc" - }, - "B", - "N", - "M", - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Alt", - { - "c": "#8ec07c", - "w": 6.25 - }, - "0", - { - "c": "#cccccc", - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "c": "#d79921", - "w": 1.25 - }, - "Extra Numbers", - { - "c": "#cccccc", - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/sway/keyboard-layout.json b/.readme/keyboard/sway/keyboard-layout.json deleted file mode 100644 index 5fd3e0f..0000000 --- a/.readme/keyboard/sway/keyboard-layout.json +++ /dev/null @@ -1,158 +0,0 @@ -[ - [ - "~\n`", - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - { - "c": "#8ec07c" - }, - "Split Vertic-ally", - { - "c": "#cccccc" - }, - "+\n=", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "c": "#8ec07c", - "w": 1.5 - }, - "Tab mode toggle", - "Prev Work-space", - "Up", - "Next Work-space", - "Float layer / Waybar", - { - "c": "#cccccc" - }, - "T", - { - "c": "#8ec07c" - }, - "Full Scr / Rec", - { - "c": "#cccccc" - }, - "U", - "I", - "O", - "P", - "{\n[", - "}\n]", - { - "c": "#8ec07c", - "w": 1.5 - }, - "Split Hori-zontally" - ], - [ - { - "w": 1.75 - }, - "Terminal", - "Left", - "Down", - "Right", - "Full-screen / Float", - { - "c": "#cccccc" - }, - "G", - { - "c": "#8ec07c" - }, - "Resize Left", - "Resize Down", - "Resize Up", - "Resize Right", - { - "c": "#cccccc" - }, - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "c": "#8ec07c", - "w": 2.25 - }, - "Alternative action (after slash) or move window", - "Lock / +Sus-pend", - "Close Window", - "Scratch toggle / move", - "Select Scr / Rec", - { - "c": "#cccccc" - }, - "B", - { - "c": "#8ec07c" - }, - "Dismiss Notif / Repeat", - { - "c": "#cccccc" - }, - "M", - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "c": "#d79921", - "w": 1.25 - }, - "WM Controls", - { - "c": "#cccccc", - "w": 1.25 - }, - "Alt", - { - "c": "#8ec07c", - "w": 6.25 - }, - "Run", - { - "c": "#cccccc", - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.readme/keyboard/system/keyboard-layout.json b/.readme/keyboard/system/keyboard-layout.json deleted file mode 100644 index ddf37b1..0000000 --- a/.readme/keyboard/system/keyboard-layout.json +++ /dev/null @@ -1,174 +0,0 @@ -[ - [ - { - "c": "#d79921" - }, - "System controls", - { - "c": "#cccccc" - }, - "!\n1", - "@\n2", - "#\n3", - "$\n4", - "%\n5", - "^\n6", - "&\n7", - "*\n8", - "(\n9", - ")\n0", - "_\n-", - "+\n=", - { - "w": 2 - }, - "Backspace" - ], - [ - { - "w": 1.5 - }, - "Tab", - "Q", - { - "c": "#8ec07c" - }, - "Bright- ness Up", - { - "c": "#cccccc" - }, - "E", - { - "c": "#8ec07c" - }, - "Live Config Reload", - { - "c": "#cccccc" - }, - "T", - "Y", - "U", - "I", - "O", - { - "c": "#8ec07c" - }, - "Toggle power-save", - { - "c": "#cccccc" - }, - "{\n[", - "}\n]", - { - "w": 1.5 - }, - "|\n\\" - ], - [ - { - "w": 1.75 - }, - "Caps Lock", - "A", - { - "c": "#8ec07c" - }, - "Bright-ness Down", - { - "c": "#cccccc" - }, - "D", - "F", - { - "c": "#8ec07c" - }, - "Toggle Gaming Mode", - { - "c": "#cccccc" - }, - "H", - "J", - "K", - { - "c": "#8ec07c" - }, - "Toggle charge limit", - { - "c": "#cccccc" - }, - ":\n;", - "\"\n'", - { - "w": 2.25 - }, - "Enter" - ], - [ - { - "w": 2.25 - }, - "Shift", - { - "c": "#8ec07c" - }, - "Sus-pend", - "Power-off", - "Reboot", - "Toggle VPN", - { - "c": "#cccccc" - }, - "B", - { - "c": "#8ec07c" - }, - "Toggle DND", - "Toggle Monitor Power", - { - "c": "#cccccc" - }, - "<\n,", - ">\n.", - "?\n/", - { - "w": 2.75 - }, - "Shift" - ], - [ - { - "w": 1.25 - }, - "Ctrl", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Alt", - { - "a": 7, - "w": 6.25 - }, - "", - { - "a": 4, - "w": 1.25 - }, - "Alt", - { - "w": 1.25 - }, - "Win", - { - "w": 1.25 - }, - "Menu", - { - "w": 1.25 - }, - "Ctrl" - ] -] \ No newline at end of file diff --git a/.treefmt.toml b/.treefmt.toml deleted file mode 100644 index 2137d4e..0000000 --- a/.treefmt.toml +++ /dev/null @@ -1,16 +0,0 @@ -# One CLI to format the code tree - https://git.numtide.com/numtide/treefmt - -# [formatter.mylanguage] -# Formatter to run -# command = "command-to-run" -# Command-line arguments for the command -# options = [] -# Glob pattern of files to include -# includes = [ "*." ] -# Glob patterns of files to exclude -# excludes = [] - -[formatter.nixfmt-rfc-style] -command = "nixfmt" -options = [ "-s" ] -includes = [ "*.nix" ] diff --git a/Makefile b/Makefile index 41ff8ab..7949d25 100644 --- a/Makefile +++ b/Makefile @@ -30,9 +30,6 @@ fix-ulimit: fix-unlock: pkill nixos-rebuild || true -format: - treefmt --no-cache --on-unmatched=info - gc: nix-collect-garbage -d # nix-store --gc diff --git a/Readme.md b/Readme.md index f0429f6..662af51 100644 --- a/Readme.md +++ b/Readme.md @@ -1,4 +1,4 @@ -# Dmitry 🌊 NixOS, Home Manager and Nix-on-Droid configurations. +# Dmitry 🌊 NixOS and Nix-on-Droid configurations. ## Please, support tabs in Nix! @@ -36,68 +36,4 @@ Newest first. Wallpaper link -[My current wallpaper](config/Wallpaper.nix#L4) - -Color theming based on wallpaper thanks to [Stylix](https://github.com/danth/stylix). - -## Discovering my configuration. - -Even tho I've tried to document everything I can in a dum-dum way, I still highly recommend you to learn the [very basics of Nix language](https://nixos.org/guides/nix-pills/). Start from the [Flake](flake.nix) file and follow the comments. If you have any questions, get in touch using [Telegram](https://t.me/voronind_com) or [Email](mailto:hi@voronind.com). - -Please tell me if you find any undocumented parts. - -## Configuration highlights. - -* [Keyd](module/Keyd.nix) allows you to have QMK-like keyboard remaps. Killer-feature is the ability to have remaps per-application. I have pretty common remaps like CapsLock to Ctrl/Esc combo, Right Shift to Backspace, Backspace to Delete and overlays for System/Windows/Media/Application controls as well as Macros. -* NixOS Containers (nspawn). Containers are great. I LOVE containers! Containers! Containers! Containers! Containers! Containers! Containers! Containers! Containers! Containers! Containers! Containers! [Here](host/x86_64-linux/home/Container.nix) is how I add containers to the host, [here](container/default.nix) is the global configuration and [here](container) are all the containers. -* NixOnDroid can be used to set up your environment inside the Termux app on Android. It also gives you access to all the Nixpkgs binaries for Arm. Configuration can be found [here](home/Android.nix), but you also need to add the definition to the root `flake.nix (nixOnDroidConfigurations.default)`. [Here](https://github.com/nix-community/nix-on-droid) are the docs. -* [Stylix](config/Stylix.nix) can be used to change colors for the whole system based on current wallpaper. Example usages: [Sway](home/config/sway/module/Style.nix), [fuzzel](home/config/fuzzel/default.nix) and [Tmux](home/config/tmux/module/Status.nix). -* [Signed auto-updates](module/AutoUpdateSigned.nix). Updates are pulled every hour and require the last commit to be signed with my signature. - -## Keyboard layouts. - -Yellow are modifier keys, they enable layers when held. Green ones are just modified keys. - -
-Default - -
- -
-Alternative Keys - -
- -
-Sway keys -
-
- -
-Per-application controls -Firefox:
-
-Jetbrains:
-
-Nautilus:
-
-Tmux:
- -
- -
-Extra numbers - -
- -
-Media Controls - -
- -
-System controls - -
- -[Link](http://www.keyboard-layout-editor.com) / [Source](https://github.com/ijprest/keyboard-layout-editor) of the tool I used to draw the images. +[My current wallpaper](module/Wallpaper.nix#L6) diff --git a/config/Setting.nix b/config/Setting.nix deleted file mode 100644 index 2ad400f..0000000 --- a/config/Setting.nix +++ /dev/null @@ -1,68 +0,0 @@ -# Global settings. -# Just like I can configure each package, here I configure my config! :O) -{ lib, ... }: -{ - options.setting = with lib; { - # Ollama settings. - # I use the best light model by default. - ollama = mkOption { - default = { }; - type = types.submodule { - # freeformType = lib.jsonFormat.type; - options = { - primaryModel = mkOption { - default = "llama3"; - type = types.str; - }; - }; - }; - }; - - # Whether to use Dpi-aware setting in supported apps. - dpiAware = mkOption { - default = false; - type = types.bool; - }; - - # Keyboard options. - keyboard = mkOption { - default = { }; - type = types.submodule { - options = { - layouts = mkOption { - default = "us,ru"; - type = types.str; - }; - options = mkOption { - default = "grp:toggle"; - type = types.str; - }; - }; - }; - }; - - # CPU configurations. - cpu = mkOption { - default = { }; - type = types.submodule { - options = { - hwmon = mkOption { - default = { }; - type = types.submodule { - options = { - path = mkOption { - default = ""; - type = types.str; - }; - file = mkOption { - default = ""; - type = types.str; - }; - }; - }; - }; - }; - }; - }; - }; -} diff --git a/config/Style.nix b/config/Style.nix deleted file mode 100644 index d0cf9c8..0000000 --- a/config/Style.nix +++ /dev/null @@ -1,123 +0,0 @@ -{ - lib, - config, - pkgs, - __findFile, - ... -}: -with lib; -let - cfg = config.style; - - mkTypeOption = default: type: mkOption { inherit default type; }; - mkStrOption = default: mkTypeOption default types.str; - mkIntOption = default: mkTypeOption default types.int; - mkFloatOption = default: mkTypeOption default types.float; - mkPkgOption = default: mkTypeOption default types.package; -in -{ - options.style = { - color = { - bg = { - dark = mkStrOption config.lib.stylix.colors.base00; - light = mkStrOption config.lib.stylix.colors.base07; - regular = mkStrOption config.lib.stylix.colors.base01; - }; - fg = { - dark = mkStrOption config.lib.stylix.colors.base04; - light = mkStrOption config.lib.stylix.colors.base06; - regular = mkStrOption config.lib.stylix.colors.base05; - }; - accent = mkStrOption config.lib.stylix.colors.base0A; - heading = mkStrOption config.lib.stylix.colors.base0D; - hl = mkStrOption config.lib.stylix.colors.base03; - keyword = mkStrOption config.lib.stylix.colors.base0E; - link = mkStrOption config.lib.stylix.colors.base09; - misc = mkStrOption config.lib.stylix.colors.base0F; - negative = mkStrOption config.lib.stylix.colors.base08; - neutral = mkStrOption config.lib.stylix.colors.base0C; - positive = mkStrOption config.lib.stylix.colors.base0B; - selection = mkStrOption config.lib.stylix.colors.base02; - transparent = mkStrOption "ffffff00"; - - accent-b = mkStrOption config.lib.stylix.colors.base0A-rgb-b; - accent-g = mkStrOption config.lib.stylix.colors.base0A-rgb-g; - accent-r = mkStrOption config.lib.stylix.colors.base0A-rgb-r; - - negative-b = mkStrOption config.lib.stylix.colors.base08-rgb-b; - negative-g = mkStrOption config.lib.stylix.colors.base08-rgb-g; - negative-r = mkStrOption config.lib.stylix.colors.base08-rgb-r; - - neutral-b = mkStrOption config.lib.stylix.colors.base0C-rgb-b; - neutral-g = mkStrOption config.lib.stylix.colors.base0C-rgb-g; - neutral-r = mkStrOption config.lib.stylix.colors.base0C-rgb-r; - - positive-b = mkStrOption config.lib.stylix.colors.base0B-rgb-b; - positive-g = mkStrOption config.lib.stylix.colors.base0B-rgb-g; - positive-r = mkStrOption config.lib.stylix.colors.base0B-rgb-r; - - bg-b = mkStrOption config.lib.stylix.colors.base00-rgb-b; - bg-g = mkStrOption config.lib.stylix.colors.base00-rgb-g; - bg-r = mkStrOption config.lib.stylix.colors.base00-rgb-r; - - fg-b = mkStrOption config.lib.stylix.colors.base06-rgb-b; - fg-g = mkStrOption config.lib.stylix.colors.base06-rgb-g; - fg-r = mkStrOption config.lib.stylix.colors.base06-rgb-r; - - border = mkStrOption config.lib.stylix.colors.base01; - border-b = mkStrOption config.lib.stylix.colors.base01-rgb-b; - border-g = mkStrOption config.lib.stylix.colors.base01-rgb-g; - border-r = mkStrOption config.lib.stylix.colors.base01-rgb-r; - }; - - font = { - size = { - application = mkIntOption 12; - terminal = mkIntOption 14; - popup = mkIntOption 12; - desktop = mkIntOption 14; - }; - serif = { - package = mkPkgOption (pkgs.callPackage { }); - name = mkStrOption "SF Pro Display"; - }; - sansSerif = { - package = mkPkgOption (pkgs.callPackage { }); - name = mkStrOption "SF Pro Display"; - }; - monospace = { - package = mkPkgOption (pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }); - name = mkStrOption "Terminess Nerd Font Mono"; - }; - emoji = { - package = mkPkgOption pkgs.noto-fonts-emoji; - name = mkStrOption "Noto Color Emoji"; - }; - }; - - opacity = { - application = mkFloatOption 0.85; - desktop = mkFloatOption 0.85; - popup = mkFloatOption 0.85; - terminal = mkFloatOption 0.85; - hex = mkStrOption "D9"; - }; - - # cursor = { - # name = mkStrOption "Adwaita"; - # package = mkPkgOption pkgs.adwaita-icon-theme; - # size = mkIntOption 14; - # }; - - cursor = { - name = mkStrOption "phinger-cursors-light"; - package = mkPkgOption pkgs.phinger-cursors; - size = mkIntOption 24; - }; - - window = { - gap = mkIntOption 8; - border = mkIntOption 4; - }; - }; -} diff --git a/config/Stylix.nix b/config/Stylix.nix deleted file mode 100644 index cd03e95..0000000 --- a/config/Stylix.nix +++ /dev/null @@ -1,42 +0,0 @@ -{ - pkgs, - config, - __findFile, - ... -}: -{ - stylix = { - enable = true; - image = config.module.wallpaper.path; - autoEnable = true; - polarity = "dark"; - fonts = { - inherit (config.style.font) - serif - sansSerif - monospace - emoji - ; - sizes = { - inherit (config.style.font.size) terminal desktop; - applications = config.style.font.size.application; - popups = config.style.font.size.popup; - }; - }; - opacity = { - inherit (config.style.opacity) desktop terminal; - applications = config.style.opacity.application; - popups = config.style.opacity.popups; - }; - inherit (config.style) cursor; - override = - if config.module.wallpaper.forceContrastText then - { - base04 = "000000"; - base05 = "ffffff"; - base06 = "ffffff"; - } - else - { }; - }; -} diff --git a/config/Wallpaper.nix b/config/Wallpaper.nix deleted file mode 100644 index 16f6acb..0000000 --- a/config/Wallpaper.nix +++ /dev/null @@ -1,21 +0,0 @@ -{ pkgs, lib, ... }: -with lib; -let - url = "https://i.imgur.com/yuZ2XSf.jpeg"; - sha256 = "sha256-Z35D7gn28d2dtPHHVwzySOingy/d8CWKmK9LQjpyjEk="; - forceContrastText = false; -in -{ - options = { - module.wallpaper = { - forceContrastText = mkOption { - default = warnIf forceContrastText "Style : Forced text contrast." forceContrastText; - type = types.bool; - }; - path = mkOption { - default = pkgs.fetchurl { inherit url sha256; }; - type = types.path; - }; - }; - }; -} diff --git a/container/Change.nix b/container/Change.nix index 218720e..d3b8a34 100644 --- a/container/Change.nix +++ b/container/Change.nix @@ -1,57 +1,52 @@ { - container, - lib, - config, - ... -}@args: -with lib; -let - cfg = config.container.module.change; -in -{ - options = { - container.module.change = { - enable = mkEnableOption "Change detection service"; - address = mkOption { - default = "10.1.0.41"; - type = types.str; - }; - port = mkOption { - default = 5000; - type = types.int; - }; - domain = mkOption { - default = "change.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/change"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.change; +in { + options.container.module.change = { + enable = lib.mkEnableOption "the change detection service"; + address = lib.mkOption { + default = "10.1.0.41"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 5000; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "change.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/change"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.change = container.mkContainer cfg { - bindMounts = { - "/var/lib/changedetection-io" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.change = container.mkContainer cfg { + bindMounts = { + "/var/lib/changedetection-io" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.changedetection-io = { - enable = true; - baseURL = cfg.domain; - behindProxy = true; - listenAddress = cfg.address; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.changedetection-io = { + enable = true; + baseURL = cfg.domain; + behindProxy = true; + listenAddress = cfg.address; + }; + }; + }; + }; } diff --git a/container/Chat.nix b/container/Chat.nix index b34abf1..e6055eb 100644 --- a/container/Chat.nix +++ b/container/Chat.nix @@ -1,81 +1,72 @@ { - container, - lib, - config, - pkgs, - ... -}: -let - cfg = config.container.module.chat; - db = config.container.module.postgres; -in -{ - options = { - container.module.chat = { - enable = lib.mkEnableOption "chat container."; - address = lib.mkOption { - default = "10.1.0.20"; - type = lib.types.str; - }; - port = lib.mkOption { - default = 8065; - type = lib.types.int; - }; - domain = lib.mkOption { - default = "chat.${config.container.domain}"; - type = lib.types.str; - }; - storage = lib.mkOption { - default = "${config.container.storage}/chat"; - type = lib.types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.chat; + db = config.container.module.postgres; +in { + options.container.module.chat = { + enable = lib.mkEnableOption "the chat container."; + address = lib.mkOption { + default = "10.1.0.20"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8065; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "chat.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/chat"; + type = lib.types.str; + }; + }; - # WIP: https://search.nixos.org/options?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=mattermost - config = lib.mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + # WIP: https://search.nixos.org/options?channel=24.05&from=0&size=50&sort=relevance&type=packages&query=mattermost + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.chat = container.mkContainer cfg { - bindMounts = { - "/var/lib/mattermost" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.chat = container.mkContainer cfg { + bindMounts = { + "/var/lib/mattermost" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.mattermost = { - enable = true; - listenAddress = ":${toString cfg.port}"; - localDatabaseCreate = false; - mutableConfig = false; - package = pkgs.mattermost; - siteName = "Chat"; - siteUrl = "https://${cfg.domain}"; - statePath = "/var/lib/mattermost"; - plugins = - let - calls = - let - version = "1.2.0"; - in - pkgs.fetchurl { - url = "https://github.com/mattermost/mattermost-plugin-calls/releases/download/v${version}/mattermost-plugin-calls-v${version}.tar.gz"; - hash = "sha256-yQGBpBPgXxC+Pm6dHlbwlNEdvn6wg9neSpNNTC4YYAA="; - }; - in - [ calls ]; - extraConfig = { - SqlSettings = { - DataSource = "postgres://mattermost:any@${db.address}:${toString db.port}/mattermost?sslmode=disable&connect_timeout=10"; - DriverName = "postgres"; - }; - }; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.mattermost = { + enable = true; + listenAddress = ":${toString cfg.port}"; + localDatabaseCreate = false; + mutableConfig = false; + package = pkgs.mattermost; + siteName = "Chat"; + siteUrl = "https://${cfg.domain}"; + statePath = "/var/lib/mattermost"; + plugins = [ + (pkgs.fetchurl rec { + hash = "sha256-yQGBpBPgXxC+Pm6dHlbwlNEdvn6wg9neSpNNTC4YYAA="; + url = "https://github.com/mattermost/mattermost-plugin-calls/releases/download/v${version}/mattermost-plugin-calls-v${version}.tar.gz"; + version = "1.2.0"; + }) + ]; + extraConfig = { + SqlSettings = { + DataSource = "postgres://mattermost:any@${db.address}:${toString db.port}/mattermost?sslmode=disable&connect_timeout=10"; + DriverName = "postgres"; + }; + }; + }; + }; + }; + }; } diff --git a/container/Cloud.nix b/container/Cloud.nix index 2ec8da0..2fad85d 100644 --- a/container/Cloud.nix +++ b/container/Cloud.nix @@ -1,85 +1,81 @@ { - container, - pkgs, - lib, - config, - ... -}@args: -with lib; -let - cfg = config.container.module.cloud; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.cloud; + postgres = config.container.module.postgres; + proxy = config.container.module.proxy; +in { + options.container.module.cloud = { + enable = lib.mkEnableOption "the file cloud service."; + address = lib.mkOption { + default = "10.1.0.13"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 80; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "cloud.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/cloud"; + type = lib.types.str; + }; + }; - postgres = config.container.module.postgres; - proxy = config.container.module.proxy; -in -{ - options = { - container.module.cloud = { - enable = mkEnableOption "File cloud service"; - address = mkOption { - default = "10.1.0.13"; - type = types.str; - }; - port = mkOption { - default = 80; - type = types.int; - }; - domain = mkOption { - default = "cloud.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/cloud"; - type = types.str; - }; - }; - }; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + containers.cloud = container.mkContainer cfg { + bindMounts = { + "/var/lib/nextcloud" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - containers.cloud = container.mkContainer cfg { - bindMounts = { - "/var/lib/nextcloud" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; - - config = - { config, ... }: - container.mkContainerConfig cfg { - services.nextcloud = { - enable = true; - # package = pkgs.nextcloud29; - hostName = cfg.domain; - # phpOptions = { - # memory_limit = lib.mkForce "20G"; - # }; - config = { - adminuser = "root"; - adminpassFile = "${pkgs.writeText "NextcloudPassword" "root"}"; - - dbhost = postgres.address; - dbname = "nextcloud"; - dbpassFile = "${pkgs.writeText "NextcloudDbPassword" "nextcloud"}"; - dbtype = "pgsql"; - dbuser = "nextcloud"; - }; - extraApps = { - inherit (config.services.nextcloud.package.packages.apps) contacts calendar onlyoffice; - }; - extraAppsEnable = true; - settings = { - trusted_domains = [ - cfg.address - cfg.domain - ]; - trusted_proxies = [ proxy.address ]; - allow_local_remote_servers = true; - }; - }; - }; - }; - }; + config = { config, ... }: container.mkContainerConfig cfg { + services.nextcloud = { + enable = true; + hostName = cfg.domain; + # package = pkgs.nextcloud29; + # phpOptions = { + # memory_limit = lib.mkForce "20G"; + # }; + config = { + adminpassFile = "${pkgs.writeText "NextcloudPassword" "root"}"; + adminuser = "root"; + dbhost = postgres.address; + dbname = "nextcloud"; + dbpassFile = "${pkgs.writeText "NextcloudDbPassword" "nextcloud"}"; + dbtype = "pgsql"; + dbuser = "nextcloud"; + }; + extraApps = { + inherit (config.services.nextcloud.package.packages.apps) + contacts calendar onlyoffice; + }; + extraAppsEnable = true; + settings = { + allow_local_remote_servers = true; + trusted_domains = [ + cfg.address + cfg.domain + ]; + trusted_proxies = [ + proxy.address + ]; + }; + }; + }; + }; + }; } diff --git a/container/Ddns.nix b/container/Ddns.nix index 311b075..10806cd 100644 --- a/container/Ddns.nix +++ b/container/Ddns.nix @@ -1,65 +1,59 @@ { - container, - lib, - config, - ... -}@args: -with lib; -let - cfg = config.container.module.ddns; -in -{ - options = { - container.module.ddns = { - enable = mkEnableOption "Dynamic dns client."; - address = mkOption { - default = "10.1.0.31"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/ddns"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.ddns; +in { + options.container.module.ddns = { + enable = lib.mkEnableOption "the dynamic dns client."; + address = lib.mkOption { + default = "10.1.0.31"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/ddns"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.ddns = container.mkContainer cfg { - bindMounts = { - "/data" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = true; - }; - }; + containers.ddns = container.mkContainer cfg { + bindMounts = { + "/data" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = true; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.cloudflare-dyndns = { - enable = true; - apiTokenFile = "/data/token"; - deleteMissing = false; - ipv4 = true; - ipv6 = false; - proxied = false; - domains = - let - domain = config.container.domain; - in - [ domain ] - ++ map (sub: "${sub}.${domain}") [ - "cloud" - "git" - "mail" - "office" - "paste" - "play" - "vpn" - ]; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.cloudflare-dyndns = { + enable = true; + apiTokenFile = "/data/token"; + deleteMissing = false; + ipv4 = true; + ipv6 = false; + proxied = false; + domains = let + domain = config.container.domain; + in [ + domain + ] ++ map (sub: "${sub}.${domain}") [ + "cloud" + "git" + "mail" + "office" + "paste" + "play" + "vpn" + ]; + }; + }; + }; + }; } diff --git a/container/Dns.nix b/container/Dns.nix index 49829d5..6de7bd6 100644 --- a/container/Dns.nix +++ b/container/Dns.nix @@ -1,144 +1,127 @@ { - container, - pkgs, - lib, - config, - ... -}: -let - cfg = config.container.module.dns; -in -{ - options = { - container.module.dns = { - enable = lib.mkEnableOption "the DNS server."; - address = lib.mkOption { - default = "10.1.0.6"; - type = lib.types.str; - }; - port = lib.mkOption { - default = 53; - type = lib.types.int; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.dns; +in { + options.container.module.dns = { + enable = lib.mkEnableOption "the DNS server."; + address = lib.mkOption { + default = "10.1.0.6"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 53; + type = lib.types.int; + }; + }; - config = lib.mkIf cfg.enable { - containers.dns = container.mkContainer cfg { - config = - { ... }: - container.mkContainerConfig cfg { - environment.systemPackages = [ pkgs.cloudflared ]; - - # systemd.services.cloudflared = { - # description = "Cloudflare DoH server."; - # enable = true; - # wantedBy = [ "multi-user.target" ]; - # serviceConfig = { - # Type = "simple"; - # ExecStart = "${lib.getExe pkgs.cloudflared} proxy-dns --port 5054"; - # }; - # }; - - services.blocky = { - enable = true; - # REF: https://0xerr0r.github.io/blocky/main/configuration/ - settings = { - bootstrapDns = "tcp+udp:1.1.1.1"; - connectIPVersion = "v4"; - upstreams.groups = { - default = [ "https://dns.quad9.net/dns-query" ]; - }; - caching = { - maxItemsCount = 100000; - maxTime = "30m"; - minTime = "5m"; - prefetchExpires = "2h"; - prefetchMaxItemsCount = 100000; - prefetchThreshold = 5; - prefetching = true; - }; - blocking = { - blockTTL = "1m"; - blockType = "zeroIP"; - loading = { - refreshPeriod = "24h"; - strategy = "blocking"; - downloads = { - timeout = "5m"; - attempts = 3; - cooldown = "10s"; - }; - }; - # SRC: https://oisd.nl - # SRC: https://v.firebog.net - denylists = { - suspicious = [ - "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt" - "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" # https://github.com/StevenBlack/hosts - "https://v.firebog.net/hosts/static/w3kbl.txt" - ]; - ads = [ - "https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" - "https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts" - "https://v.firebog.net/hosts/AdguardDNS.txt" - "https://v.firebog.net/hosts/Admiral.txt" - "https://v.firebog.net/hosts/Easylist.txt" - ]; - tracking = [ - "https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt" - "https://v.firebog.net/hosts/Easyprivacy.txt" - "https://v.firebog.net/hosts/Prigent-Ads.txt" - ]; - malicious = [ - "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt" - "https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt" - "https://phishing.army/download/phishing_army_blocklist_extended.txt" - "https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts" - "https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt" - "https://urlhaus.abuse.ch/downloads/hostfile/" - "https://v.firebog.net/hosts/Prigent-Crypto.txt" - "https://v.firebog.net/hosts/Prigent-Malware.txt" - ]; - other = [ - "https://big.oisd.nl/domainswild" - "https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser" - ]; - }; - # allowlists = { - # other = [ - # "/.*.vk.com/" - # ]; - # }; - clientGroupsBlock = { - default = [ - "suspicious" - "ads" - "tracking" - "malicious" - "other" - ]; - }; - }; - customDNS = { - mapping = - let - block = host: { ${host} = "0.0.0.0"; }; - in - { - # All subdomains to current host. - # ${config.container.domain} = config.container.host; - "voronind.com" = "10.0.0.1"; - } - // block "gosuslugi.ru" - // block "rutube.ru" - // block "vk.com"; - }; - ports.dns = cfg.port; - # httpPort = "80"; - }; - }; - }; - }; - }; + config = lib.mkIf cfg.enable { + containers.dns = container.mkContainer cfg { + config = { ... }: container.mkContainerConfig cfg { + services.blocky = { + enable = true; + # REF: https://0xerr0r.github.io/blocky/main/configuration/ + settings = { + bootstrapDns = "tcp+udp:1.1.1.1"; + connectIPVersion = "v4"; + ports.dns = cfg.port; + # httpPort = "80"; + upstreams.groups = { + default = [ + "https://dns.quad9.net/dns-query" + ]; + }; + caching = { + maxItemsCount = 100000; + maxTime = "30m"; + minTime = "5m"; + prefetchExpires = "2h"; + prefetchMaxItemsCount = 100000; + prefetchThreshold = 5; + prefetching = true; + }; + blocking = { + blockTTL = "1m"; + blockType = "zeroIP"; + loading = { + refreshPeriod = "24h"; + strategy = "blocking"; + downloads = { + attempts = 3; + cooldown = "10s"; + timeout = "5m"; + }; + }; + # SRC: https://oisd.nl + # SRC: https://v.firebog.net + denylists = { + suspicious = [ + "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt" + "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" # https://github.com/StevenBlack/hosts + "https://v.firebog.net/hosts/static/w3kbl.txt" + ]; + ads = [ + "https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" + "https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts" + "https://v.firebog.net/hosts/AdguardDNS.txt" + "https://v.firebog.net/hosts/Admiral.txt" + "https://v.firebog.net/hosts/Easylist.txt" + ]; + tracking = [ + "https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt" + "https://v.firebog.net/hosts/Easyprivacy.txt" + "https://v.firebog.net/hosts/Prigent-Ads.txt" + ]; + malicious = [ + "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt" + "https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt" + "https://phishing.army/download/phishing_army_blocklist_extended.txt" + "https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts" + "https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt" + "https://urlhaus.abuse.ch/downloads/hostfile/" + "https://v.firebog.net/hosts/Prigent-Crypto.txt" + "https://v.firebog.net/hosts/Prigent-Malware.txt" + ]; + other = [ + "https://big.oisd.nl/domainswild" + "https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser" + ]; + }; + # allowlists = { + # other = [ + # "/.*.vk.com/" + # ]; + # }; + clientGroupsBlock = { + default = [ + "ads" + "malicious" + "other" + "suspicious" + "tracking" + ]; + }; + }; + customDNS = { + mapping = let + block = host: { ${host} = "0.0.0.0"; }; + in { + # All subdomains to current host. + # ${config.container.domain} = config.container.host; + "voronind.com" = "10.0.0.1"; + } + // block "gosuslugi.ru" + // block "rutube.ru" + // block "vk.com" + ; + }; + }; + }; + }; + }; + }; } diff --git a/container/Download.nix b/container/Download.nix index 91db50e..ae460e8 100644 --- a/container/Download.nix +++ b/container/Download.nix @@ -1,68 +1,63 @@ { - container, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.download; -in -{ - options = { - container.module.download = { - enable = mkEnableOption "Downloader."; - address = mkOption { - default = "10.1.0.12"; - type = types.str; - }; - port = mkOption { - default = 8112; - type = types.int; - }; - domain = mkOption { - default = "download.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/download"; - type = types.str; - }; - memLimit = mkOption { - default = "4G"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.download; +in { + options.container.module.download = { + enable = lib.mkEnableOption "the bit-torrent downloader."; + address = lib.mkOption { + default = "10.1.0.12"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8112; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "download.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/download"; + type = lib.types.str; + }; + memLimit = lib.mkOption { + default = "4G"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.download = container.mkContainer cfg { - enableTun = true; + containers.download = container.mkContainer cfg { + enableTun = true; + bindMounts = { + "/var/lib/deluge/.config/deluge" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + } + // container.attachMedia "download" false + ; - bindMounts = { - "/var/lib/deluge/.config/deluge" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - } // container.attachMedia "download" false; - - config = - { ... }: - container.mkContainerConfig cfg { - services.deluge = { - enable = true; - dataDir = "/var/lib/deluge"; - web.enable = true; - }; - - systemd.services.deluged.serviceConfig = { - MemoryLimit = cfg.memLimit; - Restart = lib.mkForce "always"; - RuntimeMaxSec = "6h"; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.deluge = { + enable = true; + dataDir = "/var/lib/deluge"; + web.enable = true; + }; + systemd.services.deluged.serviceConfig = { + MemoryLimit = cfg.memLimit; + Restart = lib.mkForce "always"; + RuntimeMaxSec = "6h"; + }; + }; + }; + }; } diff --git a/container/Frkn.nix b/container/Frkn.nix index eec1917..522f361 100644 --- a/container/Frkn.nix +++ b/container/Frkn.nix @@ -1,130 +1,122 @@ -# TODO: Saved just in case for the dark future. -# в целом просто сделай себе шелл алиас gw-default="sudo ip route del default; sudo ip route add default via айпишник роутера" и шелл алиас gw-vpn="sudo ip route del default; sudo ip route add default via айпишник_впна" { - container, - pkgs, - lib, - config, - __findFile, - ... -}: -with lib; -let - cfg = config.container.module.frkn; -in -{ - options = { - container.module.frkn = { - enable = mkEnableOption "FRKN"; - address = mkOption { - default = "10.1.0.69"; - type = types.str; - }; - port = mkOption { - default = 1080; - type = types.int; - }; - torport = mkOption { - default = 9150; - type = types.int; - }; - xrayport = mkOption { - default = 1081; - type = types.int; - }; - storage = mkOption { - default = "${config.container.storage}/frkn"; - type = types.str; - }; - }; - }; + __findFile, + config, + container, + lib, + pkgs, + util, + ... +} @args: let + cfg = config.container.module.frkn; +in { + options.container.module.frkn = { + enable = lib.mkEnableOption "the Allmighty FRKN service."; + address = lib.mkOption { + default = "10.1.0.69"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 1080; + type = lib.types.int; + }; + torport = lib.mkOption { + default = 9150; + type = lib.types.int; + }; + xrayport = lib.mkOption { + default = 1081; + type = lib.types.int; + }; + storage = lib.mkOption { + default = "${config.container.storage}/frkn"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.frkn = container.mkContainer cfg { - bindMounts = { - "/data" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = true; - }; - }; + containers.frkn = container.mkContainer cfg { + bindMounts = { + "/data" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = true; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - boot.kernel.sysctl = { - "net.ipv4.conf.all.src_valid_mark" = 1; - "net.ipv4.ip_forward" = 1; - }; + config = { ... }: container.mkContainerConfig cfg { + imports = [ + (import args) + ]; - imports = [ ]; - module.zapret = { - enable = true; - params = config.module.zapret.params; - }; + boot.kernel.sysctl = { + "net.ipv4.conf.all.src_valid_mark" = 1; + "net.ipv4.ip_forward" = 1; + }; - services = { - microsocks = { - enable = true; - ip = cfg.address; - port = cfg.port; - disableLogging = true; - #authUsername - #outgoingBindIp - #authOnce - }; + module.zapret = { + enable = true; + params = config.module.zapret.params; + }; - tor = { - enable = true; - openFirewall = true; - settings = - let - exclude = "{RU},{UA},{BY},{KZ},{CN},{??}"; - in - { - # ExcludeExitNodes = exclude; - # ExcludeNodes = exclude; - #DNSPort = dnsport; - UseBridges = true; - ClientTransportPlugin = "obfs4 exec ${pkgs.obfs4}/bin/lyrebird"; - Bridge = [ - "obfs4 94.103.89.153:4443 5617848964FD6546968B5BF3FFA6C11BCCABE58B cert=tYsmuuTe9phJS0Gh8NKIpkVZP/XKs7gJCqi31o8LClwYetxzFz0fQZgsMwhNcIlZ0HG5LA iat-mode=0" - "obfs4 121.45.140.249:12123 0922E212E33B04F0B7C1E398161E8EDE06734F26 cert=3AQ4iJFAzxzt7a/zgXIiFEs6fvrXInXt1Dtr09DgnpvUzG/iiyRTdXYZKSYpI124Zt3ZUA iat-mode=0" - "obfs4 79.137.11.45:45072 ECA3197D49A29DDECD4ACBF9BCF15E4987B78137 cert=2FKyLWkPgMNCWxBD3cNOTRxJH3XP+HdStPGKMjJfw2YbvVjihIp3X2BCrtxQya9m5II5XA iat-mode=0" - "obfs4 145.239.31.71:10161 882125D15B59BB82BE66F999056CB676D3F061F8 cert=AnD+EvcBMuQDVM7PwW7NgFAzW1M5jDm7DjQtIIcBSjoyAf1FJ2p535rrYL2Kk8POAd0+aw iat-mode=0" - ]; - }; + services = { + microsocks = { + enable = true; + disableLogging = true; + ip = cfg.address; + port = cfg.port; + }; - client = { - enable = true; - #dns.enable = true; - socksListenAddress = { - IsolateDestAddr = true; - addr = cfg.address; - port = cfg.torport; - }; - }; - }; + tor = { + enable = true; + openFirewall = true; + settings = let + exclude = "{RU},{UA},{BY},{KZ},{CN},{??}"; + in { + # ExcludeExitNodes = exclude; + # ExcludeNodes = exclude; + # DNSPort = dnsport; + UseBridges = true; + ClientTransportPlugin = "obfs4 exec ${pkgs.obfs4}/bin/lyrebird"; + Bridge = [ + "obfs4 121.45.140.249:12123 0922E212E33B04F0B7C1E398161E8EDE06734F26 cert=3AQ4iJFAzxzt7a/zgXIiFEs6fvrXInXt1Dtr09DgnpvUzG/iiyRTdXYZKSYpI124Zt3ZUA iat-mode=0" + "obfs4 145.239.31.71:10161 882125D15B59BB82BE66F999056CB676D3F061F8 cert=AnD+EvcBMuQDVM7PwW7NgFAzW1M5jDm7DjQtIIcBSjoyAf1FJ2p535rrYL2Kk8POAd0+aw iat-mode=0" + "obfs4 79.137.11.45:45072 ECA3197D49A29DDECD4ACBF9BCF15E4987B78137 cert=2FKyLWkPgMNCWxBD3cNOTRxJH3XP+HdStPGKMjJfw2YbvVjihIp3X2BCrtxQya9m5II5XA iat-mode=0" + "obfs4 94.103.89.153:4443 5617848964FD6546968B5BF3FFA6C11BCCABE58B cert=tYsmuuTe9phJS0Gh8NKIpkVZP/XKs7gJCqi31o8LClwYetxzFz0fQZgsMwhNcIlZ0HG5LA iat-mode=0" + ]; + }; - xray = { - enable = true; - settingsFile = "/data/Client.json"; - }; - }; + client = { + enable = true; + # dns.enable = true; + socksListenAddress = { + IsolateDestAddr = true; + addr = cfg.address; + port = cfg.torport; + }; + }; + }; - systemd = { - services.tor.wantedBy = lib.mkForce [ ]; + xray = { + enable = true; + settingsFile = "/data/Client.json"; + }; + }; - timers.tor = { - timerConfig = { - OnBootSec = 5; - Unit = "tor.service"; - }; - wantedBy = [ "timers.target" ]; - }; - }; - }; - }; - }; + systemd = { + services.tor.wantedBy = lib.mkForce [ ]; + + timers.tor = { + timerConfig = { + OnBootSec = 5; + Unit = "tor.service"; + }; + wantedBy = [ "timers.target" ]; + }; + }; + }; + }; + }; } diff --git a/container/Git.nix b/container/Git.nix index 71521e8..b63cf2d 100644 --- a/container/Git.nix +++ b/container/Git.nix @@ -1,121 +1,111 @@ { - container, - pkgs, - config, - lib, - ... -}: -with lib; -let - cfg = config.container.module.git; -in -{ - options = { - container.module.git = { - enable = mkEnableOption "Git server."; - address = mkOption { - default = "10.1.0.8"; - type = types.str; - }; - port = mkOption { - default = 3000; - type = types.int; - }; - portSsh = mkOption { - default = 22144; - type = types.int; - }; - domain = mkOption { - default = "git.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/git"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.git; +in { + options.container.module.git = { + enable = lib.mkEnableOption "the git server."; + address = lib.mkOption { + default = "10.1.0.8"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 3000; + type = lib.types.int; + }; + portSsh = lib.mkOption { + default = 22144; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "git.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/git"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.git = container.mkContainer cfg { - bindMounts = { - "/var/lib/forgejo" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.git = container.mkContainer cfg { + bindMounts = { + "/var/lib/forgejo" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - environment.systemPackages = with pkgs; [ forgejo ]; + config = { ... }: container.mkContainerConfig cfg { + environment.systemPackages = with pkgs; [ + forgejo + ]; - services.forgejo = { - enable = true; - stateDir = "/var/lib/forgejo"; + services.forgejo = { + enable = true; + stateDir = "/var/lib/forgejo"; - database = - let - postgre = config.container.module.postgres; - in - { - type = "postgres"; - host = postgre.address; - port = postgre.port; - user = "forgejo"; - name = "forgejo"; - createDatabase = false; - }; + database = let + postgre = config.container.module.postgres; + in { + createDatabase = false; + host = postgre.address; + name = "forgejo"; + port = postgre.port; + type = "postgres"; + user = "forgejo"; + }; - settings = - let - gcArgs = "--aggressive --no-cruft --prune=now"; - gcTimeout = 600; - in - { - "service".DISABLE_REGISTRATION = true; - "log".LEVEL = "Error"; - "server" = { - DOMAIN = cfg.domain; - HTTP_ADDR = cfg.address; - ROOT_URL = "https://${cfg.domain}"; - - BUILTIN_SSH_SERVER_USER = "git"; - DISABLE_SSH = false; - SSH_PORT = cfg.portSsh; - START_SSH_SERVER = true; - }; - "ui" = { - AMBIGUOUS_UNICODE_DETECTION = false; - }; - "repository" = { - DEFAULT_PRIVATE = "private"; - DEFAULT_PUSH_CREATE_PRIVATE = true; - }; - "repository.pull-request".DEFAULT_MERGE_STYLE = "rebase"; - "repository.issue".MAX_PINNED = 99999; - "cron" = { - ENABLED = true; - RUN_AT_START = true; - }; - "repo-archive".ENABLED = false; - "cron.update_mirrors".SCHEDULE = "@midnight"; - "cron.cleanup_actions".ENABLED = true; - "cron.git_gc_repos" = { - ENABLED = true; - SCHEDULE = "@midnight"; - TIMEOUT = gcTimeout; - ARGS = gcArgs; - }; - "git" = { - GC_ARGS = gcArgs; - }; - "git.timeout".GC = gcTimeout; - }; - }; - }; - }; - }; + settings = let + gcArgs = "--aggressive --no-cruft --prune=now"; + gcTimeout = 600; + in { + "cron.cleanup_actions".ENABLED = true; + "cron.update_mirrors".SCHEDULE = "@midnight"; + "git".GC_ARGS = gcArgs; + "git.timeout".GC = gcTimeout; + "log".LEVEL = "Error"; + "repo-archive".ENABLED = false; + "repository.issue".MAX_PINNED = 99999; + "repository.pull-request".DEFAULT_MERGE_STYLE = "rebase"; + "service".DISABLE_REGISTRATION = true; + "server" = { + DOMAIN = cfg.domain; + HTTP_ADDR = cfg.address; + ROOT_URL = "https://${cfg.domain}"; + BUILTIN_SSH_SERVER_USER = "git"; + DISABLE_SSH = false; + SSH_PORT = cfg.portSsh; + START_SSH_SERVER = true; + }; + "ui" = { + AMBIGUOUS_UNICODE_DETECTION = false; + }; + "repository" = { + DEFAULT_PRIVATE = "private"; + DEFAULT_PUSH_CREATE_PRIVATE = true; + }; + "cron" = { + ENABLED = true; + RUN_AT_START = true; + }; + "cron.git_gc_repos" = { + ENABLED = true; + ARGS = gcArgs; + SCHEDULE = "@midnight"; + TIMEOUT = gcTimeout; + }; + }; + }; + }; + }; + }; } diff --git a/container/Hdd.nix b/container/Hdd.nix deleted file mode 100644 index e9a3616..0000000 --- a/container/Hdd.nix +++ /dev/null @@ -1,79 +0,0 @@ -# ISSUE: Broken, can't read/write sda device. -{ - container, - pkgs, - config, - lib, - ... -}: -with lib; -let - cfg = config.container.module.hdd; -in -{ - options = { - container.module.hdd = { - enable = mkEnableOption "Hdd health monitor."; - address = mkOption { - default = "10.1.0.10"; - type = types.str; - }; - port = mkOption { - default = 8080; - type = types.int; - }; - domain = mkOption { - default = "hdd.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/hdd"; - type = types.str; - }; - }; - }; - - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; - - containers.hdd = container.mkContainer cfg { - # bindMounts = let - # attachDrive = hostPath: { - # inherit hostPath; - # isReadOnly = false; - # }; - # in { - # "/opt/scrutiny" = { - # hostPath = "${cfg.storage}/data"; - # isReadOnly = false; - # }; - # "/dev/sda" = attachDrive "/dev/sda"; - # }; - - # allowedDevices = [ - # { - # modifier = "rwm"; - # node = "/dev/sda"; - # } - # ]; - - # additionalCapabilities = [ "CAP_SYS_ADMIN" ]; - - config = - { ... }: - container.mkContainerConfig cfg { - environment.systemPackages = with pkgs; [ smartmontools ]; - - services.scrutiny = { - enable = true; - settings.web = { - listen = { - host = cfg.address; - port = cfg.port; - }; - }; - }; - }; - }; - }; -} diff --git a/container/Home.nix b/container/Home.nix index 9b26b8e..fa9efe6 100644 --- a/container/Home.nix +++ b/container/Home.nix @@ -1,58 +1,54 @@ { - container, - pkgs, - util, - lib, - config, - __findFile, - ... -}@args: -with lib; -let - cfg = config.container.module.home; - package = (pkgs.callPackage args); -in -{ - options = { - container.module.home = { - enable = mkEnableOption "Dashboard."; - address = mkOption { - default = "10.1.0.18"; - type = types.str; - }; - port = mkOption { - default = 80; - type = types.int; - }; - domain = mkOption { - default = "home.${config.container.domain}"; - type = types.str; - }; - }; - }; + __findFile, + config, + container, + lib, + pkgs, + util, + ... +} @args: let + cfg = config.container.module.home; + package = (pkgs.callPackage args); +in { + options.container.module.home = { + enable = lib.mkEnableOption "the dashboard."; + address = lib.mkOption { + default = "10.1.0.18"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 80; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "home.${config.container.domain}"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - containers.home = container.mkContainer cfg { - config = - { ... }: - container.mkContainerConfig cfg { - environment.systemPackages = [ package ]; - systemd.packages = [ package ]; + config = lib.mkIf cfg.enable { + containers.home = container.mkContainer cfg { + config = { ... }: container.mkContainerConfig cfg { + environment.systemPackages = [ + package + ]; + systemd.packages = [ + package + ]; - services.nginx = { - enable = true; - virtualHosts.${cfg.domain} = container.mkServer { - default = true; - root = "${package}"; - - locations = { - "/".extraConfig = '' - try_files $uri $uri/index.html; - ''; - }; - }; - }; - }; - }; - }; + services.nginx = { + enable = true; + virtualHosts.${cfg.domain} = container.mkServer { + default = true; + root = "${package}"; + locations = { + "/".extraConfig = util.trimTabs '' + try_files $uri $uri/index.html; + ''; + }; + }; + }; + }; + }; + }; } diff --git a/container/Iot.nix b/container/Iot.nix index 0536bad..7612421 100644 --- a/container/Iot.nix +++ b/container/Iot.nix @@ -1,123 +1,119 @@ { - container, - lib, - config, - pkgsStable, - ... -}: -with lib; -let - cfg = config.container.module.iot; -in -{ - options = { - container.module.iot = { - enable = mkEnableOption "IoT service."; - address = mkOption { - default = "10.1.0.27"; - type = types.str; - }; - port = mkOption { - default = 8123; - type = types.int; - }; - domain = mkOption { - default = "iot.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/iot"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.iot; +in { + options.container.module.iot = { + enable = lib.mkEnableOption "IoT service."; + address = lib.mkOption { + default = "10.1.0.27"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8123; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "iot.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/iot"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.iot = container.mkContainer cfg { - bindMounts = { - "/var/lib/hass" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - "/dev/ttyACM0" = { - hostPath = "/dev/ttyACM0"; - isReadOnly = false; - }; - "/dev/serial/by-id" = { - hostPath = "/dev/serial/by-id"; - isReadOnly = false; - }; - } // container.attachMedia "photo" true; + containers.iot = container.mkContainer cfg { + bindMounts = { + "/var/lib/hass" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + "/dev/ttyACM0" = { + hostPath = "/dev/ttyACM0"; + isReadOnly = false; + }; + "/dev/serial/by-id" = { + hostPath = "/dev/serial/by-id"; + isReadOnly = false; + }; + } + // container.attachMedia "photo" true + ; - allowedDevices = [ - { - modifier = "rwm"; - node = "/dev/ttyACM0"; - } - ]; + allowedDevices = [ + { + modifier = "rwm"; + node = "/dev/ttyACM0"; + } + ]; - config = - { ... }: - container.mkContainerConfig cfg { - # Allow Hass to talk to Zigbee dongle. - users.users.hass.extraGroups = [ - "dialout" - "tty" - ]; + config = { ... }: container.mkContainerConfig cfg { + # Allow Hass to talk to Zigbee dongle. + users.users.hass.extraGroups = [ + "dialout" + "tty" + ]; - services.home-assistant = { - # NOTE: Missing: hacs. Inside hacs: `card-mod`, `Clock Weather Card`, `WallPanel` and `Yandex.Station`. - enable = true; - extraComponents = [ - "caldav" - "met" - "sun" - "systemmonitor" - "zha" - ]; - extraPackages = - python3Packages: with python3Packages; [ - aiodhcpwatcher - aiodiscover - aiogithubapi - arrow - async-upnp-client - av - gtts - ha-ffmpeg - hassil - home-assistant-intents - mutagen - numpy - pymicro-vad - pynacl - python-telegram-bot - pyturbojpeg - pyspeex-noise - zeroconf - ]; - configDir = "/var/lib/hass"; - # lovelaceConfig = { - # title = "Home IoT control center."; - # }; - # NOTE: Using imperative config because of secrets. - config = null; - }; + services.home-assistant = { + # NOTE: Missing: hacs. Inside hacs: `card-mod`, `Clock Weather Card`, `WallPanel` and `Yandex.Station`. + enable = true; + # NOTE: Using imperative config because of secrets. + config = null; + configDir = "/var/lib/hass"; + extraComponents = [ + "caldav" + "met" + "sun" + "systemmonitor" + "zha" + ]; + extraPackages = + python3Packages: with python3Packages; [ + aiodhcpwatcher + aiodiscover + aiogithubapi + arrow + async-upnp-client + av + gtts + ha-ffmpeg + hassil + home-assistant-intents + mutagen + numpy + pymicro-vad + pynacl + pyspeex-noise + python-telegram-bot + pyturbojpeg + zeroconf + ]; + # lovelaceConfig = { + # title = "Home IoT control center."; + # }; + }; - # HACK: Delay so that nextcloud calendar can reply on reboot. - systemd = { - services."home-assistant".wantedBy = mkForce [ ]; - timers.fixsystemd = { - timerConfig = { - OnBootSec = 15; - Unit = "home-assistant.service"; - }; - wantedBy = [ "timers.target" ]; - }; - }; - }; - }; - }; + # HACK: Delay so that nextcloud calendar can reply on reboot. + systemd = { + services."home-assistant".wantedBy = lib.mkForce [ ]; + timers.fixsystemd = { + timerConfig = { + OnBootSec = 60; + Unit = "home-assistant.service"; + }; + wantedBy = [ "timers.target" ]; + }; + }; + }; + }; + }; } diff --git a/container/Jobber.nix b/container/Jobber.nix index ca7b487..62d7873 100644 --- a/container/Jobber.nix +++ b/container/Jobber.nix @@ -1,79 +1,79 @@ { - container, - pkgsJobber, - poetry2nixJobber, - lib, - config, - __findFile, - ... -}: -with lib; -let - cfg = config.container.module.jobber; - script = import { - poetry2nix = poetry2nixJobber; - pkgs = pkgsJobber; - }; -in -{ - options = { - container.module.jobber = { - enable = mkEnableOption "Button pusher Stanley."; - address = mkOption { - default = "10.1.0.32"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/jobber"; - type = types.str; - }; - }; - }; + __findFile, + config, + container, + lib, + pkgsJobber, + poetry2nixJobber, + ... +}: let + cfg = config.container.module.jobber; + script = import { + pkgs = pkgsJobber; + poetry2nix = poetry2nixJobber; + }; +in { + options.container.module.jobber = { + enable = lib.mkEnableOption "Stanley - the button pusher."; + address = lib.mkOption { + default = "10.1.0.32"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/jobber"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.jobber = container.mkContainer cfg { - bindMounts = { - "/data" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = true; - }; - }; + containers.jobber = container.mkContainer cfg { + bindMounts = { + "/data" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = true; + }; + }; - enableTun = true; + enableTun = true; - config = - { lib, ... }: - let - packages = - [ script ] - ++ (with pkgsJobber; [ - firefox - geckodriver - openvpn - python311 - ]); - in - container.mkContainerConfig cfg { - networking = lib.mkForce { nameservers = [ "10.30.218.2" ]; }; + config = { ... }: let + packages = [ + script + ] ++ (with pkgsJobber; [ + firefox + geckodriver + openvpn + python311 + ]); + in container.mkContainerConfig cfg { + networking = lib.mkForce { + nameservers = [ + "10.30.218.2" + ]; + }; - systemd.services.jobber = { - description = "My job is pushing the button."; - enable = true; - wantedBy = [ "multi-user.target" ]; - path = packages; - environment = { - PYTHONUNBUFFERED = "1"; - PYTHONDONTWRITEBYTECODE = "1"; - }; - serviceConfig = { - Type = "simple"; - ExecStart = "${script}/bin/jobber -u"; - Restart = "on-failure"; - }; - }; - }; - }; - }; + systemd.services.jobber = { + description = "My job is pushing the button."; + enable = true; + path = packages; + wantedBy = [ + "multi-user.target" + ]; + environment = { + PYTHONDONTWRITEBYTECODE = "1"; + PYTHONUNBUFFERED = "1"; + }; + serviceConfig = { + ExecStart = "${script}/bin/jobber -u"; + Restart = "on-failure"; + Type = "simple"; + }; + }; + }; + }; + }; } diff --git a/container/Mail.nix b/container/Mail.nix index b44edbc..e99e37d 100644 --- a/container/Mail.nix +++ b/container/Mail.nix @@ -1,244 +1,224 @@ # Guide: https://nixos-mailserver.readthedocs.io/en/latest/setup-guide.html { - container, - pkgs, - util, - const, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.mail; - domain = config.container.domain; -in -{ - options = { - container.module.mail = { - enable = mkEnableOption "Email server."; - address = mkOption { - default = "10.1.0.5"; - type = types.str; - }; - port = mkOption { - default = 80; - type = types.int; - }; - domain = mkOption { - default = "mail.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/mail"; - type = types.str; - }; - }; - }; + config, + const, + container, + lib, + pkgs, + util, + ... +}: let + cfg = config.container.module.mail; + domain = config.container.domain; +in { + options.container.module.mail = { + enable = lib.mkEnableOption "the email server."; + address = lib.mkOption { + default = "10.1.0.5"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 80; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "mail.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/mail"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - # "data/indices" - # "data/vmail" - # "data/sieve" - # "data/dkim" - ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.mail = container.mkContainer cfg { - bindMounts = { - "/var/lib/dovecot/indices" = { - hostPath = "${cfg.storage}/data/indices"; - isReadOnly = false; - }; - "/var/vmail" = { - hostPath = "${cfg.storage}/data/vmail"; - isReadOnly = false; - }; - "/var/sieve" = { - hostPath = "${cfg.storage}/data/sieve"; - isReadOnly = false; - }; - "/var/dkim" = { - hostPath = "${cfg.storage}/data/dkim"; - isReadOnly = false; - }; - "/acme" = { - hostPath = "${config.container.module.proxy.storage}/letsencrypt"; - isReadOnly = true; - }; - }; + containers.mail = container.mkContainer cfg { + bindMounts = { + "/var/lib/dovecot/indices" = { + hostPath = "${cfg.storage}/data/indices"; + isReadOnly = false; + }; + "/var/vmail" = { + hostPath = "${cfg.storage}/data/vmail"; + isReadOnly = false; + }; + "/var/sieve" = { + hostPath = "${cfg.storage}/data/sieve"; + isReadOnly = false; + }; + "/var/dkim" = { + hostPath = "${cfg.storage}/data/dkim"; + isReadOnly = false; + }; + "/acme" = { + hostPath = "${config.container.module.proxy.storage}/letsencrypt"; + isReadOnly = true; + }; + }; - config = - { config, ... }: - container.mkContainerConfig cfg { - imports = [ - (builtins.fetchTarball { - url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/nixos-${const.stateVersion}/nixos-mailserver-nixos-${const.stateVersion}.tar.gz"; - sha256 = "sha256:0clvw4622mqzk1aqw1qn6shl9pai097q62mq1ibzscnjayhp278b"; - }) - ]; + config = { config, ... }: container.mkContainerConfig cfg { + imports = [ + (builtins.fetchTarball { + sha256 = "sha256:0clvw4622mqzk1aqw1qn6shl9pai097q62mq1ibzscnjayhp278b"; + url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/nixos-${const.stateVersion}/nixos-mailserver-nixos-${const.stateVersion}.tar.gz"; + }) + ]; - mailserver = { - enable = true; - domains = [ domain ]; - fqdn = cfg.domain; - sendingFqdn = domain; + mailserver = { + enable = true; + domains = [ domain ]; + fqdn = cfg.domain; + sendingFqdn = domain; - # Use `mkpasswd -sm bcrypt`. - loginAccounts = - let - defaultQuota = "1G"; - in - { - "admin@${domain}" = { - name = "admin"; - hashedPassword = "$2b$05$1O.dxXxaVshcBNybcqDRYuTlnYt3jDBwfPZWoDtP4BjOLoL0StYsi"; - quota = defaultQuota; - }; - "account@${domain}" = { - name = "account"; - hashedPassword = "$2b$05$sCyZHdk98KqQ1qsTIvbrUeRJlNBOwBqDgpdc1QxiSnONlEkZ8xGNO"; - quota = defaultQuota; - }; - "hi@${domain}" = { - name = "hi"; - hashedPassword = "$2b$05$6fT5hIhzIasNfp9IQr/ds.5RuxH95VKU3QJWlX3hmrAzDF3mExanq"; - quota = defaultQuota; - aliases = [ "voronind@${domain}" ]; - }; - "job@${domain}" = { - name = "job"; - hashedPassword = "$2b$05$.sUmv2.9EWPfLwJn/oZw2e1UbR7HrpNQ2THc5jjX3ysy7CY8ZWHUC"; - quota = defaultQuota; - }; - "trash@${domain}" = { - name = "trash"; - hashedPassword = "$2b$05$kn5ygZjN9NR3LXjnKKRw/.DXaZQNW.1XEottlCFIoKiDpIj.JGLJm"; - catchAll = [ domain ]; - quota = defaultQuota; - }; - "noreply@${domain}" = { - name = "noreply"; - hashedPassword = "$2b$05$TaKwoYmcmkAhsRRv6xG5wOkChcz50cB9BP6QPUDKNAcxMbrY6AeMK"; - sendOnly = true; - quota = defaultQuota; - }; - }; + # Use `mkpasswd -sm bcrypt`. + loginAccounts = let + defaultQuota = "1G"; + in { + "admin@${domain}" = { + hashedPassword = "$2b$05$1O.dxXxaVshcBNybcqDRYuTlnYt3jDBwfPZWoDtP4BjOLoL0StYsi"; + name = "admin"; + quota = defaultQuota; + }; + "account@${domain}" = { + hashedPassword = "$2b$05$sCyZHdk98KqQ1qsTIvbrUeRJlNBOwBqDgpdc1QxiSnONlEkZ8xGNO"; + name = "account"; + quota = defaultQuota; + }; + "hi@${domain}" = { + hashedPassword = "$2b$05$6fT5hIhzIasNfp9IQr/ds.5RuxH95VKU3QJWlX3hmrAzDF3mExanq"; + name = "hi"; + quota = defaultQuota; + aliases = [ + "voronind@${domain}" + ]; + }; + "job@${domain}" = { + hashedPassword = "$2b$05$.sUmv2.9EWPfLwJn/oZw2e1UbR7HrpNQ2THc5jjX3ysy7CY8ZWHUC"; + name = "job"; + quota = defaultQuota; + }; + "trash@${domain}" = { + hashedPassword = "$2b$05$kn5ygZjN9NR3LXjnKKRw/.DXaZQNW.1XEottlCFIoKiDpIj.JGLJm"; + name = "trash"; + quota = defaultQuota; + catchAll = [ + domain + ]; + }; + "noreply@${domain}" = { + hashedPassword = "$2b$05$TaKwoYmcmkAhsRRv6xG5wOkChcz50cB9BP6QPUDKNAcxMbrY6AeMK"; + name = "noreply"; + quota = defaultQuota; + sendOnly = true; + }; + }; - enableImap = true; - enableImapSsl = true; - enableSubmission = true; - enableSubmissionSsl = true; + enableImap = true; + enableImapSsl = true; + enableSubmission = true; + enableSubmissionSsl = true; - enableManageSieve = true; - virusScanning = false; + enableManageSieve = true; + virusScanning = false; - certificateScheme = "manual"; - keyFile = "/acme/live/${domain}/privkey.pem"; - certificateFile = "/acme/live/${domain}/cert.pem"; + certificateFile = "/acme/live/${domain}/cert.pem"; + certificateScheme = "manual"; + keyFile = "/acme/live/${domain}/privkey.pem"; - indexDir = "/var/lib/dovecot/indices"; - mailDirectory = "/var/vmail"; - sieveDirectory = "/var/sieve"; - dkimKeyDirectory = "/var/dkim"; + dkimKeyDirectory = "/var/dkim"; + indexDir = "/var/lib/dovecot/indices"; + mailDirectory = "/var/vmail"; + sieveDirectory = "/var/sieve"; - mailboxes = { - All = { - auto = "subscribe"; - specialUse = "All"; - }; - Archive = { - auto = "subscribe"; - specialUse = "Archive"; - }; - Drafts = { - auto = "subscribe"; - specialUse = "Drafts"; - }; - Junk = { - auto = "subscribe"; - specialUse = "Junk"; - # autoexpunge = "3d"; - }; - Sent = { - auto = "subscribe"; - specialUse = "Sent"; - }; - Trash = { - auto = "subscribe"; - specialUse = "Trash"; - # autoexpunge = "30d"; - }; - }; + mailboxes = let + mkSpecialBox = specialUse: { + ${specialUse} = { + inherit specialUse; + auto = "subscribe"; + }; + }; + in builtins.foldl' (acc: box: acc // (mkSpecialBox box)) {} [ + "All" + "Archive" + "Drafts" + "Junk" + "Sent" + "Trash" + ]; - dmarcReporting = { - inherit domain; - enable = true; - organizationName = "voronind"; - # email = "noreply@${domain}"; - }; + dmarcReporting = { + inherit domain; + enable = true; + organizationName = "voronind"; + # email = "noreply@${domain}"; + }; - # monitoring = { - # enable = true; - # alertAddress = "admin@${domain}"; - # }; - }; + # monitoring = { + # enable = true; + # alertAddress = "admin@${domain}"; + # }; + }; - services = { - roundcube = { - enable = true; - dicts = with pkgs.aspellDicts; [ - en - ru - ]; - hostName = cfg.domain; - plugins = [ "managesieve" ]; - extraConfig = '' - # starttls needed for authentication, so the fqdn required to match - # the certificate - # $config['smtp_server'] = "tls://${config.mailserver.fqdn}"; - # $config['smtp_server'] = "tls://localhost"; - $config['smtp_server'] = "localhost:25"; - $config['smtp_auth_type'] = null; - $config['smtp_user'] = ""; - $config['smtp_pass'] = ""; - # $config['smtp_user'] = "%u"; - # $config['smtp_pass'] = "%p"; - ''; - }; + services = { + roundcube = { + enable = true; + hostName = cfg.domain; + dicts = with pkgs.aspellDicts; [ + en + ru + ]; + plugins = [ + "managesieve" + ]; + extraConfig = util.trimTabs '' + $config['smtp_server'] = "localhost:25"; + $config['smtp_auth_type'] = null; + $config['smtp_user'] = ""; + $config['smtp_pass'] = ""; + # $config['smtp_user'] = "%u"; + # $config['smtp_pass'] = "%p"; + ''; + }; - nginx = { - virtualHosts.${cfg.domain} = { - forceSSL = false; - enableACME = false; - }; - }; - }; + nginx.virtualHosts.${cfg.domain} = { + enableACME = false; + forceSSL = false; + }; + }; - systemd = { - services.autoexpunge = { - description = "Delete old mail"; - serviceConfig.Type = "oneshot"; - path = [ pkgs.dovecot ]; - script = '' - doveadm expunge -A mailbox Junk SENTBEFORE 7d - doveadm expunge -A mailbox Trash SENTBEFORE 30d - doveadm expunge -u trash@voronind.com mailbox Inbox SENTBEFORE 30d - doveadm purge -A - ''; - }; + systemd = { + services.autoexpunge = { + description = "Delete old mail"; + serviceConfig = { + Type = "oneshot"; + }; + path = [ + pkgs.dovecot + ]; + script = util.trimTabs '' + doveadm expunge -A mailbox Junk SENTBEFORE 7d + doveadm expunge -A mailbox Trash SENTBEFORE 30d + doveadm expunge -u trash@voronind.com mailbox Inbox SENTBEFORE 30d + doveadm purge -A + ''; + }; - timers.autoexpunge = { - timerConfig = { - OnCalendar = "daily"; - Persistent = true; - Unit = "autoexpunge.service"; - }; - wantedBy = [ "timers.target" ]; - }; - }; - }; - }; - }; + timers.autoexpunge = { + timerConfig = { + OnCalendar = "daily"; + Persistent = true; + Unit = "autoexpunge.service"; + }; + wantedBy = [ + "timers.target" + ]; + }; + }; + }; + }; + }; } diff --git a/container/Office.nix b/container/Office.nix index 0c5330d..5e5f5c7 100644 --- a/container/Office.nix +++ b/container/Office.nix @@ -3,104 +3,99 @@ # 2. TODO: Generate JWT secret at /var/lib/onlyoffice/jwt, i.e. 9wLfMGha1YrfvWpb5hyYjZf8pvJQ3swS # See https://git.voronind.com/voronind/nixos/issues/74 { - container, - pkgs, - util, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.office; -in -{ - options = { - container.module.office = { - enable = mkEnableOption "Office web suite."; - address = mkOption { - default = "10.1.0.21"; - type = types.str; - }; - port = mkOption { - default = 8000; - type = types.int; - }; - domain = mkOption { - default = "office.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/office"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + util, + ... +}: let + cfg = config.container.module.office; +in { + options.container.module.office = { + enable = lib.mkEnableOption "the office web suite."; + address = lib.mkOption { + default = "10.1.0.21"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8000; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "office.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/office"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.office = container.mkContainer cfg { - bindMounts = { - "/var/lib/onlyoffice" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.office = container.mkContainer cfg { + bindMounts = { + "/var/lib/onlyoffice" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - # HACK: Temporarely run in docker due to https://github.com/ONLYOFFICE/onlyoffice-nextcloud/issues/931 - config = - { pkgs, ... }: - container.mkContainerConfig cfg { - virtualisation.oci-containers.backend = "docker"; - virtualisation.oci-containers.containers.office = { - autoStart = true; - image = "dockerhub.timeweb.cloud/onlyoffice/documentserver:latest"; - # ports = [ "${toString cfg.port}:8000" ]; - extraOptions = [ - "--network=host" - "--privileged" - ]; - environment = { - JWT_ENABLED = "true"; - JWT_SECRET = "8wLfKGha8YRfvwpB5hYYjZf8vtUQs3wS"; - AMQP_URI = "amqp://guest:guest@${config.container.module.rabbitmq.address}:${toString config.container.module.rabbitmq.port}"; - DB_HOST = config.container.module.postgres.address; - DB_PORT = toString config.container.module.postgres.port; - DB_NAME = "onlyoffice"; - DB_USER = "onlyoffice"; - DB_PWD = "onlyoffice"; - }; - }; - }; + # HACK: Temporarely run in docker due to https://github.com/ONLYOFFICE/onlyoffice-nextcloud/issues/931 + config = { pkgs, ... }: container.mkContainerConfig cfg { + virtualisation.oci-containers.backend = "docker"; + virtualisation.oci-containers.containers.office = { + autoStart = true; + image = "dockerhub.timeweb.cloud/onlyoffice/documentserver:latest"; + # ports = [ "${toString cfg.port}:8000" ]; + extraOptions = [ + "--network=host" + "--privileged" + ]; + environment = { + AMQP_URI = "amqp://guest:guest@${config.container.module.rabbitmq.address}:${toString config.container.module.rabbitmq.port}"; + DB_HOST = config.container.module.postgres.address; + DB_NAME = "onlyoffice"; + DB_PORT = toString config.container.module.postgres.port; + DB_PWD = "onlyoffice"; + DB_USER = "onlyoffice"; + JWT_ENABLED = "true"; + JWT_SECRET = "8wLfKGha8YRfvwpB5hYYjZf8vtUQs3wS"; + }; + }; + }; - # config = { pkgs, ... }: container.mkContainerConfig cfg { - # # HACK: For whatever reason it does not detect my global allowUnfree (I pass pkgs from host system in mkContainerConfig). - # nixpkgs.overlays = [ (final: prev: { - # corefonts = prev.corefonts.overrideAttrs (old: { - # meta.license = mkForce licenses.mit; - # }); - # })]; + # config = { pkgs, ... }: container.mkContainerConfig cfg { + # # HACK: For whatever reason it does not detect my global allowUnfree (I pass pkgs from host system in mkContainerConfig). + # nixpkgs.overlays = [ (final: prev: { + # corefonts = prev.corefonts.overrideAttrs (old: { + # meta.license = mkForce licenses.mit; + # }); + # })]; - # services.onlyoffice = let - # dbName = "onlyoffice"; - # in { - # enable = true; - # hostname = cfg.domain; + # services.onlyoffice = let + # dbName = "onlyoffice"; + # in { + # enable = true; + # hostname = cfg.domain; - # postgresName = dbName; - # postgresHost = config.container.module.postgres.address; - # postgresUser = dbName; - # postgresPasswordFile = "${pkgs.writeText "OfficeDbPassword" dbName}"; + # postgresName = dbName; + # postgresHost = config.container.module.postgres.address; + # postgresUser = dbName; + # postgresPasswordFile = "${pkgs.writeText "OfficeDbPassword" dbName}"; - # jwtSecretFile = "/var/lib/onlyoffice/jwt"; + # jwtSecretFile = "/var/lib/onlyoffice/jwt"; - # rabbitmqUrl = "amqp://guest:guest@${config.container.module.rabbitmq.address}:${toString config.container.module.rabbitmq.port}"; + # rabbitmqUrl = "amqp://guest:guest@${config.container.module.rabbitmq.address}:${toString config.container.module.rabbitmq.port}"; - # examplePort = cfg.port; - # enableExampleServer = true; - # }; - # }; - }; - }; + # examplePort = cfg.port; + # enableExampleServer = true; + # }; + # }; + }; + }; } diff --git a/container/Paper.nix b/container/Paper.nix index b1fe477..0677e76 100644 --- a/container/Paper.nix +++ b/container/Paper.nix @@ -1,106 +1,99 @@ { - container, - pkgs, - pkgsStable, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.paper; -in -{ - options = { - container.module.paper = { - enable = mkEnableOption "Paper scans manager."; - address = mkOption { - default = "10.1.0.40"; - type = types.str; - }; - port = mkOption { - default = 28981; - type = types.int; - }; - domain = mkOption { - default = "paper.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/paper"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.paper; +in { + options.container.module.paper = { + enable = lib.mkEnableOption "the paper scans manager."; + address = lib.mkOption { + default = "10.1.0.40"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 28981; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "paper.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/paper"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.paper = container.mkContainer cfg { - bindMounts = { - "/var/lib/paperless" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - "/var/lib/paperless/media" = { - hostPath = "${elemAt config.container.media.paper 0}"; - isReadOnly = false; - }; - }; + containers.paper = container.mkContainer cfg { + bindMounts = { + "/var/lib/paperless" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + "/var/lib/paperless/media" = { + hostPath = "${lib.elemAt config.container.media.paper 0}"; + isReadOnly = false; + }; + }; - config = - { lib, ... }: - container.mkContainerConfig cfg { - services.paperless = { - enable = true; - dataDir = "/var/lib/paperless"; - # address = cfg.domain; - address = "0.0.0.0"; - port = cfg.port; - # ISSUE: https://github.com/NixOS/nixpkgs/issues/322596 - # package = pkgsStable.paperless-ngx; - passwordFile = pkgs.writeText "PaperlessPassword" "root"; - settings = { - PAPERLESS_URL = "https://${cfg.domain}"; - PAPERLESS_ADMIN_USER = "root"; - PAPERLESS_DBHOST = config.container.module.postgres.address; - PAPERLESS_DBENGINE = "postgresql"; - PAPERLESS_DBNAME = "paperless"; - PAPERLESS_DBPASS = "paperless"; - PAPERLESS_DBPORT = config.container.module.postgres.port; - PAPERLESS_DBUSER = "paperless"; - PAPERLESS_OCR_LANGUAGE = "rus"; - PAPERLESS_REDIS = "redis://${config.container.module.redis.address}:${toString config.container.module.redis.port}"; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.paperless = { + enable = true; + address = "0.0.0.0"; + dataDir = "/var/lib/paperless"; + port = cfg.port; + passwordFile = pkgs.writeText "PaperlessPassword" "root"; # NOTE: Only for initial setup, change later. + settings = { + PAPERLESS_ADMIN_USER = "root"; + PAPERLESS_DBENGINE = "postgresql"; + PAPERLESS_DBHOST = config.container.module.postgres.address; + PAPERLESS_DBNAME = "paperless"; + PAPERLESS_DBPASS = "paperless"; + PAPERLESS_DBPORT = config.container.module.postgres.port; + PAPERLESS_DBUSER = "paperless"; + PAPERLESS_OCR_LANGUAGE = "rus"; + PAPERLESS_REDIS = "redis://${config.container.module.redis.address}:${toString config.container.module.redis.port}"; + PAPERLESS_URL = "https://${cfg.domain}"; + }; + }; - # HACK: This is required for TCP postgres connection. - systemd = { - services = { - paperless-scheduler = { - serviceConfig.PrivateNetwork = mkForce false; - wantedBy = mkForce [ ]; - }; - paperless-consumer = { - serviceConfig.PrivateNetwork = mkForce false; - wantedBy = mkForce [ ]; - }; - paperless-web = { - wantedBy = mkForce [ ]; - }; - paperless-task-queue = { - wantedBy = mkForce [ ]; - }; - }; - timers.fixsystemd = { - timerConfig = { - OnBootSec = 5; - Unit = "paperless-web.service"; - }; - wantedBy = [ "timers.target" ]; - }; - }; - }; - }; - }; + # HACK: This is required for TCP postgres connection. + systemd = { + services = { + paperless-scheduler = { + serviceConfig.PrivateNetwork = lib.mkForce false; + wantedBy = lib.mkForce [ ]; + }; + paperless-consumer = { + serviceConfig.PrivateNetwork = lib.mkForce false; + wantedBy = lib.mkForce [ ]; + }; + paperless-web = { + wantedBy = lib.mkForce [ ]; + }; + paperless-task-queue = { + wantedBy = lib.mkForce [ ]; + }; + }; + timers.fixsystemd = { + timerConfig = { + OnBootSec = 5; + Unit = "paperless-web.service"; + }; + wantedBy = [ + "timers.target" + ]; + }; + }; + }; + }; + }; } diff --git a/container/Pass.nix b/container/Pass.nix index fac3c2e..b831ae4 100644 --- a/container/Pass.nix +++ b/container/Pass.nix @@ -1,65 +1,59 @@ { - container, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.pass; -in -{ - options = { - container.module.pass = { - enable = mkEnableOption "Password manager"; - address = mkOption { - default = "10.1.0.9"; - type = types.str; - }; - port = mkOption { - default = 8000; - type = types.int; - }; - domain = mkOption { - default = "pass.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/pass"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.pass; +in { + options.container.module.pass = { + enable = lib.mkEnableOption "the password manager."; + address = lib.mkOption { + default = "10.1.0.9"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8000; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "pass.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/pass"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.pass = container.mkContainer cfg { - bindMounts = { - "/var/lib/bitwarden_rs" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.pass = container.mkContainer cfg { + bindMounts = { + "/var/lib/bitwarden_rs" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.vaultwarden = { - enable = true; - dbBackend = "sqlite"; - environmentFile = "/var/lib/bitwarden_rs/Env"; - config = { - # DATABASE_URL = "postgresql://vaultwarden:vaultwarden@${container.config.postgres.address}:${toString container.config.postgres.port}/vaultwarden"; - DATA_FOLDER = "/var/lib/bitwarden_rs"; - DOMAIN = "http://${cfg.domain}"; - SIGNUPS_ALLOWED = false; - WEB_VAULT_ENABLED = true; - ROCKET_ADDRESS = cfg.address; - ROCKET_PORT = cfg.port; - }; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.vaultwarden = { + enable = true; + dbBackend = "sqlite"; + environmentFile = "/var/lib/bitwarden_rs/Env"; + config = { + DATA_FOLDER = "/var/lib/bitwarden_rs"; + DOMAIN = "http://${cfg.domain}"; + ROCKET_ADDRESS = cfg.address; + ROCKET_PORT = cfg.port; + SIGNUPS_ALLOWED = false; + WEB_VAULT_ENABLED = true; + }; + }; + }; + }; + }; } diff --git a/container/Paste.nix b/container/Paste.nix index a167a8f..457cccf 100644 --- a/container/Paste.nix +++ b/container/Paste.nix @@ -1,138 +1,134 @@ { - pkgs, - container, - lib, - config, - __findFile, - ... -}@args: -with lib; -let - cfg = config.container.module.paste; - package = (pkgs.callPackage args); -in -{ - options = { - container.module.paste = { - enable = mkEnableOption "Pastebin."; - address = mkOption { - default = "10.1.0.14"; - type = types.str; - }; - port = mkOption { - default = 80; - type = types.int; - }; - domain = mkOption { - default = "paste.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/paste"; - type = types.str; - }; - }; - }; + __findFile, + config, + container, + lib, + pkgs, + util, + ... +} @args: let + cfg = config.container.module.paste; + package = (pkgs.callPackage args); +in { + options.container.module.paste = { + enable = lib.mkEnableOption "the text share platform."; + address = lib.mkOption { + default = "10.1.0.14"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 80; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "paste.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/paste"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - "tmp" - "nginxtmp" - "config" - ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "config" + "data" + "nginxtmp" + "tmp" + ]; - containers.paste = container.mkContainer cfg { - bindMounts = { - "/srv/data" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - "/tmp" = { - hostPath = "${cfg.storage}/tmp"; - isReadOnly = false; - }; - "/var/lib/nginx/tmp" = { - hostPath = "${cfg.storage}/nginxtmp"; - isReadOnly = false; - }; - "/srv/config" = { - hostPath = "${cfg.storage}/config"; - isReadOnly = false; - }; - }; + containers.paste = container.mkContainer cfg { + bindMounts = { + "/srv/data" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + "/tmp" = { + hostPath = "${cfg.storage}/tmp"; + isReadOnly = false; + }; + "/var/lib/nginx/tmp" = { + hostPath = "${cfg.storage}/nginxtmp"; + isReadOnly = false; + }; + "/srv/config" = { + hostPath = "${cfg.storage}/config"; + isReadOnly = false; + }; + }; - config = - { config, ... }: - container.mkContainerConfig cfg { - environment.systemPackages = [ package ]; - systemd.packages = [ package ]; + config = { config, ... }: container.mkContainerConfig cfg { + environment.systemPackages = [ + package + ]; + systemd.packages = [ + package + ]; - users.users.paste = { - group = "nginx"; - isSystemUser = true; - }; + users.users.paste = { + group = "nginx"; + isSystemUser = true; + }; - services.phpfpm.pools.paste = { - user = "paste"; - group = "nginx"; + services = { + phpfpm.pools.paste = { + group = "nginx"; + user = "paste"; + phpPackage = pkgs.php; + settings = { + "catch_workers_output" = true; + "listen.owner" = "nginx"; + "php_admin_flag[log_errors]" = true; + "php_admin_value[error_log]" = "stderr"; + "pm" = "dynamic"; + "pm.max_children" = "32"; + "pm.max_requests" = "500"; + "pm.max_spare_servers" = "4"; + "pm.min_spare_servers" = "2"; + "pm.start_servers" = "2"; + }; + phpEnv = { + # CONFIG_PATH = "${package}/cfg"; # NOTE: Not working? + }; + }; - phpPackage = pkgs.php; + nginx = { + enable = true; + virtualHosts.${cfg.domain} = container.mkServer { + default = true; + root = "${package}"; + locations = { + "/".extraConfig = util.trimTabs '' + rewrite ^ /index.php; + ''; - settings = { - "pm" = "dynamic"; - "php_admin_value[error_log]" = "stderr"; - "php_admin_flag[log_errors]" = true; - "listen.owner" = "nginx"; - "catch_workers_output" = true; - "pm.max_children" = "32"; - "pm.start_servers" = "2"; - "pm.min_spare_servers" = "2"; - "pm.max_spare_servers" = "4"; - "pm.max_requests" = "500"; - }; + "~ \\.php$".extraConfig = util.trimTabs '' + fastcgi_split_path_info ^(.+\.php)(/.+)$; + fastcgi_pass unix:${config.services.phpfpm.pools.paste.socket}; + include ${config.services.nginx.package}/conf/fastcgi.conf; + include ${config.services.nginx.package}/conf/fastcgi_params; + ''; - phpEnv = { - # CONFIG_PATH = "${package}/cfg"; - }; - }; + "~ \\.(js|css|ttf|woff2?|png|jpe?g|svg)$".extraConfig = util.trimTabs '' + add_header Cache-Control "public, max-age=15778463"; + add_header Referrer-Policy no-referrer; + add_header X-Content-Type-Options nosniff; + add_header X-Download-Options noopen; + add_header X-Permitted-Cross-Domain-Policies none; + add_header X-Robots-Tag none; + add_header X-XSS-Protection "1; mode=block"; + access_log off; + ''; + }; - services.nginx = { - enable = true; - virtualHosts.${cfg.domain} = container.mkServer { - default = true; - root = "${package}"; - - locations = { - "/".extraConfig = '' - rewrite ^ /index.php; - ''; - - "~ \\.php$".extraConfig = '' - fastcgi_split_path_info ^(.+\.php)(/.+)$; - fastcgi_pass unix:${config.services.phpfpm.pools.paste.socket}; - include ${config.services.nginx.package}/conf/fastcgi.conf; - include ${config.services.nginx.package}/conf/fastcgi_params; - ''; - - "~ \\.(js|css|ttf|woff2?|png|jpe?g|svg)$".extraConfig = '' - add_header Cache-Control "public, max-age=15778463"; - add_header X-Content-Type-Options nosniff; - add_header X-XSS-Protection "1; mode=block"; - add_header X-Robots-Tag none; - add_header X-Download-Options noopen; - add_header X-Permitted-Cross-Domain-Policies none; - add_header Referrer-Policy no-referrer; - access_log off; - ''; - }; - - extraConfig = '' - try_files $uri /index.php; - ''; - }; - }; - }; - }; - }; + extraConfig = util.trimTabs '' + try_files $uri /index.php; + ''; + }; + }; + }; + }; + }; + }; } diff --git a/container/Postgres.nix b/container/Postgres.nix index afd5c06..416ea99 100644 --- a/container/Postgres.nix +++ b/container/Postgres.nix @@ -1,104 +1,95 @@ { - container, - lib, - pkgs, - config, - ... -}: -with lib; -let - cfg = config.container.module.postgres; -in -{ - options = { - container.module.postgres = { - enable = mkEnableOption "Postgresql server."; - address = mkOption { - default = "10.1.0.3"; - type = types.str; - }; - port = mkOption { - default = 5432; - type = types.int; - }; - storage = mkOption { - default = "${config.container.storage}/postgres"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.postgres; +in { + options.container.module.postgres = { + enable = lib.mkEnableOption "the PostgreSQL server."; + address = lib.mkOption { + default = "10.1.0.3"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 5432; + type = lib.types.int; + }; + storage = lib.mkOption { + default = "${config.container.storage}/postgres"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.postgres = container.mkContainer cfg { - bindMounts = { - "/var/lib/postgresql/data" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.postgres = container.mkContainer cfg { + bindMounts = { + "/var/lib/postgresql/data" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.postgresql = - let - # Populate with services here. - configurations = with config.container.module; { - forgejo = git; - invidious = yt; - mattermost = chat; - nextcloud = cloud; - onlyoffice = office; - paperless = paper; - privatebin = paste; - }; + config = { ... }: container.mkContainerConfig cfg { + services.postgresql = let + # Populate with services here. + configurations = with config.container.module; { + forgejo = git; + invidious = yt; + mattermost = chat; + nextcloud = cloud; + onlyoffice = office; + paperless = paper; + privatebin = paste; + }; - access = configurations // { - all = { - address = config.container.host; - }; - }; + access = configurations // { + all.address = config.container.host; + }; - authentication = builtins.foldl' (acc: item: acc + "${item}\n") "" ( - mapAttrsToList (db: cfg: "host ${db} ${db} ${cfg.address}/32 trust") access - ); + authentication = let + rules = lib.mapAttrsToList (db: cfg: + "host ${db} ${db} ${cfg.address}/32 trust" + ) access; + in builtins.foldl' (acc: item: acc + "${item}\n") "" rules; - ensureDatabases = [ "root" ] ++ mapAttrsToList (name: _: name) configurations; + ensureDatabases = [ + "root" + ] ++ lib.mapAttrsToList (name: _: name) configurations; - ensureUsers = map (name: { - inherit name; - ensureClauses = - if name == "root" then - { - superuser = true; - createrole = true; - createdb = true; - } - else - { }; - ensureDBOwnership = true; - }) ensureDatabases; - in - { - inherit authentication ensureDatabases ensureUsers; + ensureUsers = map (name: { + inherit name; + ensureDBOwnership = true; + ensureClauses = if name == "root" then { + createdb = true; + createrole = true; + superuser = true; + } else { }; + }) ensureDatabases; + in { + inherit authentication ensureDatabases ensureUsers; - enable = true; - package = pkgs.postgresql_14; - dataDir = "/var/lib/postgresql/data/14"; - enableTCPIP = true; + enable = true; + dataDir = "/var/lib/postgresql/data/14"; + enableTCPIP = true; + package = pkgs.postgresql_14; - # NOTE: Debug mode. - # settings = { - # log_connections = true; - # log_destination = lib.mkForce "syslog"; - # log_disconnections = true; - # log_statement = "all"; - # logging_collector = true; - # }; - }; - }; - }; - }; + # NOTE: Debug mode. + # settings = { + # log_connections = true; + # log_destination = lib.mkForce "syslog"; + # log_disconnections = true; + # log_statement = "all"; + # logging_collector = true; + # }; + }; + }; + }; + }; } diff --git a/container/Print.nix b/container/Print.nix index 9d5f5b8..78e06bf 100644 --- a/container/Print.nix +++ b/container/Print.nix @@ -1,78 +1,72 @@ # NOTE: Login to contaier, run passwd and use that root/pw combo for administration. `AllowFrom = all` doesn't seem to work. - # ipp://192.168.2.237 # Pantum M6500W-Series { - container, - pkgs, - lib, - config, - __findFile, - ... -}@args: -with lib; -let - cfg = config.container.module.print; - package = pkgs.callPackage args; - host = config.container.host; -in -{ - options = { - container.module.print = { - enable = mkEnableOption "Printing server."; - address = mkOption { - default = "10.1.0.46"; - type = types.str; - }; - port = mkOption { - default = 631; - type = types.int; - }; - domain = mkOption { - default = "print.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/print"; - type = types.str; - }; - }; - }; + __findFile, + config, + container, + lib, + pkgs, + ... +} @args: let + cfg = config.container.module.print; + host = config.container.host; + package = pkgs.callPackage args; +in { + options.container.module.print = { + enable = lib.mkEnableOption "the printing server."; + address = lib.mkOption { + default = "10.1.0.46"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 631; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "print.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/print"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.print = container.mkContainer cfg { - bindMounts = { - "/var/lib/cups" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.print = container.mkContainer cfg { + bindMounts = { + "/var/lib/cups" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - networking.interfaces."eth0".ipv4.routes = [ - { - address = "192.168.2.237"; - prefixLength = 32; - via = host; - } - ]; + config = { ... }: container.mkContainerConfig cfg { + networking.interfaces."eth0".ipv4.routes = [ + { + address = "192.168.2.237"; # NOTE: Printer's IP address. + prefixLength = 32; + via = host; + } + ]; - services.printing = { - enable = true; - allowFrom = [ "all" ]; - browsing = true; - defaultShared = true; - drivers = [ package ]; - listenAddresses = [ "${cfg.address}:${toString cfg.port}" ]; - startWhenNeeded = true; - stateless = false; - webInterface = true; - }; - }; - }; - }; + services.printing = { + enable = true; + allowFrom = [ "all" ]; + browsing = true; + defaultShared = true; + drivers = [ package ]; + listenAddresses = [ "${cfg.address}:${toString cfg.port}" ]; + startWhenNeeded = true; + stateless = false; + webInterface = true; + }; + }; + }; + }; } diff --git a/container/Proxy.nix b/container/Proxy.nix index 5814cee..fb04ccf 100644 --- a/container/Proxy.nix +++ b/container/Proxy.nix @@ -10,91 +10,85 @@ # ``` # For certbot to generate new keys: `certbot certonly --manual --manual-public-ip-logging-ok --preferred-challenges dns-01 --server https://acme-v02.api.letsencrypt.org/directory -d "*.voronind.com" -d voronind.com` { - util, - container, - pkgs, - lib, - config, - ... -}@args: -with lib; -let - cfg = config.container.module.proxy; - virtualHosts = util.catSet (util.ls ./proxy/host) args; -in -{ - options = { - container.module.proxy = { - enable = mkEnableOption "Proxy server."; - address = mkOption { - default = "10.1.0.2"; - type = types.str; - }; - port = mkOption { - default = 443; - type = types.int; - }; - storage = mkOption { - default = "${config.container.storage}/proxy"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + util, + ... +} @args: let + cfg = config.container.module.proxy; + virtualHosts = util.catSet (util.ls ./proxy/host) args; +in { + options.container.module.proxy = { + enable = lib.mkEnableOption "the proxy server."; + address = lib.mkOption { + default = "10.1.0.2"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 443; + type = lib.types.int; + }; + storage = lib.mkOption { + default = "${config.container.storage}/proxy"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "challenge" - "letsencrypt" - ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "challenge" + "letsencrypt" + ]; - containers.proxy = container.mkContainer cfg { - bindMounts = { - "/etc/letsencrypt" = { - hostPath = "${cfg.storage}/letsencrypt"; - isReadOnly = false; - }; - "/var/www/.well-known" = { - hostPath = "${cfg.storage}/challenge"; - isReadOnly = false; - }; - }; + containers.proxy = container.mkContainer cfg { + bindMounts = { + "/etc/letsencrypt" = { + hostPath = "${cfg.storage}/letsencrypt"; + isReadOnly = false; + }; + "/var/www/.well-known" = { + hostPath = "${cfg.storage}/challenge"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - environment.systemPackages = with pkgs; [ certbot ]; + config = { ... }: container.mkContainerConfig cfg { + environment.systemPackages = with pkgs; [ + certbot + ]; - services.nginx = { - inherit virtualHosts; + services.nginx = { + inherit virtualHosts; + enable = true; + clientMaxBodySize = "4096m"; + recommendedOptimisation = true; + recommendedProxySettings = true; + appendConfig = util.trimTabs '' + worker_processes 4; + ''; + eventsConfig = util.trimTabs '' + worker_connections 4096; + ''; + appendHttpConfig = util.trimTabs '' + proxy_max_temp_file_size 0; + proxy_buffering off; - enable = true; - recommendedOptimisation = true; - recommendedProxySettings = true; - clientMaxBodySize = "4096m"; - appendConfig = '' - worker_processes 4; - ''; - eventsConfig = '' - worker_connections 4096; - ''; - appendHttpConfig = '' - proxy_max_temp_file_size 0; - proxy_buffering off; + server { + listen 443 ssl default_server; + server_name _; - server { - listen 443 ssl default_server; - server_name _; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - - return 403; - } - ''; - }; - }; - }; - }; + return 403; + } + ''; + }; + }; + }; + }; } diff --git a/container/Rabbitmq.nix b/container/Rabbitmq.nix index ece4693..5a015f0 100644 --- a/container/Rabbitmq.nix +++ b/container/Rabbitmq.nix @@ -1,58 +1,53 @@ { - container, - pkgs, - util, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.rabbitmq; -in -{ - options = { - container.module.rabbitmq = { - enable = mkEnableOption "Mqtt server."; - address = mkOption { - default = "10.1.0.28"; - type = types.str; - }; - port = mkOption { - default = 5672; - type = types.int; - }; - storage = mkOption { - default = "${config.container.storage}/rabbitmq"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + util, + ... +}: let + cfg = config.container.module.rabbitmq; +in { + options.container.module.rabbitmq = { + enable = lib.mkEnableOption "the mqtt server."; + address = lib.mkOption { + default = "10.1.0.28"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 5672; + type = lib.types.int; + }; + storage = lib.mkOption { + default = "${config.container.storage}/rabbitmq"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.rabbitmq = container.mkContainer cfg { - bindMounts = { - "/var/lib/rabbitmq" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.rabbitmq = container.mkContainer cfg { + bindMounts = { + "/var/lib/rabbitmq" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.rabbitmq = { - enable = true; - listenAddress = cfg.address; - port = cfg.port; - dataDir = "/var/lib/rabbitmq"; - configItems = { - "loopback_users" = "none"; - }; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.rabbitmq = { + enable = true; + dataDir = "/var/lib/rabbitmq"; + listenAddress = cfg.address; + port = cfg.port; + configItems = { + "loopback_users" = "none"; + }; + }; + }; + }; + }; } diff --git a/container/Read.nix b/container/Read.nix index 198faec..f1da1a9 100644 --- a/container/Read.nix +++ b/container/Read.nix @@ -1,61 +1,59 @@ { - container, - lib, - pkgs, - config, - ... -}: -with lib; -let - cfg = config.container.module.read; -in -{ - options = { - container.module.read = { - enable = mkEnableOption "Reading server."; - address = mkOption { - default = "10.1.0.39"; - type = types.str; - }; - port = mkOption { - default = 5000; - type = types.int; - }; - domain = mkOption { - default = "read.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/read"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.read; +in { + options.container.module.read = { + enable = lib.mkEnableOption "the reading server."; + address = lib.mkOption { + default = "10.1.0.39"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 5000; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "read.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/read"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.read = container.mkContainer cfg { - bindMounts = { - "/var/lib/kavita" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - } // container.attachMedia "book" true // container.attachMedia "manga" true; + containers.read = container.mkContainer cfg { + bindMounts = { + "/var/lib/kavita" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + } + // container.attachMedia "book" true + // container.attachMedia "manga" true + ; - config = - { ... }: - container.mkContainerConfig cfg { - services.kavita = { - enable = true; - dataDir = "/var/lib/kavita"; - tokenKeyFile = pkgs.writeText "KavitaToken" "xY19aQOa939/Ie6GCRGbubVK8zRwrgBY/20AuyMpYshUjwK1Uyl7bw1yknVh6jJIFIfwq2vAjeotOUq7NEsf9Q=="; - settings = { - IpAddresses = cfg.address; - Port = cfg.port; - }; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.kavita = { + enable = true; + dataDir = "/var/lib/kavita"; + tokenKeyFile = pkgs.writeText "KavitaToken" "xY19aQOa939/Ie6GCRGbubVK8zRwrgBY/20AuyMpYshUjwK1Uyl7bw1yknVh6jJIFIfwq2vAjeotOUq7NEsf9Q=="; + settings = { + IpAddresses = cfg.address; + Port = cfg.port; + }; + }; + }; + }; + }; } diff --git a/container/Redis.nix b/container/Redis.nix index 4fe74f3..fb88899 100644 --- a/container/Redis.nix +++ b/container/Redis.nix @@ -1,42 +1,35 @@ { - container, - pkgs, - util, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.redis; -in -{ - options = { - container.module.redis = { - enable = mkEnableOption "Redis server."; - address = mkOption { - default = "10.1.0.38"; - type = types.str; - }; - port = mkOption { - default = 6379; - type = types.int; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.redis; +in { + options.container.module.redis = { + enable = lib.mkEnableOption "the Redis server."; + address = lib.mkOption { + default = "10.1.0.38"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 6379; + type = lib.types.int; + }; + }; - config = mkIf cfg.enable { - containers.redis = container.mkContainer cfg { - config = - { ... }: - container.mkContainerConfig cfg { - services.redis.servers.main = { - enable = true; - port = cfg.port; - bind = cfg.address; - extraParams = [ "--protected-mode no" ]; - }; - }; - }; - }; + config = lib.mkIf cfg.enable { + containers.redis = container.mkContainer cfg { + config = { ... }: container.mkContainerConfig cfg { + services.redis.servers.main = { + enable = true; + port = cfg.port; + bind = cfg.address; + extraParams = [ + "--protected-mode no" + ]; + }; + }; + }; + }; } diff --git a/container/Search.nix b/container/Search.nix index 5a3b2c8..5123c4a 100644 --- a/container/Search.nix +++ b/container/Search.nix @@ -1,143 +1,138 @@ { - container, - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.search; -in -{ - options = { - container.module.search = { - enable = mkEnableOption "Search frontend."; - address = mkOption { - default = "10.1.0.26"; - type = types.str; - }; - port = mkOption { - default = 8080; - type = types.int; - }; - domain = mkOption { - default = "search.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/search"; - type = types.str; - }; - }; - }; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.search; +in { + options.container.module.search = { + enable = lib.mkEnableOption "the search frontend."; + address = lib.mkOption { + default = "10.1.0.26"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8080; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "search.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/search"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - containers.search = container.mkContainer cfg { - config = - { ... }: - container.mkContainerConfig cfg { - services.searx = { - enable = true; - package = pkgs.searxng; - # REF: https://github.com/searxng/searxng/blob/master/searx/settings.yml - settings = { - general = { - debug = false; - instance_name = "SearX"; - enable_metrics = false; - }; - server = { - bind_address = cfg.address; - port = cfg.port; - secret_key = "searxxx"; - limiter = false; - public_instance = false; - image_proxy = false; - method = "GET"; - }; - search = { - safe_search = 0; - autocomplete = ""; - autocomplete_min = 4; - default_lang = "auto"; - }; - ui = { - infinite_scroll = false; - default_theme = "simple"; - center_alignment = false; - default_locale = ""; - simple_style = "dark"; - hotkeys = "vim"; - }; - outgoing = { - request_timeout = 3.0; - max_request_timeout = 10.0; - pool_connections = 100; - pool_maxsize = 20; - enable_http2 = true; - # proxies = { - # "all://" = with config.container.module; [ - # # "socks5:${frkn.address}:${frkn.port}" - # "socks5:${frkn.address}:1081" - # # "socks5:${frkn.address}:9150" - # ]; - # }; - # using_tor_proxy = true; - # extra_proxy_timeout = 10; - }; - # plugins = [ ]; - enabled_plugins = [ - "Basic Calculator" - "Tracker URL remover" - "Hostnames plugin" - ]; - hostnames = { - replace = with config.container.module; { - "(.*\.)?youtube\.com$" = yt.domain; - "(.*\.)?youtu\.be$" = yt.domain; - }; - remove = [ - "(.*\.)?dzen\.ru?$" - "(.*\.)?facebook.com$" - "(.*\.)?gosuslugi\.ru?$" - "(.*\.)?quora\.com?$" - "(.*\.)?rutube\.ru?$" - "(.*\.)?vk\.com?$" - ]; - low_priority = [ - "(.*\.)?google(\..*)?$" - "(.*\.)?microsoft\.com?$" - ]; - high_priority = [ "(.*\.)?wikipedia.org$" ]; - }; - categories_as_tabs = { - general = { }; - images = { }; - videos = { }; - news = { }; - map = { }; - it = { }; - files = { }; - }; - engines = - let - mkEnable = name: { - inherit name; - disabled = false; - }; - mkDisable = name: { - inherit name; - disabled = true; - }; - in - [ - (mkEnable "bing") - (mkDisable "qwant") - ]; - }; - }; - }; - }; - }; + config = lib.mkIf cfg.enable { + containers.search = container.mkContainer cfg { + config = { ... }: container.mkContainerConfig cfg { + services.searx = { + enable = true; + package = pkgs.searxng; + # REF: https://github.com/searxng/searxng/blob/master/searx/settings.yml + settings = { + general = { + debug = false; + enable_metrics = false; + instance_name = "SearX"; + }; + server = { + bind_address = cfg.address; + image_proxy = false; + limiter = false; + method = "GET"; + port = cfg.port; + public_instance = false; + secret_key = "searxxx"; + }; + search = { + autocomplete = ""; + autocomplete_min = 4; + default_lang = "auto"; + safe_search = 0; + }; + ui = { + center_alignment = false; + default_locale = ""; + default_theme = "simple"; + hotkeys = "vim"; + infinite_scroll = false; + simple_style = "dark"; + }; + outgoing = { + enable_http2 = true; + max_request_timeout = 10.0; + pool_connections = 100; + pool_maxsize = 20; + request_timeout = 3.0; + # proxies = { + # "all://" = with config.container.module; [ + # # "socks5:${frkn.address}:${frkn.port}" + # "socks5:${frkn.address}:1081" + # # "socks5:${frkn.address}:9150" + # ]; + # }; + # using_tor_proxy = true; + # extra_proxy_timeout = 10; + }; + # plugins = [ ]; + enabled_plugins = [ + "Basic Calculator" + "Hostnames plugin" + "Tracker URL remover" + ]; + hostnames = { + replace = with config.container.module; { + "(.*\.)?youtu\.be$" = yt.domain; + "(.*\.)?youtube\.com$" = yt.domain; + }; + remove = [ + "(.*\.)?dzen\.ru?$" + "(.*\.)?facebook.com$" + "(.*\.)?gosuslugi\.ru?$" + "(.*\.)?quora\.com?$" + "(.*\.)?rutube\.ru?$" + "(.*\.)?vk\.com?$" + ]; + low_priority = [ + "(.*\.)?google(\..*)?$" + "(.*\.)?microsoft\.com?$" + ]; + high_priority = [ + "(.*\.)?4pda.to$" + "(.*\.)?github.com$" + "(.*\.)?wikipedia.org$" + ]; + }; + categories_as_tabs = { + files = { }; + general = { }; + images = { }; + it = { }; + map = { }; + news = { }; + videos = { }; + }; + engines = let + mkEnable = name: { + inherit name; + disabled = false; + }; + mkDisable = name: { + inherit name; + disabled = true; + }; + in [ + (mkEnable "bing") + (mkDisable "qwant") + ]; + }; + }; + }; + }; + }; } diff --git a/container/Status.nix b/container/Status.nix index 30a7932..a65431d 100644 --- a/container/Status.nix +++ b/container/Status.nix @@ -1,67 +1,66 @@ { - container, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.status; -in -{ - options = { - container.module.status = { - enable = mkEnableOption "Status monitor."; - address = mkOption { - default = "10.1.0.22"; - type = types.str; - }; - port = mkOption { - default = 3001; - type = types.int; - }; - domain = mkOption { - default = "status.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/status"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.status; +in { + options.container.module.status = { + enable = lib.mkEnableOption "the status monitor."; + address = lib.mkOption { + default = "10.1.0.22"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 3001; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "status.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/status"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.status = container.mkContainer cfg { - bindMounts = { - "/var/lib/uptime-kuma" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.status = container.mkContainer cfg { + bindMounts = { + "/var/lib/uptime-kuma" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { lib, ... }: - container.mkContainerConfig cfg { - networking = { - nameservers = mkForce [ config.container.module.dns.address ]; - }; + config = { ... }: container.mkContainerConfig cfg { + networking = { + nameservers = lib.mkForce [ + config.container.module.dns.address + ]; + }; - services.uptime-kuma = { - enable = true; - settings = { - DATA_DIR = "/var/lib/uptime-kuma/"; - HOST = cfg.address; - PORT = toString cfg.port; - }; - }; + services.uptime-kuma = { + enable = true; + settings = { + DATA_DIR = "/var/lib/uptime-kuma/"; + HOST = cfg.address; + PORT = toString cfg.port; + }; + }; - systemd.services.uptime-kuma = { - serviceConfig.DynamicUser = mkForce false; - }; - }; - }; - }; + systemd.services.uptime-kuma = { + serviceConfig = { + DynamicUser = lib.mkForce false; + }; + }; + }; + }; + }; } diff --git a/container/Stock.nix b/container/Stock.nix index d395fd4..61a41ed 100644 --- a/container/Stock.nix +++ b/container/Stock.nix @@ -1,65 +1,62 @@ { - container, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.stock; -in -{ - options = { - container.module.stock = { - enable = mkEnableOption "Stock management."; - address = mkOption { - default = "10.1.0.45"; - type = types.str; - }; - port = mkOption { - default = 80; - type = types.int; - }; - domain = mkOption { - default = "stock.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/stock"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.stock; +in { + options.container.module.stock = { + enable = lib.mkEnableOption "the stock management."; + address = lib.mkOption { + default = "10.1.0.45"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 80; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "stock.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/stock"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ "data" ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + ]; - containers.stock = container.mkContainer cfg { - bindMounts = { - "/var/lib/grocy" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.stock = container.mkContainer cfg { + bindMounts = { + "/var/lib/grocy" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - services.grocy = { - enable = true; - dataDir = "/var/lib/grocy"; - hostName = cfg.domain; - nginx.enableSSL = false; - settings = { - calendar = { - firstDayOfWeek = 1; - showWeekNumber = true; - }; - culture = "en"; - currency = "RUB"; - }; - }; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + services.grocy = { + enable = true; + dataDir = "/var/lib/grocy"; + hostName = cfg.domain; + nginx = { + enableSSL = false; + }; + settings = { + calendar = { + firstDayOfWeek = 1; + showWeekNumber = true; + }; + culture = "en"; + currency = "RUB"; + }; + }; + }; + }; + }; } diff --git a/container/Vpn.nix b/container/Vpn.nix index b448a64..327cc9b 100644 --- a/container/Vpn.nix +++ b/container/Vpn.nix @@ -1,100 +1,96 @@ { - container, - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.vpn; + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.vpn; - wireguardPeers = - let - mkPeer = name: ip: PublicKey: { - inherit PublicKey; - PresharedKeyFile = "/var/lib/wireguard/preshared/${name}"; - AllowedIPs = [ "${ip}/32" ]; - }; - in - [ - (mkPeer "dashaphone" "10.1.1.3" "O/3y8+QKEY8UoLVlmbc8xdhs248L4wtQcl1MsBBfoQo=") - (mkPeer "laptop" "10.1.1.9" "xxoCNPSB86zs8L8p+wXhqaIwpNDkiZu1Yjv8sj8XhgY=") - (mkPeer "phone" "10.1.1.5" "bFmFisMqbDpIrAg3o/GiRl9XhceZEVnZtkegZDTL4yg=") - (mkPeer "tablet" "10.1.1.6" "BdslswVc9OgUpEhJd0sugDBmYw44DiS0FbUPT5EjOG0=") - (mkPeer "work" "10.1.1.2" "Pk0AASSInKO9O8RaQEmm1uNrl0cwWTJDcT8rLn7PSA0=") - ]; -in -{ - options = { - container.module.vpn = { - enable = mkEnableOption "Vpn server."; - address = mkOption { - default = "10.1.0.23"; - type = types.str; - }; - port = mkOption { - default = 51820; - type = types.int; - }; - storage = mkOption { - default = "${config.container.storage}/vpn"; - type = types.str; - }; - }; - }; + wireguardPeers = let + mkPeer = name: ip: PublicKey: { + inherit PublicKey; + PresharedKeyFile = "/var/lib/wireguard/preshared/${name}"; + AllowedIPs = [ + "${ip}/32" + ]; + }; + in [ + (mkPeer "dashaphone" "10.1.1.3" "O/3y8+QKEY8UoLVlmbc8xdhs248L4wtQcl1MsBBfoQo=") + (mkPeer "laptop" "10.1.1.9" "xxoCNPSB86zs8L8p+wXhqaIwpNDkiZu1Yjv8sj8XhgY=") + (mkPeer "phone" "10.1.1.5" "bFmFisMqbDpIrAg3o/GiRl9XhceZEVnZtkegZDTL4yg=") + (mkPeer "tablet" "10.1.1.6" "BdslswVc9OgUpEhJd0sugDBmYw44DiS0FbUPT5EjOG0=") + (mkPeer "work" "10.1.1.2" "Pk0AASSInKO9O8RaQEmm1uNrl0cwWTJDcT8rLn7PSA0=") + ]; +in { + options.container.module.vpn = { + enable = lib.mkEnableOption "the vpn server."; + address = lib.mkOption { + default = "10.1.0.23"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 51820; + type = lib.types.int; + }; + storage = lib.mkOption { + default = "${config.container.storage}/vpn"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - "data/preshared" - ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + "data/preshared" + ]; - containers.vpn = container.mkContainer cfg { - bindMounts = { - "/var/lib/wireguard" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - }; + containers.vpn = container.mkContainer cfg { + bindMounts = { + "/var/lib/wireguard" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + }; - config = - { ... }: - container.mkContainerConfig cfg { - boot.kernel.sysctl = { - "net.ipv4.conf.all.src_valid_mark" = 1; - "net.ipv4.ip_forward" = 1; - }; + config = { ... }: container.mkContainerConfig cfg { + networking.useNetworkd = true; + boot.kernel.sysctl = { + "net.ipv4.conf.all.src_valid_mark" = 1; + "net.ipv4.ip_forward" = 1; + }; + environment.systemPackages = with pkgs; [ + wireguard-tools + ]; + systemd.network = { + enable = true; + netdevs = { + "50-wg0" = { + inherit wireguardPeers; + netdevConfig = { + Kind = "wireguard"; + MTUBytes = "1300"; + Name = "wg0"; + }; + wireguardConfig = { + ListenPort = cfg.port; + PrivateKeyFile = "/var/lib/wireguard/privkey"; + }; + }; + }; - environment.systemPackages = with pkgs; [ wireguard-tools ]; - networking.useNetworkd = true; - systemd.network = { - enable = true; - netdevs = { - "50-wg0" = { - netdevConfig = { - Kind = "wireguard"; - MTUBytes = "1300"; - Name = "wg0"; - }; - wireguardConfig = { - PrivateKeyFile = "/var/lib/wireguard/privkey"; - ListenPort = cfg.port; - }; - inherit wireguardPeers; - }; - }; - - networks.wg0 = { - matchConfig.Name = "wg0"; - address = [ "10.1.1.0/24" ]; - networkConfig = { - IPv4Forwarding = "yes"; - IPMasquerade = "ipv4"; - }; - }; - }; - }; - }; - }; + networks.wg0 = { + matchConfig.Name = "wg0"; + address = [ + "10.1.1.0/24" + ]; + networkConfig = { + IPMasquerade = "ipv4"; + IPv4Forwarding = "yes"; + }; + }; + }; + }; + }; + }; } diff --git a/container/Watch.nix b/container/Watch.nix index c80d038..c94d5a6 100644 --- a/container/Watch.nix +++ b/container/Watch.nix @@ -1,96 +1,87 @@ { - container, - lib, - config, - ... -}: -with lib; -let - cfg = config.container.module.watch; -in -{ - options = { - container.module.watch = { - enable = mkEnableOption "Media server."; - address = mkOption { - default = "10.1.0.11"; - type = types.str; - }; - port = mkOption { - default = 8096; - type = types.int; - }; - domain = mkOption { - default = "watch.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/watch"; - type = types.str; - }; - memLimit = mkOption { - default = "8G"; - type = types.str; - }; - }; - }; + config, + container, + lib, + ... +}: let + cfg = config.container.module.watch; +in { + options.container.module.watch = { + enable = lib.mkEnableOption "the media server."; + address = lib.mkOption { + default = "10.1.0.11"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 8096; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "watch.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/watch"; + type = lib.types.str; + }; + memLimit = lib.mkOption { + default = "8G"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - "cache" - ]; + config = lib.mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "cache" + "data" + ]; - containers.watch = container.mkContainer cfg { - bindMounts = - { - "/var/lib/jellyfin" = { - hostPath = "${cfg.storage}/data"; - isReadOnly = false; - }; - "/var/cache/jellyfin" = { - hostPath = "${cfg.storage}/cache"; - isReadOnly = false; - }; - "/dev/dri" = { - hostPath = "/dev/dri"; - isReadOnly = false; - }; - } - // container.attachMedia "anime" true - // container.attachMedia "download" true - // container.attachMedia "movie" true - // container.attachMedia "music" true - // container.attachMedia "photo" true - // container.attachMedia "porn" true - // container.attachMedia "show" true - // container.attachMedia "study" true - // container.attachMedia "work" true - // container.attachMedia "youtube" true; + containers.watch = container.mkContainer cfg { + bindMounts = { + "/var/lib/jellyfin" = { + hostPath = "${cfg.storage}/data"; + isReadOnly = false; + }; + "/var/cache/jellyfin" = { + hostPath = "${cfg.storage}/cache"; + isReadOnly = false; + }; + "/dev/dri" = { + hostPath = "/dev/dri"; + isReadOnly = false; + }; + } + // container.attachMedia "anime" true + // container.attachMedia "download" true + // container.attachMedia "movie" true + // container.attachMedia "music" true + // container.attachMedia "photo" true + // container.attachMedia "porn" true + // container.attachMedia "show" true + // container.attachMedia "study" true + // container.attachMedia "work" true + // container.attachMedia "youtube" true + ; - allowedDevices = [ - { - modifier = "rwm"; - node = "/dev/dri/renderD128"; - } - ]; + allowedDevices = [ + { + modifier = "rwm"; + node = "/dev/dri/renderD128"; + } + ]; - config = - { ... }: - container.mkContainerConfig cfg { - # users.users.jellyfin.extraGroups = [ - # "video" - # "render" - # ]; - - services.jellyfin = { - enable = true; - cacheDir = "/var/cache/jellyfin"; - dataDir = "/var/lib/jellyfin"; - }; - - systemd.services.jellyfin.serviceConfig.MemoryLimit = cfg.memLimit; - }; - }; - }; + config = { ... }: container.mkContainerConfig cfg { + systemd.services.jellyfin.serviceConfig.MemoryLimit = cfg.memLimit; + services.jellyfin = { + enable = true; + cacheDir = "/var/cache/jellyfin"; + dataDir = "/var/lib/jellyfin"; + }; + # users.users.jellyfin.extraGroups = [ + # "video" + # "render" + # ]; + }; + }; + }; } diff --git a/container/Yt.nix b/container/Yt.nix index 3b69355..24e5069 100644 --- a/container/Yt.nix +++ b/container/Yt.nix @@ -1,64 +1,59 @@ { - container, - pkgs, - lib, - config, - __findFile, - ... -}: -with lib; -let - cfg = config.container.module.yt; -in -{ - options = { - container.module.yt = { - enable = mkEnableOption "YouTube frontend."; - address = mkOption { - default = "10.1.0.19"; - type = types.str; - }; - port = mkOption { - default = 3000; - type = types.int; - }; - domain = mkOption { - default = "yt.${config.container.domain}"; - type = types.str; - }; - storage = mkOption { - default = "${config.container.storage}/yt"; - type = types.str; - }; - }; - }; + __findFile, + config, + container, + lib, + pkgs, + ... +}: let + cfg = config.container.module.yt; +in { + options.container.module.yt = { + enable = lib.mkEnableOption "the YouTube frontend."; + address = lib.mkOption { + default = "10.1.0.19"; + type = lib.types.str; + }; + port = lib.mkOption { + default = 3000; + type = lib.types.int; + }; + domain = lib.mkOption { + default = "yt.${config.container.domain}"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "${config.container.storage}/yt"; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - containers.yt = container.mkContainer cfg { - config = - { ... }: - container.mkContainerConfig cfg { - services.invidious = { - enable = true; - domain = cfg.domain; - port = cfg.port; - nginx.enable = false; - database = { - port = config.container.module.postgres.port; - host = config.container.module.postgres.address; - createLocally = false; - passwordFile = "${pkgs.writeText "InvidiousDbPassword" "invidious"}"; - }; - settings = { - admins = [ "root" ]; - captcha_enabled = false; - check_tables = true; - registration_enabled = false; - external_port = 443; - https_only = true; - }; - }; - }; - }; - }; + config = lib.mkIf cfg.enable { + containers.yt = container.mkContainer cfg { + config = { ... }: container.mkContainerConfig cfg { + services.invidious = { + enable = true; + domain = cfg.domain; + port = cfg.port; + nginx.enable = false; + database = { + host = config.container.module.postgres.address; + port = config.container.module.postgres.port; + createLocally = false; + passwordFile = "${pkgs.writeText "InvidiousDbPassword" "invidious"}"; + }; + settings = { + captcha_enabled = false; + check_tables = true; + external_port = 443; + https_only = true; + registration_enabled = false; + admins = [ + "root" + ]; + }; + }; + }; + }; + }; } diff --git a/container/default.nix b/container/default.nix index e2b9b1c..0c5d9ce 100644 --- a/container/default.nix +++ b/container/default.nix @@ -1,61 +1,57 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.container; -in { - options = { - container = { - enable = mkEnableOption "Containers!!"; + config, + lib, + ... +}: let + cfg = config.container; +in { + options.container = { + enable = lib.mkEnableOption "Containers!!"; + autoStart = lib.mkOption { + default = false; + type = lib.types.bool; + }; + host = lib.mkOption { + default = "0.0.0.0"; + type = lib.types.str; + }; + localAccess = lib.mkOption { + default = "0.0.0.0"; + type = lib.types.str; + }; + storage = lib.mkOption { + default = "/tmp/container"; + type = lib.types.str; + }; + domain = lib.mkOption { + default = "local"; + type = lib.types.str; + }; + interface = lib.mkOption { + default = "lo"; + type = lib.types.str; + }; + media = lib.mkOption { + default = { }; + type = lib.types.attrs; + }; + }; - autoStart = mkOption { - default = false; - type = types.bool; - }; - - host = mkOption { - default = "0.0.0.0"; - type = types.str; - }; - - localAccess = mkOption { - default = "0.0.0.0"; - type = types.str; - }; - - storage = mkOption { - default = "/tmp/container"; - type = types.str; - }; - - domain = mkOption { - default = "local"; - type = types.str; - }; - - interface = mkOption { - default = "lo"; - type = types.str; - }; - - media = mkOption { - default = { }; - type = types.attrs; - }; - }; - }; - - config = mkIf cfg.enable { - # This is the network for all the containers. - # They are not available to the external interface by default, - # instead they all expose specific ports in their configuration. - networking = { - nat = { - enable = true; - internalInterfaces = [ "ve-+" ]; - externalInterface = config.container.interface; - }; - networkmanager.unmanaged = [ "interface-name:ve-*" ]; - }; - }; + config = lib.mkIf cfg.enable { + # This is the network for all the containers. + # They are not available to the external interface by default, + # instead they all expose specific ports in their configuration. + networking = { + nat = { + enable = true; + externalInterface = config.container.interface; + internalInterfaces = [ + "ve-+" + ]; + }; + networkmanager.unmanaged = [ + "interface-name:ve-*" + ]; + }; + }; } diff --git a/container/proxy/host/Camera.nix b/container/proxy/host/Camera.nix index 5ee2196..5fc9748 100644 --- a/container/proxy/host/Camera.nix +++ b/container/proxy/host/Camera.nix @@ -1,27 +1,30 @@ -{ config, container, ... }: -let - domain = "camera.${config.container.domain}"; - address = "192.168.2.249"; - port = 554; -in { - ${domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; + config, + container, + util, + ... +}: let + address = "192.168.2.249"; + domain = "camera.${config.container.domain}"; + port = 554; +in { + ${domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - return 301 rtsp://${address}:${toString port}/live/main; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + return 301 rtsp://${address}:${toString port}/live/main; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Change.nix b/container/proxy/host/Change.nix index 0915cb2..6e5e31f 100644 --- a/container/proxy/host/Change.nix +++ b/container/proxy/host/Change.nix @@ -1,30 +1,33 @@ -{ config, container, ... }: -let - cfg = config.container.module.change; - name = "change"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + config, + container, + util, + ... +}: let + cfg = config.container.module.change; + name = "change"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; - proxy_pass http://''$${name}$request_uri; + proxy_pass http://''$${name}$request_uri; - add_header Referrer-Policy 'origin'; - } + add_header Referrer-Policy 'origin'; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Chat.nix b/container/proxy/host/Chat.nix index eccbe2c..6d95a0d 100644 --- a/container/proxy/host/Chat.nix +++ b/container/proxy/host/Chat.nix @@ -1,28 +1,31 @@ -{ config, container, ... }: -let - cfg = config.container.module.chat; - name = "chat"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + config, + container, + util, + ... +}: let + cfg = config.container.module.chat; + name = "chat"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; - proxy_pass http://''$${name}$request_uri; - } + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Cloud.nix b/container/proxy/host/Cloud.nix index e660113..e9fbc24 100644 --- a/container/proxy/host/Cloud.nix +++ b/container/proxy/host/Cloud.nix @@ -1,31 +1,34 @@ -{ config, container, ... }: -let - cfg = config.container.module.cloud; - name = "cloud"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + config, + container, + util, + ... +}: let + cfg = config.container.module.cloud; + name = "cloud"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location ~ ^/(settings/admin|settings/users|settings/apps|login|api) { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location ~ ^/(settings/admin|settings/users|settings/apps|login|api) { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - location / { - proxy_pass http://''$${name}$request_uri; - } + location / { + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Download.nix b/container/proxy/host/Download.nix index 70c70e1..a43bd70 100644 --- a/container/proxy/host/Download.nix +++ b/container/proxy/host/Download.nix @@ -1,27 +1,30 @@ -{ config, container, ... }: -let - cfg = config.container.module.download; - name = "download"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + config, + container, + util, + ... +}: let + cfg = config.container.module.download; + name = "download"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Git.nix b/container/proxy/host/Git.nix index e562c3a..95440ea 100644 --- a/container/proxy/host/Git.nix +++ b/container/proxy/host/Git.nix @@ -1,30 +1,33 @@ -{ container, config, ... }: -let - cfg = config.container.module.git; - name = "git"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.git; + name = "git"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location ~ ^/(admin|api|user) { - allow ${config.container.localAccess}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location ~ ^/(admin|api|user) { + allow ${config.container.localAccess}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - location / { - proxy_pass http://''$${name}$request_uri; - } + location / { + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Hdd.nix b/container/proxy/host/Hdd.nix deleted file mode 100644 index 2971f3c..0000000 --- a/container/proxy/host/Hdd.nix +++ /dev/null @@ -1,27 +0,0 @@ -{ container, config, ... }: -let - cfg = config.container.module.hdd; - name = "hdd"; -in -{ - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; - - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } - - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; -} diff --git a/container/proxy/host/Home.nix b/container/proxy/host/Home.nix index 369d81c..d2aa04e 100644 --- a/container/proxy/host/Home.nix +++ b/container/proxy/host/Home.nix @@ -1,27 +1,30 @@ -{ config, container, ... }: -let - cfg = config.container.module.home; - name = "home"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + config, + container, + util, + ... +}: let + cfg = config.container.module.home; + name = "home"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Iot.nix b/container/proxy/host/Iot.nix index 6b17160..b572ce0 100644 --- a/container/proxy/host/Iot.nix +++ b/container/proxy/host/Iot.nix @@ -1,34 +1,37 @@ -{ container, config, ... }: -let - cfg = config.container.module.iot; - name = "iot"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.iot; + name = "iot"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; - # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; - proxy_set_header Host $host; - proxy_http_version 1.1; - proxy_set_header Upgrade $http_upgrade; - proxy_set_header Connection "upgrade"; + # proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for; + proxy_set_header Host $host; + proxy_http_version 1.1; + proxy_set_header Upgrade $http_upgrade; + proxy_set_header Connection "upgrade"; - proxy_pass http://''$${name}$request_uri; - } + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Mail.nix b/container/proxy/host/Mail.nix index 11ab27d..abea01a 100644 --- a/container/proxy/host/Mail.nix +++ b/container/proxy/host/Mail.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.mail; - name = "mail"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.mail; + name = "mail"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Office.nix b/container/proxy/host/Office.nix index 089b226..2074f11 100644 --- a/container/proxy/host/Office.nix +++ b/container/proxy/host/Office.nix @@ -1,28 +1,31 @@ -{ container, config, ... }: -let - cfg = config.container.module.office; - name = "office"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.office; + name = "office"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - # allow ${config.container.localAccess}; - # allow ${config.container.module.status.address}; - # allow ${config.container.module.vpn.address}; - # allow ${config.container.module.frkn.address}; - # deny all; - add_header X-Forwarded-Proto https; - proxy_pass http://''$${name}$request_uri; - } + location / { + # allow ${config.container.localAccess}; + # allow ${config.container.module.status.address}; + # allow ${config.container.module.vpn.address}; + # allow ${config.container.module.frkn.address}; + # deny all; + add_header X-Forwarded-Proto https; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Paper.nix b/container/proxy/host/Paper.nix index c79ad93..5c96ecf 100644 --- a/container/proxy/host/Paper.nix +++ b/container/proxy/host/Paper.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.paper; - name = "paper"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.paper; + name = "paper"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Pass.nix b/container/proxy/host/Pass.nix index 0d6ede0..12cec10 100644 --- a/container/proxy/host/Pass.nix +++ b/container/proxy/host/Pass.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.pass; - name = "pass"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.pass; + name = "pass"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Paste.nix b/container/proxy/host/Paste.nix index ec0c65a..36c0004 100644 --- a/container/proxy/host/Paste.nix +++ b/container/proxy/host/Paste.nix @@ -1,26 +1,29 @@ -{ container, config, ... }: -let - cfg = config.container.module.paste; - name = "paste"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.paste; + name = "paste"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location = / { - return 403; - } + location = / { + return 403; + } - location / { - proxy_pass http://''$${name}$request_uri; - } + location / { + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Print.nix b/container/proxy/host/Print.nix index 8848366..fe92374 100644 --- a/container/proxy/host/Print.nix +++ b/container/proxy/host/Print.nix @@ -1,32 +1,35 @@ -{ container, config, ... }: -let - cfg = config.container.module.print; - name = "print"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.print; + name = "print"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; - proxy_pass http://''$${name}$request_uri; + proxy_pass http://''$${name}$request_uri; - proxy_set_header Host "127.0.0.1"; - proxy_set_header X-Real-IP $remote_addr; - proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; - } + proxy_set_header Host "127.0.0.1"; + proxy_set_header X-Real-IP $remote_addr; + proxy_set_header X-Forward-For $proxy_add_x_forwarded_for; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Printer.nix b/container/proxy/host/Printer.nix index 56d2e04..8661fc7 100644 --- a/container/proxy/host/Printer.nix +++ b/container/proxy/host/Printer.nix @@ -1,29 +1,32 @@ -{ container, config, ... }: -let - address = "192.168.2.237"; - domain = "printer.${config.container.domain}"; - port = 80; - name = "printer"; -in { - ${domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${address}:${toString port}; + container, + config, + util, + ... +}: let + address = "192.168.2.237"; + domain = "printer.${config.container.domain}"; + name = "printer"; + port = 80; +in { + ${domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${address}:${toString port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Read.nix b/container/proxy/host/Read.nix index ff18c43..a7dca67 100644 --- a/container/proxy/host/Read.nix +++ b/container/proxy/host/Read.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.read; - name = "read"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.read; + name = "read"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Resume.nix b/container/proxy/host/Resume.nix index b6035c9..0229df0 100644 --- a/container/proxy/host/Resume.nix +++ b/container/proxy/host/Resume.nix @@ -1,24 +1,26 @@ -{ container, config, ... }: -let - domain = "resume.${config.container.domain}"; - name = "resume"; -in { - ${domain} = container.mkServer { - extraConfig = '' - server_name ${domain}; - listen 443 ssl; + container, + config, + util, + ... +}: let + domain = "resume.${config.container.domain}"; +in { + ${domain} = container.mkServer { + extraConfig = util.trimTabs '' + server_name ${domain}; + listen 443 ssl; - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - if ($http_accept_language ~ ru) { - return 301 https://${config.container.module.git.domain}/voronind/resume/releases/download/latest/VoronindRu.pdf; - } + if ($http_accept_language ~ ru) { + return 301 https://${config.container.module.git.domain}/voronind/resume/releases/download/latest/VoronindRu.pdf; + } - return 301 https://${config.container.module.git.domain}/voronind/resume/releases/download/latest/VoronindEn.pdf; - ''; - }; + return 301 https://${config.container.module.git.domain}/voronind/resume/releases/download/latest/VoronindEn.pdf; + ''; + }; } diff --git a/container/proxy/host/Router.nix b/container/proxy/host/Router.nix index 83e16e4..db1df5e 100644 --- a/container/proxy/host/Router.nix +++ b/container/proxy/host/Router.nix @@ -1,29 +1,32 @@ -{ container, config, ... }: -let - address = "10.0.0.2"; - domain = "router.${config.container.domain}"; - port = 80; - name = "router"; -in { - ${domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${address}:${toString port}; + container, + config, + util, + ... +}: let + address = "10.0.0.2"; + domain = "router.${config.container.domain}"; + name = "router"; + port = 80; +in { + ${domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${address}:${toString port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Search.nix b/container/proxy/host/Search.nix index a6fb137..c5afc3b 100644 --- a/container/proxy/host/Search.nix +++ b/container/proxy/host/Search.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.search; - name = "search"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.search; + name = "search"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Status.nix b/container/proxy/host/Status.nix index a4a0d6f..bf53f3d 100644 --- a/container/proxy/host/Status.nix +++ b/container/proxy/host/Status.nix @@ -1,34 +1,37 @@ -{ container, config, ... }: -let - cfg = config.container.module.status; - name = "sstatus"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.status; + name = "sstatus"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location ~ ^/(dashboard|settings) { - allow ${config.container.localAccess}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location ~ ^/(dashboard|settings) { + allow ${config.container.localAccess}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Stock.nix b/container/proxy/host/Stock.nix index 0151865..3d6cf9f 100644 --- a/container/proxy/host/Stock.nix +++ b/container/proxy/host/Stock.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.stock; - name = "stock"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.stock; + name = "stock"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Watch.nix b/container/proxy/host/Watch.nix index fd1e36d..6ca2e8a 100644 --- a/container/proxy/host/Watch.nix +++ b/container/proxy/host/Watch.nix @@ -1,27 +1,30 @@ -{ container, config, ... }: -let - cfg = config.container.module.watch; - name = "watch"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.watch; + name = "watch"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; - proxy_pass http://''$${name}$request_uri; - } + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; + proxy_pass http://''$${name}$request_uri; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/container/proxy/host/Yt.nix b/container/proxy/host/Yt.nix index be119a0..aea0ce5 100644 --- a/container/proxy/host/Yt.nix +++ b/container/proxy/host/Yt.nix @@ -1,37 +1,40 @@ -{ container, config, ... }: -let - cfg = config.container.module.yt; - name = "yt"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; + container, + config, + util, + ... +}: let + cfg = config.container.module.yt; + name = "yt"; +in { + ${cfg.domain} = container.mkServer { + extraConfig = util.trimTabs '' + listen 443 ssl; + set ''$${name} ${cfg.address}:${toString cfg.port}; - location / { - allow ${config.container.localAccess}; - allow ${config.container.module.status.address}; - allow ${config.container.module.vpn.address}; - allow ${config.container.module.frkn.address}; - deny all; + location / { + allow ${config.container.localAccess}; + allow ${config.container.module.status.address}; + allow ${config.container.module.vpn.address}; + allow ${config.container.module.frkn.address}; + deny all; - proxy_pass http://''$${name}$request_uri; + proxy_pass http://''$${name}$request_uri; - proxy_set_header X-Forwarded-For $remote_addr; - proxy_set_header Host $host; - proxy_http_version 1.1; - proxy_set_header Connection ""; + proxy_set_header X-Forwarded-For $remote_addr; + proxy_set_header Host $host; + proxy_http_version 1.1; + proxy_set_header Connection ""; - proxy_hide_header Content-Security-Policy; - proxy_hide_header X-Frame-Options; - proxy_hide_header X-Content-Type-Options; - } + proxy_hide_header Content-Security-Policy; + proxy_hide_header X-Frame-Options; + proxy_hide_header X-Content-Type-Options; + } - ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; - ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; - include /etc/letsencrypt/conf/options-ssl-nginx.conf; - ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; - ''; - }; + ssl_certificate /etc/letsencrypt/live/${config.container.domain}/fullchain.pem; + ssl_certificate_key /etc/letsencrypt/live/${config.container.domain}/privkey.pem; + include /etc/letsencrypt/conf/options-ssl-nginx.conf; + ssl_dhparam /etc/letsencrypt/conf/ssl-dhparams.pem; + ''; + }; } diff --git a/flake.nix b/flake.nix index 23390d6..c761cc9 100644 --- a/flake.nix +++ b/flake.nix @@ -1,375 +1,163 @@ -# This is a configuration entry-point called "Flake". -# Here you define your inputs (dependencies) and outputs (hosts). { - # Those are external dependencies. - inputs = { - # Core system. - # Homepage: https://github.com/NixOS/nixpkgs - # Manual: https://nixos.org/manual/nixos/stable - # Search: https://search.nixos.org/packages and https://search.nixos.org/options - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - nixpkgsUnstable.url = "github:nixos/nixpkgs/nixos-unstable"; - nixpkgsStable.url = "github:nixos/nixpkgs/nixos-24.05"; - nixpkgsMaster.url = "github:nixos/nixpkgs/master"; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + nixpkgsUnstable.url = "github:nixos/nixpkgs/nixos-unstable"; + nixpkgsStable.url = "github:nixos/nixpkgs/nixos-24.05"; + nixpkgsMaster.url = "github:nixos/nixpkgs/master"; - # This thing manages user's /home directroies. Because NixOS only manages system itself. - # Homepage: https://github.com/nix-community/home-manager - # Manual: https://nix-community.github.io/home-manager - # Search: https://home-manager-options.extranix.com - home-manager = { - url = "github:nix-community/home-manager"; + home-manager = { + url = "github:nix-community/home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; - # This means that home-manager and our Flake both depend on the same nixpkgs version. - inputs.nixpkgs.follows = "nixpkgs"; - }; + stylix.url = "github:danth/stylix"; - # This allows automatic styling based on active Wallpaper. - # Homepage: https://github.com/danth/stylix - # Manual: https://danth.github.io/stylix - stylix.url = "github:danth/stylix"; + nixpkgsJobber.url = "github:nixos/nixpkgs/051f920625ab5aabe37c920346e3e69d7d34400e"; + poetry2nixJobber.url = "github:nix-community/poetry2nix/304f8235fb0729fd48567af34fcd1b58d18f9b95"; - # I use this for a single container called jobber. WARN: Do not update. - # You likely won't need this one, so just skip it for now. - poetry2nixJobber.url = "github:nix-community/poetry2nix/304f8235fb0729fd48567af34fcd1b58d18f9b95"; - nixpkgsJobber.url = "github:nixos/nixpkgs/051f920625ab5aabe37c920346e3e69d7d34400e"; + nix-on-droid = { + url = "github:t184256/nix-on-droid/release-23.11"; + inputs.home-manager.follows = "home-manager"; + inputs.nixpkgs.follows = "nixpkgs"; + }; - # Nix on Android (inside Termux). It has no NixOS modules, but still allows the use of Nixpkgs arm packages with Home-Manager configurations. - # Homepage: https://github.com/nix-community/nix-on-droid - # Manual: https://github.com/nix-community/nix-on-droid/blob/master/README.md - nix-on-droid = { - url = "github:t184256/nix-on-droid/release-23.11"; - inputs.nixpkgs.follows = "nixpkgs"; - inputs.home-manager.follows = "home-manager"; - }; + nvimAlign = { flake = false; url = "github:echasnovski/mini.align"; }; + nvimAutoclose = { flake = false; url = "github:m4xshen/autoclose.nvim"; }; + nvimBufferline = { flake = false; url = "github:akinsho/bufferline.nvim"; }; + nvimCloseBuffers = { flake = false; url = "github:kazhala/close-buffers.nvim"; }; + nvimColorizer = { flake = false; url = "github:brenoprata10/nvim-highlight-colors"; }; + nvimDevicons = { flake = false; url = "github:nvim-tree/nvim-web-devicons"; }; + nvimDressing = { flake = false; url = "github:stevearc/dressing.nvim"; }; + nvimGen = { flake = false; url = "github:David-Kunz/gen.nvim"; }; + nvimGitsigns = { flake = false; url = "github:lewis6991/gitsigns.nvim"; }; + nvimGruvboxMaterial = { flake = false; url = "github:sainnhe/gruvbox-material"; }; + nvimIndentoMatic = { flake = false; url = "github:Darazaki/indent-o-matic"; }; + nvimLspconfig = { flake = false; url = "github:neovim/nvim-lspconfig"; }; + nvimPlenary = { flake = false; url = "github:nvim-lua/plenary.nvim"; }; + nvimTelescope = { flake = false; url = "github:nvim-telescope/telescope.nvim"; }; + nvimTodo = { flake = false; url = "github:folke/todo-comments.nvim"; }; + nvimTree = { flake = false; url = "github:nvim-tree/nvim-tree.lua"; }; + nvimTreesitter = { flake = false; url = "github:nvim-treesitter/nvim-treesitter"; }; + nvimTrouble = { flake = false; url = "github:folke/trouble.nvim"; }; + }; - # Those are Nvim plugins. I do not use package managers like Packer or Lazy, instead I use Nix to download them and later configure in [Neovim module](module/common/Nvim.nix). - nvimAlign = { - url = "github:echasnovski/mini.align"; - flake = false; - }; - nvimAutoclose = { - url = "github:m4xshen/autoclose.nvim"; - flake = false; - }; - nvimBufferline = { - url = "github:akinsho/bufferline.nvim"; - flake = false; - }; - nvimCloseBuffers = { - url = "github:kazhala/close-buffers.nvim"; - flake = false; - }; - nvimColorizer = { - url = "github:brenoprata10/nvim-highlight-colors"; - flake = false; - }; - nvimDevicons = { - url = "github:nvim-tree/nvim-web-devicons"; - flake = false; - }; - nvimDressing = { - url = "github:stevearc/dressing.nvim"; - flake = false; - }; - nvimGen = { - url = "github:David-Kunz/gen.nvim"; - flake = false; - }; - nvimGitsigns = { - url = "github:lewis6991/gitsigns.nvim"; - flake = false; - }; - nvimGruvboxMaterial = { - url = "github:sainnhe/gruvbox-material"; - flake = false; - }; - nvimIndentoMatic = { - url = "github:Darazaki/indent-o-matic"; - flake = false; - }; - nvimLspconfig = { - url = "github:neovim/nvim-lspconfig"; - flake = false; - }; - nvimPlenary = { - url = "github:nvim-lua/plenary.nvim"; - flake = false; - }; - nvimTelescope = { - url = "github:nvim-telescope/telescope.nvim"; - flake = false; - }; - nvimTodo = { - url = "github:folke/todo-comments.nvim"; - flake = false; - }; - nvimTree = { - url = "github:nvim-tree/nvim-tree.lua"; - flake = false; - }; - nvimTreesitter = { - url = "github:nvim-treesitter/nvim-treesitter"; - flake = false; - }; - nvimTrouble = { - url = "github:folke/trouble.nvim"; - flake = false; - }; - }; + outputs = { + home-manager, + nix-on-droid, + nixpkgs, + nixpkgsJobber, + nixpkgsMaster, + nixpkgsStable, + nixpkgsUnstable, + poetry2nixJobber, + self, + stylix, + ... + } @inputs: { + const = { + droidStateVersion = "23.11"; + stateVersion = "24.05"; + timeZone = "Europe/Moscow"; + url = "https://git.voronind.com/voronind/nix.git"; + }; - # Those are outputs (hosts, configurations) that can be produced by this whole config. - # Here you see a set of inputs we defined above, like nixpkgs, home-manager and so on. - # `...` at the end of a set means "ignore other arguments provided to this function". - # @inputs means aliasing all the inputs to the `inputs` name, so we can pass them all at once later. - outputs = - { - self, - nixpkgs, - nixpkgsUnstable, - nixpkgsStable, - nixpkgsMaster, - nix-on-droid, - home-manager, - stylix, - poetry2nixJobber, - nixpkgsJobber, - ... - }@inputs: - { - # Constant values. - const = { - droidStateVersion = "23.11"; - stateVersion = "24.05"; - timeZone = "Europe/Moscow"; - url = "https://git.voronind.com/voronind/nix.git"; - }; + __findFile = _: p: ./${p}; - # Hack to use in other files. - # Need to add __findFile to args tho. - __findFile = _: p: ./${p}; + findFiles = path: map (f: "${path}/${f}") ( + builtins.filter (i: builtins.readFileType "${path}/${i}" == "regular") ( + builtins.attrNames (builtins.readDir path) + ) + ); - # List all files in a dir. - findFiles = - path: - map (f: "${path}/${f}") ( - builtins.filter (i: builtins.readFileType "${path}/${i}" == "regular") ( - builtins.attrNames (builtins.readDir path) - ) - ); + devShells = let + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}; + system = "x86_64-linux"; + in { + ${system}.default = pkgs.mkShell { + nativeBuildInputs = with pkgs; [ + nixd + ]; + # buildInputs = with pkgs; [ ]; - # Dev shell for this repo. - devShells = - let - system = "x86_64-linux"; - lib = nixpkgs.lib; - pkgs = nixpkgs.legacyPackages.${system}; - in - { - ${system}.default = pkgs.mkShell { - nativeBuildInputs = with pkgs; [ - nixd - nixfmt-rfc-style - treefmt - ]; - # buildInputs = with pkgs; [ ]; + # LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; + # SOURCE_DATE_EPOCH = "${toString self.lastModified}"; + }; + }; - # LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; - # SOURCE_DATE_EPOCH = "${toString self.lastModified}"; - }; - }; + nixosConfigurations = let + mkHost = { system, hostname }: nixpkgs.lib.nixosSystem { + inherit system; + modules = [ + # Make a device hostname match the one from this config. + { networking.hostName = hostname; } - # Nixos systems. - nixosConfigurations = - let - # Function to create a host. It does basic setup, like adding common modules. - mkHost = - { system, hostname }: - nixpkgs.lib.nixosSystem { - # `Inherit` is just an alias for `system = system;`, which means that - # keep the `system` argument as a property in a resulting set. - inherit system; + # Specify current release version. + { system.stateVersion = self.const.stateVersion; } - # List of modules to use by defualt for all the hosts. - modules = - [ - # Make a device hostname match the one from this config. - { networking.hostName = hostname; } + # Add Home Manager module. + home-manager.nixosModules.home-manager - # Specify current release version. - { system.stateVersion = self.const.stateVersion; } + # Add Stylix module. + stylix.nixosModules.stylix - # Add Home Manager module. - home-manager.nixosModules.home-manager + # HM config. + ./home/NixOs.nix + ] + ++ (self.findFiles ./container) + ++ (self.findFiles ./host/${system}/${hostname}) + ++ (self.findFiles ./module) + ++ (self.findFiles ./overlay) + ++ (self.findFiles ./system) + ; + specialArgs = let + pkgs = nixpkgs.legacyPackages.${system}.pkgs; + lib = nixpkgs.lib; + config = self.nixosConfigurations.${hostname}.config; + util = import ./lib/Util.nix { inherit lib; }; + in { + inherit (self) const __findFile; + inherit inputs self poetry2nixJobber util; + container = import ./lib/Container.nix { inherit lib pkgs config util; inherit (self) const; }; + pkgsJobber = nixpkgsJobber.legacyPackages.${system}.pkgs; + pkgsMaster = nixpkgsMaster.legacyPackages.${system}.pkgs; + pkgsStable = nixpkgsStable.legacyPackages.${system}.pkgs; + pkgsUnstable = nixpkgsUnstable.legacyPackages.${system}.pkgs; + secret = import ./secret { }; + }; + }; - # Add Stylix module. - stylix.nixosModules.stylix + mkSystem = system: hostname: { "${hostname}" = mkHost { inherit system hostname; }; }; + in nixpkgs.lib.foldl' (acc: h: acc // h) { } ( + map (system: nixpkgs.lib.foldl' (acc: h: acc // h) { } ( + map (host: mkSystem system host) (builtins.attrNames (builtins.readDir ./host/${system})) + )) (builtins.attrNames (builtins.readDir ./host)) + ); - # HM config. - ./home/NixOs.nix - ] - ++ (self.findFiles ./host/${system}/${hostname}) - ++ (self.findFiles ./config) - ++ (self.findFiles ./container) - ++ (self.findFiles ./module) - ++ (self.findFiles ./system) - ++ (self.findFiles ./overlay); - - # SpecialArgs allows you to pass objects down to other NixOS modules. - specialArgs = - let - pkgs = nixpkgs.legacyPackages.${system}.pkgs; - lib = nixpkgs.lib; - config = self.nixosConfigurations.${hostname}.config; - in - { - inherit inputs self; - inherit (self) const __findFile; - - pkgsJobber = nixpkgsJobber.legacyPackages.${system}.pkgs; - pkgsStable = nixpkgsStable.legacyPackages.${system}.pkgs; - pkgsUnstable = nixpkgsUnstable.legacyPackages.${system}.pkgs; - pkgsMaster = nixpkgsMaster.legacyPackages.${system}.pkgs; - - secret = import ./secret { }; # Secrets (public keys). - container = import ./lib/Container.nix { - inherit lib pkgs config; - inherit (self) const; - }; # Container utils. - util = import ./lib/Util.nix { inherit lib; }; # Util functions. - - # Stuff for Jobber container, skip this part. - inherit poetry2nixJobber; - }; - }; - - mkSystem = system: hostname: { "${hostname}" = mkHost { inherit system hostname; }; }; - in - nixpkgs.lib.foldl' (acc: h: acc // h) { } ( - map ( - system: - nixpkgs.lib.foldl' (acc: h: acc // h) { } ( - map (host: mkSystem system host) (builtins.attrNames (builtins.readDir ./host/${system})) - ) - ) (builtins.attrNames (builtins.readDir ./host)) - ); - - # Home manager (distro-independent). - # Install nix: sh <(curl -L https://nixos.org/nix/install) --no-daemon - # Or with --daemon for multi-user (as root). - # $ nix run home-manager/master -- init --switch - # $ nix shell '' -A install - # Add to /etc/nix/nix.conf > experimental-features = nix-command flakes - # And then # systemctl restart nix-daemon.service - # $ home-manager switch --flake ~/hmconf - homeConfigurations = - let - lib = nixpkgs.lib; - secret = import ./secret { }; - util = import ./lib/Util.nix { inherit lib; }; - - mkCommonHome = - username: system: - let - pkgs = nixpkgs.legacyPackages.${system}; - pkgsStable = nixpkgsStable.legacyPackages.${system}; - pkgsUnstable = nixpkgsUnstable.legacyPackages.${system}; - pkgsMaster = nixpkgsMaster.legacyPackages.${system}; - in - { - ${username} = home-manager.lib.homeManagerConfiguration { - inherit pkgs; - - extraSpecialArgs = { - inherit - self - inputs - secret - util - pkgs - pkgsStable - pkgsMaster - ; - inherit (self) const __findFile; - }; - modules = [ - ./home/HomeManager.nix - { - home.hm = { - inherit username; - enable = true; - }; - } - - { nixpkgs.config.allowUnfree = true; } - { nixpkgs.config.allowUnfreePredicate = (pkg: true); } - { nix.package = pkgs.nix; } - { - nix.settings.experimental-features = [ - "nix-command " - "flakes" - ]; - } - - inputs.stylix.homeManagerModules.stylix - ] ++ (self.findFiles ./home/user/${system}/${username}) ++ (self.findFiles ./config); - }; - }; - in - nixpkgs.lib.foldl' (acc: h: acc // h) { } ( - map ( - system: - nixpkgs.lib.foldl' (acc: h: acc // h) { } ( - map (username: mkCommonHome username system) ( - builtins.attrNames (builtins.readDir ./home/user/${system}) - ) - ) - ) (builtins.attrNames (builtins.readDir ./home/user)) - ); - - # Android. - nixOnDroidConfigurations.default = - let - system = "aarch64-linux"; - config = self.nixOnDroidConfigurations.default.config; - lib = nixpkgs.lib; - pkgs = nixpkgs.legacyPackages.${system}.pkgs; - pkgsStable = nixpkgsStable.legacyPackages.${system}.pkgs; - pkgsUnstable = nixpkgsUnstable.legacyPackages.${system}.pkgs; - pkgsMaster = nixpkgsMaster.legacyPackages.${system}.pkgs; - in - nix-on-droid.lib.nixOnDroidConfiguration { - modules = [ - # Android release version. - { system.stateVersion = self.const.droidStateVersion; } - - # I put all my Android configuration there. - ./home/Android.nix - { home.android.enable = true; } - - # { nixpkgs.config.allowUnfree = true; } - # { nixpkgs.config.allowUnfreePredicate = (pkg: true); } - { nix.extraOptions = "experimental-features = nix-command flakes"; } - { home-manager.config.stylix.autoEnable = lib.mkForce false; } - - # Some common modules. - ./config/Setting.nix - ./config/Wallpaper.nix - (import ./config/Style.nix { - inherit (config.home-manager) config; - inherit (self) __findFile; - inherit lib pkgs; - }) - ]; - - # SpecialArgs allows you to pass objects down to other configuration. - extraSpecialArgs = { - inherit inputs self; - inherit (self) const __findFile; - - secret = import ./secret { }; # Secrets (public keys). - util = import ./lib/Util.nix { inherit lib; }; # Util functions. - }; - }; - }; + nixOnDroidConfigurations.default = let + config = self.nixOnDroidConfigurations.default.config; + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}.pkgs; + pkgsMaster = nixpkgsMaster.legacyPackages.${system}.pkgs; + pkgsStable = nixpkgsStable.legacyPackages.${system}.pkgs; + pkgsUnstable = nixpkgsUnstable.legacyPackages.${system}.pkgs; + system = "aarch64-linux"; + in nix-on-droid.lib.nixOnDroidConfiguration { + modules = [ + (import ./module/Style.nix { inherit (config.home-manager) config; inherit (self) __findFile; inherit lib pkgs; }) + ./home/Android.nix + ./module/Wallpaper.nix + { home-manager.config.stylix.autoEnable = lib.mkForce false; } + { home.android.enable = true; } + { nix.extraOptions = "experimental-features = nix-command flakes"; } + { system.stateVersion = self.const.droidStateVersion; } + ]; + extraSpecialArgs = { + inherit inputs self; + inherit (self) const __findFile; + secret = import ./secret { }; + util = import ./lib/Util.nix { inherit lib; }; + }; + }; + }; } -# That's it! diff --git a/home/Android.nix b/home/Android.nix index d813b2d..548a100 100644 --- a/home/Android.nix +++ b/home/Android.nix @@ -1,48 +1,42 @@ # This is a common user configuration. { - const, - pkgs, - self, - config, - lib, - inputs, - pkgsStable, - pkgsMaster, - __findFile, - ... -}@args: -with lib; -let - cfg = config.home.android; - stylix = import args; - android = import ./android args; - package = import args; - programs = import ./program args; -in -# homePath = "/data/data/com.termux.nix/files/home"; -{ - options = { - home.android = { - enable = mkEnableOption "Android HM config."; - }; - }; + __findFile, + config, + const, + inputs, + lib, + pkgs, + pkgsMaster, + pkgsStable, + self, + ... +} @args: let + cfg = config.home.android; + android = import ./android args; + package = import args; + programs = import ./program args; + stylix = import args; +in { + options.home.android = { + enable = lib.mkEnableOption "the Android HM config."; + }; - config = mkIf cfg.enable { - environment.packages = package.core; - time.timeZone = const.timeZone; - - terminal = { - inherit (android) font colors; - }; - - home-manager.config = stylix // { - imports = [ inputs.stylix.homeManagerModules.stylix ]; - home = { - file = import ./config args; - sessionVariables = import ./variable args; - stateVersion = const.droidStateVersion; - }; - programs = with programs; core; - }; - }; + config = lib.mkIf cfg.enable { + environment.packages = package.core; + time.timeZone = const.timeZone; + terminal = { + inherit (android) font colors; + }; + home-manager.config = stylix // { + programs = with programs; core; + imports = [ + inputs.stylix.homeManagerModules.stylix + ]; + home = { + file = import ./config args; + sessionVariables = import ./variable args; + stateVersion = const.droidStateVersion; + }; + }; + }; } diff --git a/home/HomeManager.nix b/home/HomeManager.nix deleted file mode 100644 index c65a3b1..0000000 --- a/home/HomeManager.nix +++ /dev/null @@ -1,70 +0,0 @@ -# This is a common user configuration. -{ - const, - util, - config, - lib, - __findFile, - ... -}@args: -with lib; -let - cfg = config.home.hm; - package = import args; - programs = import ./program args; -in -{ - options = { - home.hm = { - enable = mkEnableOption "Home-Manager standalone config."; - username = mkOption { - default = null; - type = types.str; - }; - homeDirectory = mkOption { - default = "/home/${cfg.username}"; - type = types.str; - }; - package = mkOption { - default = { }; - type = types.submodule { - options = { - common.enable = mkEnableOption "Common apps."; - core.enable = mkEnableOption "Core apps."; - creative.enable = mkEnableOption "Creative apps."; - desktop.enable = mkEnableOption "Desktop apps."; - dev.enable = mkEnableOption "Dev apps."; - extra.enable = mkEnableOption "Extra apps."; - gaming.enable = mkEnableOption "Gaming apps."; - }; - }; - }; - }; - }; - - config = mkIf cfg.enable (mkMerge [ - { - home = { - inherit (cfg) username homeDirectory; - inherit (const) stateVersion; - file = import ./config args; - sessionVariables = import ./variable args; - }; - xdg = import ./xdg { inherit (cfg) homeDirectory; }; - programs = with programs; core; - dconf.settings = util.catSet (util.ls ./config/dconf) args; - } - (mkIf cfg.package.common.enable { home.packages = package.common; }) - (mkIf cfg.package.core.enable { home.packages = package.core; }) - (mkIf cfg.package.creative.enable { home.packages = package.creative; }) - (mkIf cfg.package.desktop.enable { - home = { - packages = package.desktop; - programs = programs.desktop; - }; - }) - (mkIf cfg.package.dev.enable { home.packages = package.dev; }) - (mkIf cfg.package.extra.enable { home.packages = package.extra; }) - (mkIf cfg.package.gaming.enable { home.packages = package.gaming; }) - ]); -} diff --git a/home/NixOs.nix b/home/NixOs.nix index 733e5b6..f963f3c 100644 --- a/home/NixOs.nix +++ b/home/NixOs.nix @@ -1,57 +1,47 @@ # This is a common user configuration. { - const, - config, - util, - lib, - pkgs, - __findFile, - ... -}@args: -with lib; -let - cfg = config.home.nixos; - programs = import ./program args; -in -{ - imports = (util.ls ); + __findFile, + config, + const, + lib, + pkgs, + util, + ... +} @args: let + cfg = config.home.nixos; + programs = import ./program args; +in { + imports = (util.ls ); - options = { - home.nixos = { - enable = mkEnableOption "NixOS user setup."; - users = mkOption { - default = [ ]; - type = types.listOf types.attrs; - }; - }; - }; + options.home.nixos = { + enable = lib.mkEnableOption "the NixOS user setup."; + users = lib.mkOption { + default = [ ]; + type = with lib.types; listOf attrs; + }; + }; - config = mkIf cfg.enable { - home-manager = { - users = builtins.foldl' ( - acc: user: - acc - // { - ${user.username} = { - home = { - inherit (const) stateVersion; - inherit (user) username homeDirectory; - file = import ./config args; - sessionVariables = import ./variable args; + config = lib.mkIf cfg.enable { + home-manager = { + backupFileExtension = "backup-" + pkgs.lib.readFile "${pkgs.runCommand "timestamp" { } "echo -n date '+%Y%m%d%H%M%S' > $out"}"; + users = builtins.foldl' (acc: user: + acc // { + ${user.username} = { + home = { + inherit (const) stateVersion; + inherit (user) username homeDirectory; + file = import ./config args; + sessionVariables = import ./variable args; - # ISSUE: https://github.com/nix-community/home-manager/issues/5589 - extraActivationPath = with pkgs; [ openssh ]; - }; - xdg = import ./xdg { inherit (user) homeDirectory; }; - programs = with programs; core // desktop; - dconf.settings = util.catSet (util.ls ./config/dconf) args; - }; - } - ) { } cfg.users; - - backupFileExtension = - "backup-" - + pkgs.lib.readFile "${pkgs.runCommand "timestamp" { } "echo -n date '+%Y%m%d%H%M%S' > $out"}"; - }; - }; + # ISSUE: https://github.com/nix-community/home-manager/issues/5589 + extraActivationPath = with pkgs; [ openssh ]; + }; + xdg = import ./xdg { inherit (user) homeDirectory; }; + programs = with programs; core // desktop; + dconf.settings = util.catSet (util.ls ./config/dconf) args; + }; + } + ) { } cfg.users; + }; + }; } diff --git a/home/android/default.nix b/home/android/default.nix index 8379cfc..729b8bc 100644 --- a/home/android/default.nix +++ b/home/android/default.nix @@ -1,14 +1,15 @@ -{ pkgs, config, ... }: { - font = pkgs.runCommandNoCC "font" { } '' - cp ${ - pkgs.nerdfonts.override { fonts = [ "Terminus" ]; } - }/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out - ''; + config, + pkgs, + ... +}: { + font = pkgs.runCommandNoCC "font" { } '' + cp ${pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }}/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out + ''; - colors = with config.style.color; { - background = "#${bg.dark}"; - cursor = "#${fg.light}"; - foreground = "#${fg.light}"; - }; + colors = with config.module.style.color; { + background = "#${bg.dark}"; + cursor = "#${fg.light}"; + foreground = "#${fg.light}"; + }; } diff --git a/home/config/btop/default.nix b/home/config/btop/default.nix index 1385fc0..bacb9ba 100644 --- a/home/config/btop/default.nix +++ b/home/config/btop/default.nix @@ -1,250 +1,100 @@ -{ ... }: { - text = '' - #? Config file for btop v. 1.3.0 - - #* Name of a btop++/bpytop/bashtop formatted ".theme" file, "Default" and "TTY" for builtin themes. - #* Themes should be placed in "../share/btop/themes" relative to binary or "$HOME/.config/btop/themes" - color_theme = "/usr/share/btop/themes/gruvbox_material_dark.theme" - - #* If the theme set background should be shown, set to False if you want terminal background transparency. - theme_background = False - - #* Sets if 24-bit truecolor should be used, will convert 24-bit colors to 256 color (6x6x6 color cube) if false. - truecolor = True - - #* Set to true to force tty mode regardless if a real tty has been detected or not. - #* Will force 16-color mode and TTY theme, set all graph symbols to "tty" and swap out other non tty friendly symbols. - force_tty = False - - #* Define presets for the layout of the boxes. Preset 0 is always all boxes shown with default settings. Max 9 presets. - #* Format: "box_name:P:G,box_name:P:G" P=(0 or 1) for alternate positions, G=graph symbol to use for box. - #* Use whitespace " " as separator between different presets. - #* Example: "cpu:0:default,mem:0:tty,proc:1:default cpu:0:braille,proc:0:tty" - presets = "" - - #* Set to True to enable "h,j,k,l,g,G" keys for directional control in lists. - #* Conflicting keys for h:"help" and k:"kill" is accessible while holding shift. - vim_keys = True - - #* Rounded corners on boxes, is ignored if TTY mode is ON. - rounded_corners = True - - #* Default symbols to use for graph creation, "braille", "block" or "tty". - #* "braille" offers the highest resolution but might not be included in all fonts. - #* "block" has half the resolution of braille but uses more common characters. - #* "tty" uses only 3 different symbols but will work with most fonts and should work in a real TTY. - #* Note that "tty" only has half the horizontal resolution of the other two, so will show a shorter historical view. - graph_symbol = "braille" - - # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". - graph_symbol_cpu = "default" - - # Graph symbol to use for graphs in gpu box, "default", "braille", "block" or "tty". - graph_symbol_gpu = "default" - - # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". - graph_symbol_mem = "default" - - # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". - graph_symbol_net = "default" - - # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". - graph_symbol_proc = "default" - - #* Manually set which boxes to show. Available values are "cpu mem net proc" and "gpu0" through "gpu5", separate values with whitespace. - shown_boxes = "cpu mem net proc" - - #* Update time in milliseconds, recommended 2000 ms or above for better sample times for graphs. - update_ms = 2000 - - #* Processes sorting, "pid" "program" "arguments" "threads" "user" "memory" "cpu lazy" "cpu direct", - #* "cpu lazy" sorts top process over time (easier to follow), "cpu direct" updates top process directly. - proc_sorting = "memory" - - #* Reverse sorting order, True or False. - proc_reversed = False - - #* Show processes as a tree. - proc_tree = False - - #* Use the cpu graph colors in the process list. - proc_colors = True - - #* Use a darkening gradient in the process list. - proc_gradient = True - - #* If process cpu usage should be of the core it's running on or usage of the total available cpu power. - proc_per_core = False - - #* Show process memory as bytes instead of percent. - proc_mem_bytes = True - - #* Show cpu graph for each process. - proc_cpu_graphs = True - - #* Use /proc/[pid]/smaps for memory information in the process info box (very slow but more accurate) - proc_info_smaps = False - - #* Show proc box on left side of screen instead of right. - proc_left = True - - #* (Linux) Filter processes tied to the Linux kernel(similar behavior to htop). - proc_filter_kernel = True - - #* In tree-view, always accumulate child process resources in the parent process. - proc_aggregate = False - - #* Sets the CPU stat shown in upper half of the CPU graph, "total" is always available. - #* Select from a list of detected attributes from the options menu. - cpu_graph_upper = "total" - - #* Sets the CPU stat shown in lower half of the CPU graph, "total" is always available. - #* Select from a list of detected attributes from the options menu. - cpu_graph_lower = "total" - - #* If gpu info should be shown in the cpu box. Available values = "Auto", "On" and "Off". - show_gpu_info = "Auto" - - #* Toggles if the lower CPU graph should be inverted. - cpu_invert_lower = True - - #* Set to True to completely disable the lower CPU graph. - cpu_single_graph = False - - #* Show cpu box at bottom of screen instead of top. - cpu_bottom = False - - #* Shows the system uptime in the CPU box. - show_uptime = True - - #* Show cpu temperature. - check_temp = True - - #* Which sensor to use for cpu temperature, use options menu to select from list of available sensors. - cpu_sensor = "Auto" - - #* Show temperatures for cpu cores also if check_temp is True and sensors has been found. - show_coretemp = True - - #* Set a custom mapping between core and coretemp, can be needed on certain cpus to get correct temperature for correct core. - #* Use lm-sensors or similar to see which cores are reporting temperatures on your machine. - #* Format "x:y" x=core with wrong temp, y=core with correct temp, use space as separator between multiple entries. - #* Example: "4:0 5:1 6:3" - cpu_core_map = "" - - #* Which temperature scale to use, available values: "celsius", "fahrenheit", "kelvin" and "rankine". - temp_scale = "celsius" - - #* Use base 10 for bits/bytes sizes, KB = 1000 instead of KiB = 1024. - base_10_sizes = True - - #* Show CPU frequency. - show_cpu_freq = True - - #* Draw a clock at top of screen, formatting according to strftime, empty string to disable. - #* Special formatting: /host = hostname | /user = username | /uptime = system uptime - clock_format = "%X" - - #* Update main ui in background when menus are showing, set this to false if the menus is flickering too much for comfort. - background_update = True - - #* Custom cpu model name, empty string to disable. - custom_cpu_name = "" - - #* Optional filter for shown disks, should be full path of a mountpoint, separate multiple values with whitespace " ". - #* Begin line with "exclude=" to change to exclude filter, otherwise defaults to "most include" filter. Example: disks_filter="exclude=/boot /home/user". - disks_filter = "exclude=/boot /boot/efi" - - #* Show graphs instead of meters for memory values. - mem_graphs = True - - #* Show mem box below net box instead of above. - mem_below_net = False - - #* Count ZFS ARC in cached and available memory. - zfs_arc_cached = True - - #* If swap memory should be shown in memory box. - show_swap = True - - #* Show swap as a disk, ignores show_swap value above, inserts itself after first disk. - swap_disk = False - - #* If mem box should be split to also show disks info. - show_disks = True - - #* Filter out non physical disks. Set this to False to include network disks, RAM disks and similar. - only_physical = True - - #* Read disks list from /etc/fstab. This also disables only_physical. - use_fstab = True - - #* Setting this to True will hide all datasets, and only show ZFS pools. (IO stats will be calculated per-pool) - zfs_hide_datasets = False - - #* Set to true to show available disk space for privileged users. - disk_free_priv = False - - #* Toggles if io activity % (disk busy time) should be shown in regular disk usage view. - show_io_stat = True - - #* Toggles io mode for disks, showing big graphs for disk read/write speeds. - io_mode = False - - #* Set to True to show combined read/write io graphs in io mode. - io_graph_combined = False - - #* Set the top speed for the io graphs in MiB/s (100 by default), use format "mountpoint:speed" separate disks with whitespace " ". - #* Example: "/mnt/media:100 /:20 /boot:1". - io_graph_speeds = "" - - #* Set fixed values for network graphs in Mebibits. Is only used if net_auto is also set to False. - net_download = 100 - - net_upload = 100 - - #* Use network graphs auto rescaling mode, ignores any values set above and rescales down to 10 Kibibytes at the lowest. - net_auto = True - - #* Sync the auto scaling for download and upload to whichever currently has the highest scale. - net_sync = True - - #* Starts with the Network Interface specified here. - net_iface = "" - - #* Show battery stats in top right if battery is present. - show_battery = True - - #* Which battery to use if multiple are present. "Auto" for auto detection. - selected_battery = "Auto" - - #* Set loglevel for "~/.config/btop/btop.log" levels are: "ERROR" "WARNING" "INFO" "DEBUG". - #* The level set includes all lower levels, i.e. "DEBUG" will show all logging info. - log_level = "WARNING" - - #* Measure PCIe throughput on NVIDIA cards, may impact performance on certain cards. - nvml_measure_pcie_speeds = True - - #* Horizontally mirror the GPU graph. - gpu_mirror_graph = True - - #* Custom gpu0 model name, empty string to disable. - custom_gpu_name0 = "" - - #* Custom gpu1 model name, empty string to disable. - custom_gpu_name1 = "" - - #* Custom gpu2 model name, empty string to disable. - custom_gpu_name2 = "" - - #* Custom gpu3 model name, empty string to disable. - custom_gpu_name3 = "" - - #* Custom gpu4 model name, empty string to disable. - custom_gpu_name4 = "" - - #* Custom gpu5 model name, empty string to disable. - custom_gpu_name5 = "" - ''; + pkgs, + lib, + ... +}: let + config = { + background_update = true; + base_10_sizes = true; + check_temp = true; + clock_format = "%X"; + color_theme = "/usr/share/btop/themes/gruvbox_material_dark.theme"; + cpu_bottom = false; + cpu_core_map = ""; + cpu_graph_lower = "total"; + cpu_graph_upper = "total"; + cpu_invert_lower = true; + cpu_sensor = "Auto"; + cpu_single_graph = false; + custom_cpu_name = ""; + custom_gpu_name0 = ""; + custom_gpu_name1 = ""; + custom_gpu_name2 = ""; + custom_gpu_name3 = ""; + custom_gpu_name4 = ""; + custom_gpu_name5 = ""; + disk_free_priv = false; + disks_filter = "exclude = /boot /boot/efi"; + force_tty = false; + gpu_mirror_graph = true; + graph_symbol = "braille"; + graph_symbol_cpu = "default"; + graph_symbol_gpu = "default"; + graph_symbol_mem = "default"; + graph_symbol_net = "default"; + graph_symbol_proc = "default"; + io_graph_combined = false; + io_graph_speeds = ""; + io_mode = false; + log_level = "WARNING"; + mem_below_net = false; + mem_graphs = true; + net_auto = true; + net_download = 100; + net_iface = ""; + net_sync = true; + net_upload = 100; + nvml_measure_pcie_speeds = true; + only_physical = true; + presets = ""; + proc_aggregate = true; + proc_colors = true; + proc_cpu_graphs = true; + proc_filter_kernel = true; + proc_gradient = false; + proc_info_smaps = false; + proc_left = true; + proc_mem_bytes = true; + proc_per_core = true; + proc_reversed = false; + proc_sorting = "memory"; + proc_tree = true; + rounded_corners = true; + selected_battery = "Auto"; + show_battery = true; + show_coretemp = true; + show_cpu_freq = true; + show_disks = true; + show_gpu_info = "Auto"; + show_io_stat = true; + show_swap = true; + show_uptime = true; + shown_boxes = "cpu mem net proc"; + swap_disk = false; + temp_scale = "celsius"; + theme_background = false; + truecolor = true; + update_ms = 2000; + use_fstab = true; + vim_keys = true; + zfs_arc_cached = true; + zfs_hide_datasets = false; + }; + + mkOption = k: v: lib.generators.mkKeyValueDefault { } " = " k v; +in { + file = pkgs.writeText "BtopConfig" ( + builtins.foldl' (acc: line: acc + "${line}\n") "" ( + lib.mapAttrsToList (k: v: let + value = if builtins.isString v then + "\"${v}\"" + else if builtins.isBool v then + if v then "True" else "False" + else + v + ; + in mkOption k value + ) config + ) + ); } diff --git a/home/config/chromium/default.nix b/home/config/chromium/default.nix index 4ae7646..2d89010 100644 --- a/home/config/chromium/default.nix +++ b/home/config/chromium/default.nix @@ -1,93 +1,98 @@ -{ pkgs, config, ... }: { - preferences = (pkgs.formats.json { }).generate "ChromiumConfig" { - bookmark_bar.show_on_all_tabs = false; - browser.show_home_button = false; - default_apps_install_state = 2; - default_search_provider = { - guid = "5761b040-db50-4f8e-9d00-c9ad985779a4"; - synced_guid = "5761b040-db50-4f8e-9d00-c9ad985779a4"; - }; - default_search_provider_data = { - template_url_data = { - id = 11; - is_active = 1; - keyword = "s"; - short_name = "SearX"; - synced_guid = "5761b040-db50-4f8e-9d00-c9ad985779a4"; - url = "https://search.voronind.com/search?q={searchTerms}"; - }; - }; - download.prompt_for_download = false; - download_bubble.partial_view_enabled = false; - extensions = { - alerts.initialized = false; - commands = { - "linux:Alt+Shift+L" = { - command_name = "addSite"; - extension = "eimadpbcbfnmbkopoojfekhnkhdbieeh"; - global = false; - }; - "linux:Alt+Shift+B" = { - command_name = "_execute_browser_action"; - extension = "cgbcahbpdhpcegmbfconppldiemgcoii"; - global = false; - }; - "linux:Alt+Shift+K" = { - command_name = "launch-element-zapper"; - extension = "cgbcahbpdhpcegmbfconppldiemgcoii"; - global = false; - }; - "linux:Alt+Shift+J" = { - command_name = "toggle-javascript"; - extension = "cgbcahbpdhpcegmbfconppldiemgcoii"; - global = false; - }; - "linux:Alt+Shift+P" = { - command_name = "_execute_action"; - extension = "gcknhkkoolaabfmlnjonogaaifnjlfnp"; - global = false; - }; - }; - }; - intl.selected_languages = "en-US,en"; - password_manager = { - autofillable_credentials_account_store_login_database = false; - autofillable_credentials_profile_store_login_database = false; - }; - name = "Work"; - session.restore_on_startup = 1; - side_panel.is_right_aligned = false; - webkit = { - webprefs = { - default_fixed_font_size = 14; - default_font_size = 17; - minimum_font_size = 16; - fonts = - let - mono = config.style.font.monospace.name; - sans = config.style.font.sansSerif.name; - in - { - fixed.Zyyy = mono; - sansserif.Zyyy = sans; - serif.Zyyy = sans; - standard.Zyyy = sans; - }; - }; - }; - }; + pkgs, + config, + ... +}: { + preferences = (pkgs.formats.json { }).generate "ChromiumConfig" { + name = "Work"; + bookmark_bar.show_on_all_tabs = false; + browser.show_home_button = false; + default_apps_install_state = 2; + download.prompt_for_download = false; + download_bubble.partial_view_enabled = false; + intl.selected_languages = "en-US,en"; + session.restore_on_startup = 1; + side_panel.is_right_aligned = false; + default_search_provider = { + guid = "5761b040-db50-4f8e-9d00-c9ad985779a4"; + synced_guid = "5761b040-db50-4f8e-9d00-c9ad985779a4"; + }; + default_search_provider_data = { + template_url_data = { + id = 11; + is_active = 1; + keyword = "s"; + short_name = "SearX"; + synced_guid = "5761b040-db50-4f8e-9d00-c9ad985779a4"; + url = "https://search.voronind.com/search?q={searchTerms}"; + }; + }; + extensions = { + alerts.initialized = false; + commands = { + "linux:Alt+Shift+L" = { + command_name = "addSite"; + extension = "eimadpbcbfnmbkopoojfekhnkhdbieeh"; + global = false; + }; + "linux:Alt+Shift+B" = { + command_name = "_execute_browser_action"; + extension = "cgbcahbpdhpcegmbfconppldiemgcoii"; + global = false; + }; + "linux:Alt+Shift+K" = { + command_name = "launch-element-zapper"; + extension = "cgbcahbpdhpcegmbfconppldiemgcoii"; + global = false; + }; + "linux:Alt+Shift+J" = { + command_name = "toggle-javascript"; + extension = "cgbcahbpdhpcegmbfconppldiemgcoii"; + global = false; + }; + "linux:Alt+Shift+P" = { + command_name = "_execute_action"; + extension = "gcknhkkoolaabfmlnjonogaaifnjlfnp"; + global = false; + }; + }; + }; + password_manager = { + autofillable_credentials_account_store_login_database = false; + autofillable_credentials_profile_store_login_database = false; + }; + webkit = { + webprefs = { + default_fixed_font_size = 14; + default_font_size = 17; + minimum_font_size = 16; + fonts = let + mono = config.module.style.font.monospace.name; + sans = config.module.style.font.sansSerif.name; + in { + fixed.Zyyy = mono; + sansserif.Zyyy = sans; + serif.Zyyy = sans; + standard.Zyyy = sans; + }; + }; + }; + }; - localState = (pkgs.formats.json { }).generate "ChromiumLocalState" { - browser = { - enabled_labs_experiments = [ "smooth-scrolling@2" ]; - first_run_finished = true; - }; - }; + localState = (pkgs.formats.json { }).generate "ChromiumLocalState" { + browser = { + first_run_finished = true; + enabled_labs_experiments = [ + "smooth-scrolling@2" + ]; + }; + }; - # REF: https://chromeenterprise.google/intl/en_us/policies/ - policy = (pkgs.formats.json { }).generate "ChromiumPolicy" { - URLBlocklist = [ "darkreader.org" ]; - DefaultBrowserSettingEnabled = false; - }; + # REF: https://chromeenterprise.google/intl/en_us/policies/ + policy = (pkgs.formats.json { }).generate "ChromiumPolicy" { + DefaultBrowserSettingEnabled = false; + URLBlocklist = [ + "darkreader.org" + ]; + }; } diff --git a/home/config/dconf/Accessibility.nix b/home/config/dconf/Accessibility.nix index ed4c2db..52d86f4 100644 --- a/home/config/dconf/Accessibility.nix +++ b/home/config/dconf/Accessibility.nix @@ -1,6 +1,5 @@ -{ ... }: -{ - "org/gnome/desktop/a11y" = { - always-show-universal-access-status = true; - }; +{ ... }: { + "org/gnome/desktop/a11y" = { + always-show-universal-access-status = true; + }; } diff --git a/home/config/dconf/Gtk.nix b/home/config/dconf/Gtk.nix index 9afa88a..d35fb66 100644 --- a/home/config/dconf/Gtk.nix +++ b/home/config/dconf/Gtk.nix @@ -1,28 +1,27 @@ -{ ... }: -{ - "org/gtk/gtk4/settings/file-chooser" = { - date-format = "regular"; - location-mode = "path-bar"; - show-hidden = false; - show-size-column = true; - show-type-column = true; - sidebar-width = "166"; - sort-column = "modified"; - sort-directories-first = true; - sort-order = "descending"; - type-format = "category"; - view-type = "list"; - }; +{ ... }: { + "org/gtk/gtk4/settings/file-chooser" = { + date-format = "regular"; + location-mode = "path-bar"; + show-hidden = false; + show-size-column = true; + show-type-column = true; + sidebar-width = "166"; + sort-column = "modified"; + sort-directories-first = true; + sort-order = "descending"; + type-format = "category"; + view-type = "list"; + }; - "org/gtk/settings/file-chooser" = { - date-format = "regular"; - location-mode = "path-bar"; - show-hidden = false; - show-size-column = true; - show-type-column = true; - sort-column = "modified"; - sort-directories-first = true; - sort-order = "descending"; - type-format = "category"; - }; + "org/gtk/settings/file-chooser" = { + date-format = "regular"; + location-mode = "path-bar"; + show-hidden = false; + show-size-column = true; + show-type-column = true; + sort-column = "modified"; + sort-directories-first = true; + sort-order = "descending"; + type-format = "category"; + }; } diff --git a/home/config/dconf/Input.nix b/home/config/dconf/Input.nix index 9fe5000..5dcaada 100644 --- a/home/config/dconf/Input.nix +++ b/home/config/dconf/Input.nix @@ -1,40 +1,32 @@ -{ lib, config, ... }: { - "org/gnome/desktop/input-sources" = with lib.gvariant; { - current = mkUint32 0; - mru-sources = [ - (mkTuple [ - "xkb" - "us" - ]) - (mkTuple [ - "xkb" - "ru" - ]) - ]; - per-window = false; - show-all-sources = true; - sources = [ - (mkTuple [ - "xkb" - "us" - ]) - (mkTuple [ - "xkb" - "ru" - ]) - ]; - xkb-options = [ config.setting.keyboard.options ]; - }; + lib, + config, + ... +}: { + "org/gnome/desktop/input-sources" = with lib.gvariant; let + sources = [ + (mkTuple [ "xkb" "us" ]) + (mkTuple [ "xkb" "ru" ]) + ]; + in { + inherit sources; + current = mkUint32 0; + mru-sources = sources; + per-window = false; + show-all-sources = true; + xkb-options = [ + config.module.keyboard.options + ]; + }; - "org/gnome/desktop/peripherals/mouse" = { - accel-profile = "flat"; - natural-scroll = true; - speed = "0.0"; - }; + "org/gnome/desktop/peripherals/mouse" = { + accel-profile = "flat"; + natural-scroll = true; + speed = "0.0"; + }; - "org/gnome/desktop/peripherals/touchpad" = { - tap-to-click = true; - two-finger-scrolling-enabled = true; - }; + "org/gnome/desktop/peripherals/touchpad" = { + tap-to-click = true; + two-finger-scrolling-enabled = true; + }; } diff --git a/home/config/dconf/Interface.nix b/home/config/dconf/Interface.nix index ad37863..c6b2e9f 100644 --- a/home/config/dconf/Interface.nix +++ b/home/config/dconf/Interface.nix @@ -1,12 +1,12 @@ { ... }: { - "org/gnome/desktop/interface" = { - clock-show-date = true; - clock-show-weekday = true; - color-scheme = "prefer-dark"; - enable-animations = false; - enable-hot-corners = false; - gtk-enable-primary-paste = false; - show-battery-percentage = false; - }; + "org/gnome/desktop/interface" = { + clock-show-date = true; + clock-show-weekday = true; + color-scheme = "prefer-dark"; + enable-animations = false; + enable-hot-corners = false; + gtk-enable-primary-paste = false; + show-battery-percentage = false; + }; } diff --git a/home/config/dconf/Key.nix b/home/config/dconf/Key.nix index 1c57e7b..9271e70 100644 --- a/home/config/dconf/Key.nix +++ b/home/config/dconf/Key.nix @@ -1,134 +1,132 @@ -{ config, ... }: -let - mod = ""; -in -{ - "org/gnome/desktop/wm/keybindings" = { - activate-window-menu = [ "" ]; - begin-move = [ "" ]; - begin-resize = [ "${mod}r" ]; - close = [ "${mod}x" ]; - cycle-group = [ "" ]; - cycle-group-backward = [ "" ]; - cycle-panels = [ "" ]; - cycle-panels-backward = [ "" ]; - cycle-windows = [ "" ]; - cycle-windows-backward = [ "" ]; - maximize = [ "" ]; - maximize-horizontally = [ "" ]; - minimize = [ "${mod}s" ]; - move-to-monitor-down = [ "" ]; - move-to-monitor-left = [ "" ]; - move-to-monitor-right = [ "" ]; - move-to-monitor-up = [ "" ]; - move-to-workspace-1 = [ "" ]; - move-to-workspace-2 = [ "" ]; - move-to-workspace-3 = [ "" ]; - move-to-workspace-4 = [ "" ]; - move-to-workspace-last = [ "" ]; - move-to-workspace-left = [ "${mod}q" ]; - move-to-workspace-right = [ "${mod}e" ]; - panel-run-dialog = [ "${mod}space" ]; - show-desktop = [ "${mod}c" ]; - switch-applications = [ "${mod}Tab" ]; - switch-applications-backward = [ "${mod}Tab" ]; - switch-group = [ "Tab" ]; - switch-group-backward = [ "Tab" ]; - switch-input-source = [ "" ]; - switch-input-source-backward = [ "" ]; - switch-panels = [ "" ]; - switch-panels-backward = [ "" ]; - switch-to-workspace-1 = [ "" ]; - switch-to-workspace-2 = [ "" ]; - switch-to-workspace-3 = [ "" ]; - switch-to-workspace-4 = [ "" ]; - switch-to-workspace-last = [ "" ]; - switch-to-workspace-left = [ "${mod}q" ]; - switch-to-workspace-right = [ "${mod}e" ]; - switch-windows = [ "" ]; - switch-windows-backward = [ "" ]; - toggle-fullscreen = [ "${mod}f" ]; - toggle-maximized = [ "${mod}w" ]; - unmaximize = [ "" ]; - }; +{ ... }: let + mod = ""; +in { + "org/gnome/desktop/wm/keybindings" = { + activate-window-menu = [ "" ]; + begin-move = [ "" ]; + begin-resize = [ "${mod}r" ]; + close = [ "${mod}x" ]; + cycle-group = [ "" ]; + cycle-group-backward = [ "" ]; + cycle-panels = [ "" ]; + cycle-panels-backward = [ "" ]; + cycle-windows = [ "" ]; + cycle-windows-backward = [ "" ]; + maximize = [ "" ]; + maximize-horizontally = [ "" ]; + minimize = [ "${mod}s" ]; + move-to-monitor-down = [ "" ]; + move-to-monitor-left = [ "" ]; + move-to-monitor-right = [ "" ]; + move-to-monitor-up = [ "" ]; + move-to-workspace-1 = [ "" ]; + move-to-workspace-2 = [ "" ]; + move-to-workspace-3 = [ "" ]; + move-to-workspace-4 = [ "" ]; + move-to-workspace-last = [ "" ]; + move-to-workspace-left = [ "${mod}q" ]; + move-to-workspace-right = [ "${mod}e" ]; + panel-run-dialog = [ "${mod}space" ]; + show-desktop = [ "${mod}c" ]; + switch-applications = [ "${mod}Tab" ]; + switch-applications-backward = [ "${mod}Tab" ]; + switch-group = [ "Tab" ]; + switch-group-backward = [ "Tab" ]; + switch-input-source = [ "" ]; + switch-input-source-backward = [ "" ]; + switch-panels = [ "" ]; + switch-panels-backward = [ "" ]; + switch-to-workspace-1 = [ "" ]; + switch-to-workspace-2 = [ "" ]; + switch-to-workspace-3 = [ "" ]; + switch-to-workspace-4 = [ "" ]; + switch-to-workspace-last = [ "" ]; + switch-to-workspace-left = [ "${mod}q" ]; + switch-to-workspace-right = [ "${mod}e" ]; + switch-windows = [ "" ]; + switch-windows-backward = [ "" ]; + toggle-fullscreen = [ "${mod}f" ]; + toggle-maximized = [ "${mod}w" ]; + unmaximize = [ "" ]; + }; - "org/gnome/mutter/keybindings" = { - toggle-tiled-left = [ "${mod}a" ]; - toggle-tiled-right = [ "${mod}d" ]; - }; + "org/gnome/mutter/keybindings" = { + toggle-tiled-left = [ "${mod}a" ]; + toggle-tiled-right = [ "${mod}d" ]; + }; - "org/gnome/mutter/wayland/keybindings" = { - restore-shortcuts = [ "" ]; - }; + "org/gnome/mutter/wayland/keybindings" = { + restore-shortcuts = [ "" ]; + }; - "org/gnome/settings-daemon/plugins/media-keys" = { - custom-keybindings = [ - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/" - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/" - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/" - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/" - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/" - "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/" - ]; - magnifier = [ "" ]; - magnifier-zoom-in = [ "" ]; - magnifier-zoom-out = [ "" ]; - screenreader = [ "" ]; - screensaver = [ "${mod}z" ]; - }; + "org/gnome/settings-daemon/plugins/media-keys" = { + custom-keybindings = [ + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0/" + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1/" + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2/" + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3/" + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4/" + "/org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5/" + ]; + magnifier = [ "" ]; + magnifier-zoom-in = [ "" ]; + magnifier-zoom-out = [ "" ]; + screenreader = [ "" ]; + screensaver = [ "${mod}z" ]; + }; - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0" = { - binding = "${mod}Escape"; - command = "kgx -e bash -c 'tmux new-session -A -s main; bash'"; - name = "gnome-terminal"; - }; + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom0" = { + binding = "${mod}Escape"; + command = "kgx -e bash -c 'tmux new-session -A -s main; bash'"; + name = "gnome-terminal"; + }; - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1" = { - binding = "printz"; - command = "systemctl suspend -i"; - name = "System Sleep"; - }; + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom1" = { + binding = "printz"; + command = "systemctl suspend -i"; + name = "System Sleep"; + }; - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2" = { - binding = "printx"; - command = "systemctl poweroff -i"; - name = "System Poweroff"; - }; + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom2" = { + binding = "printx"; + command = "systemctl poweroff -i"; + name = "System Poweroff"; + }; - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3" = { - binding = "printc"; - command = "systemctl reboot -i"; - name = "System Reboot"; - }; + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom3" = { + binding = "printc"; + command = "systemctl reboot -i"; + name = "System Reboot"; + }; - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4" = { - binding = "printp"; - command = "powersave toggle"; - name = "Toggle Powersave"; - }; + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom4" = { + binding = "printp"; + command = "powersave toggle"; + name = "Toggle Powersave"; + }; - "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5" = { - binding = "printl"; - command = "powerlimit toggle"; - name = "Toggle Powerlimit"; - }; + "org/gnome/settings-daemon/plugins/media-keys/custom-keybindings/custom5" = { + binding = "printl"; + command = "powerlimit toggle"; + name = "Toggle Powerlimit"; + }; - "org/gnome/shell/keybindings" = { - focus-active-notification = [ "" ]; - open-application-menu = [ "" ]; - show-screenshot-ui = [ "${mod}v" ]; - switch-to-application-1 = [ "" ]; - switch-to-application-2 = [ "" ]; - switch-to-application-3 = [ "" ]; - switch-to-application-4 = [ "" ]; - switch-to-application-5 = [ "" ]; - switch-to-application-6 = [ "" ]; - switch-to-application-7 = [ "" ]; - switch-to-application-8 = [ "" ]; - switch-to-application-9 = [ "" ]; - toggle-application-view = [ "" ]; - toggle-message-tray = [ "" ]; - toggle-overview = [ "" ]; - toggle-quick-settings = [ "" ]; - }; + "org/gnome/shell/keybindings" = { + focus-active-notification = [ "" ]; + open-application-menu = [ "" ]; + show-screenshot-ui = [ "${mod}v" ]; + switch-to-application-1 = [ "" ]; + switch-to-application-2 = [ "" ]; + switch-to-application-3 = [ "" ]; + switch-to-application-4 = [ "" ]; + switch-to-application-5 = [ "" ]; + switch-to-application-6 = [ "" ]; + switch-to-application-7 = [ "" ]; + switch-to-application-8 = [ "" ]; + switch-to-application-9 = [ "" ]; + toggle-application-view = [ "" ]; + toggle-message-tray = [ "" ]; + toggle-overview = [ "" ]; + toggle-quick-settings = [ "" ]; + }; } diff --git a/home/config/dconf/Media.nix b/home/config/dconf/Media.nix index fef8d15..01e67e1 100644 --- a/home/config/dconf/Media.nix +++ b/home/config/dconf/Media.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - "org/gnome/desktop/media-handling" = { - automount = false; - automount-open = false; - autorun-never = true; - }; +{ ... }: { + "org/gnome/desktop/media-handling" = { + automount = false; + automount-open = false; + autorun-never = true; + }; } diff --git a/home/config/dconf/Nautilus.nix b/home/config/dconf/Nautilus.nix index 253a8aa..e20a08e 100644 --- a/home/config/dconf/Nautilus.nix +++ b/home/config/dconf/Nautilus.nix @@ -1,22 +1,21 @@ -{ ... }: -{ - "org/gnome/nautilus/icon-view" = { - default-zoom-level = "larger"; - }; +{ ... }: { + "org/gnome/nautilus/icon-view" = { + default-zoom-level = "larger"; + }; - "org/gnome/nautilus/list-view" = { - default-zoom-level = "small"; - use-tree-view = false; - }; + "org/gnome/nautilus/list-view" = { + default-zoom-level = "small"; + use-tree-view = false; + }; - "org/gnome/nautilus/preferences" = { - click-policy = "single"; - default-folder-viewer = "list-view"; - default-sort-in-reverse-order = false; - default-sort-order = "name"; - migrated-gtk-settings = true; - search-filter-time-type = "last_modified"; - search-view = "list-view"; - show-image-thumbnails = "local-only"; - }; + "org/gnome/nautilus/preferences" = { + click-policy = "single"; + default-folder-viewer = "list-view"; + default-sort-in-reverse-order = false; + default-sort-order = "name"; + migrated-gtk-settings = true; + search-filter-time-type = "last_modified"; + search-view = "list-view"; + show-image-thumbnails = "local-only"; + }; } diff --git a/home/config/dconf/Power.nix b/home/config/dconf/Power.nix index 01c55d6..06ff8c1 100644 --- a/home/config/dconf/Power.nix +++ b/home/config/dconf/Power.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - "org/gnome/settings-daemon/plugins/power" = { - ambient-enabled = false; - idle-dim = false; - power-button-action = "nothing"; - sleep-inactive-ac-timeout = "0"; - sleep-inactive-ac-type = "nothing"; - sleep-inactive-battery-type = "nothing"; - }; +{ ... }: { + "org/gnome/settings-daemon/plugins/power" = { + ambient-enabled = false; + idle-dim = false; + power-button-action = "nothing"; + sleep-inactive-ac-timeout = "0"; + sleep-inactive-ac-type = "nothing"; + sleep-inactive-battery-type = "nothing"; + }; } diff --git a/home/config/dconf/Privacy.nix b/home/config/dconf/Privacy.nix index f45daf3..e44548a 100644 --- a/home/config/dconf/Privacy.nix +++ b/home/config/dconf/Privacy.nix @@ -1,16 +1,18 @@ -{ lib, ... }: { - "org/gnome/desktop/privacy" = with lib.gvariant; { - disable-camera = false; - disable-microphone = false; - old-files-age = mkUint32 30; - recent-files-max-age = mkUint32 30; - remove-old-temp-files = true; - remove-old-trash-files = true; - report-technical-problems = true; - }; + lib, + ... +}: { + "org/gnome/desktop/privacy" = with lib.gvariant; { + disable-camera = false; + disable-microphone = false; + old-files-age = mkUint32 30; + recent-files-max-age = mkUint32 30; + remove-old-temp-files = true; + remove-old-trash-files = true; + report-technical-problems = true; + }; - "org/gnome/system/location" = { - enabled = false; - }; + "org/gnome/system/location" = { + enabled = false; + }; } diff --git a/home/config/dconf/Session.nix b/home/config/dconf/Session.nix index 7e4b7c7..1ad0a13 100644 --- a/home/config/dconf/Session.nix +++ b/home/config/dconf/Session.nix @@ -1,6 +1,8 @@ -{ lib, ... }: { - "org/gnome/desktop/session" = with lib.gvariant; { - idle-delay = mkUint32 0; - }; + lib, + ... +}: { + "org/gnome/desktop/session" = with lib.gvariant; { + idle-delay = mkUint32 0; + }; } diff --git a/home/config/dconf/Shell.nix b/home/config/dconf/Shell.nix index 9a867f8..88cec98 100644 --- a/home/config/dconf/Shell.nix +++ b/home/config/dconf/Shell.nix @@ -1,15 +1,14 @@ -{ ... }: -{ - "org/gnome/shell" = { - disable-extension-version-validation = true; - disable-user-extensions = false; - favorite-apps = [ "" ]; - had-bluetooth-devices-setup = true; - last-selected-power-profile = "power-saver"; - remember-mount-password = false; - }; +{ ... }: { + "org/gnome/shell" = { + disable-extension-version-validation = true; + disable-user-extensions = false; + favorite-apps = [ "" ]; + had-bluetooth-devices-setup = true; + last-selected-power-profile = "power-saver"; + remember-mount-password = false; + }; - "system/proxy" = { - mode = "none"; - }; + "system/proxy" = { + mode = "none"; + }; } diff --git a/home/config/dconf/Software.nix b/home/config/dconf/Software.nix index 2c38d0e..11303f2 100644 --- a/home/config/dconf/Software.nix +++ b/home/config/dconf/Software.nix @@ -1,9 +1,8 @@ -{ ... }: -{ - "org/gnome/software" = { - download-updates = false; - download-updates-notify = false; - first-run = false; - show-nonfree-prompt = false; - }; +{ ... }: { + "org/gnome/software" = { + download-updates = false; + download-updates-notify = false; + first-run = false; + show-nonfree-prompt = false; + }; } diff --git a/home/config/dconf/Sound.nix b/home/config/dconf/Sound.nix index 8a42caa..743e038 100644 --- a/home/config/dconf/Sound.nix +++ b/home/config/dconf/Sound.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - "org/gnome/desktop/sound" = { - allow-volume-above-100-percent = false; - event-sounds = false; - theme-name = "freedesktop"; - }; +{ ... }: { + "org/gnome/desktop/sound" = { + allow-volume-above-100-percent = false; + event-sounds = false; + theme-name = "freedesktop"; + }; } diff --git a/home/config/dconf/Wm.nix b/home/config/dconf/Wm.nix index 64c3ba4..cdc997b 100644 --- a/home/config/dconf/Wm.nix +++ b/home/config/dconf/Wm.nix @@ -1,33 +1,35 @@ -{ lib, ... }: { - "org/gnome/desktop/wm/preferences" = { - action-middle-click-titlebar = "minimize"; - action-right-click-titlebar = "menu"; - focus-mode = "click"; # `click` or `sloppy`. - button-layout = "appmenu:close"; - }; + lib, + ... +}: { + "org/gnome/desktop/wm/preferences" = { + action-middle-click-titlebar = "minimize"; + action-right-click-titlebar = "menu"; + button-layout = "appmenu:close"; + focus-mode = "click"; # `click` or `sloppy`. + }; - "org/gnome/mutter" = { - attach-modal-dialogs = true; - center-new-windows = true; - dynamic-workspaces = true; - edge-tiling = true; - workspaces-only-on-primary = true; - }; + "org/gnome/mutter" = { + attach-modal-dialogs = true; + center-new-windows = true; + dynamic-workspaces = true; + edge-tiling = true; + workspaces-only-on-primary = true; + }; - "org/gnome/settings-daemon/plugins/color" = with lib.gvariant; { - night-light-enabled = false; - night-light-schedule-automatic = false; - night-light-schedule-from = "0.0"; - night-light-schedule-to = "0.0"; - night-light-temperature = mkUint32 3700; - }; + "org/gnome/settings-daemon/plugins/color" = with lib.gvariant; { + night-light-enabled = false; + night-light-schedule-automatic = false; + night-light-schedule-from = "0.0"; + night-light-schedule-to = "0.0"; + night-light-temperature = mkUint32 3700; + }; - "org/gnome/shell/app-switcher" = { - current-workspace-only = true; - }; + "org/gnome/shell/app-switcher" = { + current-workspace-only = true; + }; - "org/gnome/shell/overrides" = { - edge-tiling = false; - }; + "org/gnome/shell/overrides" = { + edge-tiling = false; + }; } diff --git a/home/config/default.nix b/home/config/default.nix index e7c7627..2c2db50 100644 --- a/home/config/default.nix +++ b/home/config/default.nix @@ -1,60 +1,56 @@ { - self, - inputs, - config, - ... -}@args: -let - btop = import ./btop args; - chromium = import ./chromium args; - editor = import ./editorconfig args; - foot = import ./foot args; - fuzzel = import ./fuzzel args; - git = import ./git args; - gtk3 = import ./gtk/3 args; - jetbrains = import ./jetbrains args; - keyd = import ./keyd args; - mako = import ./mako args; - mangohud = import ./mangohud args; - nvim = import ./nvim args; - ssh = import ./ssh args; - swappy = import ./swappy args; - sway = import ./sway args; - tmux = import ./tmux args; - waybar = import ./waybar args; - yazi = import ./yazi args; -in -{ - ".Wallpaper".source = config.module.wallpaper.path; - ".config/MangoHud/MangoHud.conf".source = mangohud.config; - ".config/MangoHud/presets.conf".source = mangohud.presets; - ".config/btop/btop.conf".text = btop.text; - ".config/chromium/Default/Preferences".source = chromium.preferences; - ".config/chromium/Local State".source = chromium.localState; - ".config/foot/foot.ini".source = foot.file; - ".config/fuzzel/fuzzel.ini".source = fuzzel.file; - ".config/gtk-3.0/bookmarks".text = gtk3.bookmarks; - ".config/keyd/app.conf".text = keyd.text; - ".config/mako/config".source = mako.file; - ".config/nvim/init.vim".text = nvim.text; - ".config/swappy/config".source = swappy.config; - ".config/sway/config".text = sway.text; - ".config/tmux/tmux.conf".text = tmux.text; - ".config/waybar/config".source = waybar.config; - ".config/waybar/style.css".source = waybar.style; - ".config/yazi/init.lua".source = yazi.init; - ".config/yazi/keymap.toml".source = yazi.keymap; - ".config/yazi/theme.toml".source = yazi.theme; - ".config/yazi/yazi.toml".source = yazi.yazi; - ".editorconfig".source = editor.file; - ".gitconfig".source = git.file; - ".ideavimrc".text = jetbrains.ideavimrc; - ".nix".source = self; - ".nixpkgs".source = inputs.nixpkgs; - ".parallel/will-cite".text = ""; - ".ssh/config".text = ssh.text; - ".template".source = ./template; - # ".nixpkgs_master".source = inputs.nixpkgs; - # ".nixpkgs_unstable".source = inputs.nixpkgs; - # TODO: Add after migrating to stable. + config, + inputs, + self, + ... +} @args: let + btop = import ./btop args; + chromium = import ./chromium args; + editor = import ./editorconfig args; + foot = import ./foot args; + fuzzel = import ./fuzzel args; + git = import ./git args; + jetbrains = import ./jetbrains args; + keyd = import ./keyd args; + mako = import ./mako args; + mangohud = import ./mangohud args; + nvim = import ./nvim args; + ssh = import ./ssh args; + swappy = import ./swappy args; + sway = import ./sway args; + tmux = import ./tmux args; + waybar = import ./waybar args; + yazi = import ./yazi args; +in { + ".Wallpaper".source = config.module.wallpaper.path; + ".config/MangoHud/MangoHud.conf".source = mangohud.config; + ".config/MangoHud/presets.conf".source = mangohud.presets; + ".config/btop/btop.conf".source = btop.file; + ".config/chromium/Default/Preferences".source = chromium.preferences; + ".config/chromium/Local State".source = chromium.localState; + ".config/foot/foot.ini".source = foot.file; + ".config/fuzzel/fuzzel.ini".source = fuzzel.file; + ".config/keyd/app.conf".text = keyd.text; + ".config/mako/config".source = mako.file; + ".config/nvim/init.vim".text = nvim.text; + ".config/swappy/config".source = swappy.config; + ".config/sway/config".text = sway.text; + ".config/tmux/tmux.conf".text = tmux.text; + ".config/waybar/config".source = waybar.config; + ".config/waybar/style.css".source = waybar.style; + ".config/yazi/init.lua".source = yazi.init; + ".config/yazi/keymap.toml".source = yazi.keymap; + ".config/yazi/theme.toml".source = yazi.theme; + ".config/yazi/yazi.toml".source = yazi.yazi; + ".editorconfig".source = editor.file; + ".gitconfig".source = git.file; + ".ideavimrc".text = jetbrains.ideavimrc; + ".nix".source = self; + ".nixpkgs".source = inputs.nixpkgs; + ".parallel/will-cite".text = ""; + ".ssh/config".text = ssh.text; + ".template".source = ./template; + # ".nixpkgs_master".source = inputs.nixpkgs; + # ".nixpkgs_unstable".source = inputs.nixpkgs; + # TODO: Add after migrating to stable. } diff --git a/home/config/editorconfig/default.nix b/home/config/editorconfig/default.nix index 36bbf0e..489b9d2 100644 --- a/home/config/editorconfig/default.nix +++ b/home/config/editorconfig/default.nix @@ -1,34 +1,26 @@ -{ pkgs, ... }: { - file = (pkgs.formats.iniWithGlobalSection { }).generate "EditorconfigConfig" { - globalSection.root = true; - - sections = { - "*" = { - end_of_line = "lf"; - charset = "utf-8"; - indent_style = "tab"; - indent_size = 2; - insert_final_newline = false; - trim_trailing_whitespace = true; - }; - - "Makefile" = { - indent_size = 4; - }; - - "*.nix" = { - indent_style = "space"; - indent_size = 2; - }; - - "*.{lua,kt,kts,rs,py}" = { - indent_size = 4; - }; - - "*.{sh,md}" = { - indent_size = 8; - }; - }; - }; + pkgs, + ... +}: { + file = (pkgs.formats.iniWithGlobalSection { }).generate "EditorconfigConfig" { + globalSection = { + root = true; + }; + sections = { + "*" = { + charset = "utf-8"; + end_of_line = "lf"; + indent_size = 8; + indent_style = "tab"; + insert_final_newline = false; + trim_trailing_whitespace = true; + }; + "*.nix" = { + indent_size = 2; + }; + "*.{lua,kt,kts,rs,py}" = { + indent_size = 4; + }; + }; + }; } diff --git a/home/config/foot/default.nix b/home/config/foot/default.nix index bd34307..b642257 100644 --- a/home/config/foot/default.nix +++ b/home/config/foot/default.nix @@ -1,30 +1,31 @@ -{ config, pkgs, ... }: -let - dpiAware = if config.setting.dpiAware then "yes" else "no"; - borderSize = toString config.style.window.border; - fontStep = 1; -in { - file = (pkgs.formats.iniWithGlobalSection { }).generate "FootConfig" { - globalSection = { - font = "${config.style.font.monospace.name}:size=${toString config.style.font.size.terminal}"; - # font-bold = "${config.style.font.monospace.name}:size=${toString config.style.font.size.terminal}"; - font-italic = "${config.style.font.monospace.name}:size=${toString config.style.font.size.terminal}"; - font-bold-italic = "${config.style.font.monospace.name}:size=${toString config.style.font.size.terminal}"; - dpi-aware = dpiAware; - font-size-adjustment = fontStep; - pad = "${borderSize}x${borderSize} center"; - }; - - sections = { - colors = { - alpha = config.style.opacity.terminal; - background = config.style.color.bg.dark; - foreground = config.style.color.fg.light; - }; - key-bindings = { - show-urls-launch = "Mod1+o"; - }; - }; - }; + config, + pkgs, + ... +}: let + borderSize = toString config.module.style.window.border; + dpiAware = if config.module.dpi.aware then "yes" else "no"; + fontStep = 1; +in { + file = (pkgs.formats.iniWithGlobalSection { }).generate "FootConfig" { + globalSection = { + dpi-aware = dpiAware; + font = "${config.module.style.font.monospace.name}:size=${toString config.module.style.font.size.terminal}"; + font-bold = "${config.module.style.font.monospace.name}:size=${toString config.module.style.font.size.terminal}"; + font-bold-italic = "${config.module.style.font.monospace.name}:size=${toString config.module.style.font.size.terminal}"; + font-italic = "${config.module.style.font.monospace.name}:size=${toString config.module.style.font.size.terminal}"; + font-size-adjustment = fontStep; + pad = "${borderSize}x${borderSize} center"; + }; + sections = { + colors = { + alpha = config.module.style.opacity.terminal; + background = config.module.style.color.bg.dark; + foreground = config.module.style.color.fg.light; + }; + key-bindings = { + show-urls-launch = "Mod1+o"; + }; + }; + }; } diff --git a/home/config/fuzzel/default.nix b/home/config/fuzzel/default.nix index 783bcbb..18594ad 100644 --- a/home/config/fuzzel/default.nix +++ b/home/config/fuzzel/default.nix @@ -1,40 +1,38 @@ -{ pkgs, config, ... }: -let - dpiAware = if config.setting.dpiAware then "yes" else "no"; -in { - file = (pkgs.formats.ini { }).generate "FuzzelConfig" { - main = { - dpi-aware = dpiAware; - # font = "${style.font.serif.name}:size=${toString style.font.size.popup}"; - font = "Minecraftia:size=${toString config.style.font.size.popup}"; - lines = 20; - prompt = "\"\""; - show-actions = "yes"; - terminal = "foot"; - width = 40; - # list-executables-in-path = "no"; - }; - border = { - radius = 0; - width = 1; - }; - colors = - let - defaultOpacity = "ff"; - in - { - background = config.style.color.bg.dark + config.style.opacity.hex; - border = config.style.color.border + config.style.opacity.hex; - counter = config.style.color.bg.regular + defaultOpacity; - input = config.style.color.fg.light + defaultOpacity; - match = config.style.color.fg.light + defaultOpacity; - placeholder = config.style.color.bg.regular + defaultOpacity; - prompt = config.style.color.fg.light + defaultOpacity; - selection = config.style.color.bg.regular + defaultOpacity; - selection-match = config.style.color.accent + defaultOpacity; - selection-text = config.style.color.fg.light + defaultOpacity; - text = config.style.color.fg.light + defaultOpacity; - }; - }; + pkgs, + config, + ... +}: let + dpiAware = if config.module.dpi.aware then "yes" else "no"; +in { + file = (pkgs.formats.ini { }).generate "FuzzelConfig" { + main = { + dpi-aware = dpiAware; + font = "Minecraftia:size=${toString config.module.style.font.size.popup}"; + lines = 20; + prompt = "\"\""; + show-actions = "yes"; + terminal = "foot"; + width = 40; + }; + border = { + radius = 0; + width = 1; + }; + colors = let + defaultOpacity = "ff"; + in { + background = config.module.style.color.bg.dark + config.module.style.opacity.hex; + border = config.module.style.color.border + config.module.style.opacity.hex; + counter = config.module.style.color.bg.regular + defaultOpacity; + input = config.module.style.color.fg.light + defaultOpacity; + match = config.module.style.color.fg.light + defaultOpacity; + placeholder = config.module.style.color.bg.regular + defaultOpacity; + prompt = config.module.style.color.fg.light + defaultOpacity; + selection = config.module.style.color.bg.regular + defaultOpacity; + selection-match = config.module.style.color.accent + defaultOpacity; + selection-text = config.module.style.color.fg.light + defaultOpacity; + text = config.module.style.color.fg.light + defaultOpacity; + }; + }; } diff --git a/home/config/git/default.nix b/home/config/git/default.nix index e28551d..b09d8df 100644 --- a/home/config/git/default.nix +++ b/home/config/git/default.nix @@ -1,14 +1,16 @@ -{ secret, pkgs, ... }: { - file = (pkgs.formats.gitIni { listsAsDuplicateKeys = true; }).generate "GitConfig" { - # credential.helper = "store"; - gpg.format = secret.crypto.sign.git.format; - gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed; - init.defaultBranch = "main"; - pull.rebase = true; - push.autoSetupRemote = true; - rebase.autoStash = true; - safe.directory = "*"; - user.signingkey = builtins.readFile secret.crypto.sign.git.key; - }; + secret, + pkgs, + ... +}: { + file = (pkgs.formats.gitIni { listsAsDuplicateKeys = true; }).generate "GitConfig" { + gpg.format = secret.crypto.sign.git.format; + gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed; + init.defaultBranch = "main"; + pull.rebase = true; + push.autoSetupRemote = true; + rebase.autoStash = true; + safe.directory = "*"; + user.signingkey = builtins.readFile secret.crypto.sign.git.key; + }; } diff --git a/home/config/gtk/3/default.nix b/home/config/gtk/3/default.nix deleted file mode 100644 index ca1944a..0000000 --- a/home/config/gtk/3/default.nix +++ /dev/null @@ -1,10 +0,0 @@ -{ ... }: -{ - bookmarks = '' - file:///storage - file:///home/voronind/tmp - sftp://10.0.0.1:22143/storage/hot/docker/cloud/data/data/cakee/files/ home cloud - sftp://10.0.0.1:22143/ home sftp - ftp://10.0.0.1/ home ftp - ''; -} diff --git a/home/config/jetbrains/default.nix b/home/config/jetbrains/default.nix index 7d6fbf8..155c85c 100644 --- a/home/config/jetbrains/default.nix +++ b/home/config/jetbrains/default.nix @@ -1,27 +1,29 @@ -{ ... }: { - ideavimrc = '' - " Plugins. - Plug 'tpope/vim-commentary' - Plug 'machakann/vim-highlightedyank' - " Plug 'junegunn/vim-easy-align' + util, + ... +}: { + ideavimrc = util.trimTabs '' + " Plugins. + Plug 'tpope/vim-commentary' + Plug 'machakann/vim-highlightedyank' + " Plug 'junegunn/vim-easy-align' - " General config. - set scrolloff=4 - set incsearch - set hlsearch - set clipboard=unnamedplus - set relativenumber - set number + " General config. + set scrolloff=4 + set incsearch + set hlsearch + set clipboard=unnamedplus + set relativenumber + set number - " Space as a leader. - nnoremap - let mapleader=" " + " Space as a leader. + nnoremap + let mapleader=" " - " Align. ISSUE: Broken. - " vmap a (EasyAlign) + " Align. ISSUE: Broken. + " vmap a (EasyAlign) - " Sort. - vmap A :sort - ''; + " Sort. + vmap A :sort + ''; } diff --git a/home/config/keyd/default.nix b/home/config/keyd/default.nix index 2e1c2ad..6aa9764 100644 --- a/home/config/keyd/default.nix +++ b/home/config/keyd/default.nix @@ -1,4 +1,6 @@ -{ util, ... }@args: { - text = util.catFile (util.ls ./module) args; + util, + ... +} @args: { + text = util.catFile (util.ls ./module) args; } diff --git a/home/config/keyd/module/Chromium.nix b/home/config/keyd/module/Chromium.nix index bbee735..b10a73e 100644 --- a/home/config/keyd/module/Chromium.nix +++ b/home/config/keyd/module/Chromium.nix @@ -1,29 +1,31 @@ -{ pkgs, ... }: { - file = (pkgs.formats.ini { }).generate "KeydChromiumConfig" { - "chromium-browser" = { - "alt.capslock" = "C-t"; # New tab. - "alt.x" = "C-w"; # Close tab. - "alt.u" = "C-S-t"; # Restore closed tab. - "alt.q" = "C-pageup"; # Prev tab. - "alt.e" = "C-pagedown"; # Next tab. - "alt.Q" = "C-S-pageup"; # Move tab left. - "alt.E" = "C-S-pagedown"; # Move tab right. - "alt.a" = "A-left"; # Go back. - "alt.d" = "A-right"; # Go forward. - "alt.s" = "down"; # Scroll down. - "alt.w" = "up"; # Scroll up. - "alt.f" = "C-f"; # Find text. - "alt.N" = "S-f3"; # Find prev. - "alt.n" = "f3"; # Find next. - "alt.space" = "f6"; # Focus address bar. - "alt.r" = "C-f5"; # Full refresh. - "alt.l" = "A-S-l"; # Toggle dark mode. - "alt.enter" = "C-S-l"; # Fill password. - "alt.p" = "A-S-p"; # Toggle proxy. - "alt.j" = "A-S-j"; # Toggle js. - "alt.k" = "A-S-k"; # Block element. - "alt.b" = "A-S-b"; # Show uBlock. - }; - }; + pkgs, + ... +}: { + file = (pkgs.formats.ini { }).generate "KeydChromiumConfig" { + "chromium-browser" = { + "alt.capslock" = "C-t"; # New tab. + "alt.x" = "C-w"; # Close tab. + "alt.u" = "C-S-t"; # Restore closed tab. + "alt.q" = "C-pageup"; # Prev tab. + "alt.e" = "C-pagedown"; # Next tab. + "alt.Q" = "C-S-pageup"; # Move tab left. + "alt.E" = "C-S-pagedown"; # Move tab right. + "alt.a" = "A-left"; # Go back. + "alt.d" = "A-right"; # Go forward. + "alt.s" = "down"; # Scroll down. + "alt.w" = "up"; # Scroll up. + "alt.f" = "C-f"; # Find text. + "alt.N" = "S-f3"; # Find prev. + "alt.n" = "f3"; # Find next. + "alt.space" = "f6"; # Focus address bar. + "alt.r" = "C-f5"; # Full refresh. + "alt.l" = "A-S-l"; # Toggle dark mode. + "alt.enter" = "C-S-l"; # Fill password. + "alt.p" = "A-S-p"; # Toggle proxy. + "alt.j" = "A-S-j"; # Toggle js. + "alt.k" = "A-S-k"; # Block element. + "alt.b" = "A-S-b"; # Show uBlock. + }; + }; } diff --git a/home/config/keyd/module/DRG.nix b/home/config/keyd/module/DRG.nix index 5bd9689..c29049a 100644 --- a/home/config/keyd/module/DRG.nix +++ b/home/config/keyd/module/DRG.nix @@ -1,33 +1,35 @@ -{ pkgs, ... }: { - file = (pkgs.formats.ini { }).generate "KeydDrgConfig" { - steam-app-548430 = { - "alt.1" = "macro(enter 10ms L e t ' s 10ms space d o 10ms space t h i s 10ms space T e x a s 10ms space s t y l e ! 10ms enter)"; - "alt.2" = "macro(enter 10ms H e c k space y e s ! enter)"; - "alt.3" = "macro(enter 10ms J u s t space a space s i d e - j o b space w h i l e 10ms space w a i t i n g space f o r space a space s e x space u p d a t e . enter)"; - "alt.4" = "macro(enter 10ms < 3 enter)"; - "alt.[" = "macro(enter 10ms W h a t space i s space c r u n c h y 10ms space o n space t h e space o u t s i d e , 10ms space g o o e y space o n space 10ms t h e space i n s i d e ? enter)"; - "alt.]" = "macro(enter 10ms Q ' r o n a r space S h e l l b a c k ! enter)"; - "alt.a" = "macro(enter 10ms N o enter)"; - "alt.b" = "macro(enter 10ms I ' m space b a c k enter)"; - "alt.c" = "macro(enter 10ms > space R i g h t enter)"; - "alt.d" = "macro(enter 10ms Y e s enter)"; - "alt.e" = "macro(enter 10ms T h a n k s ! enter)"; - "alt.f" = "macro(enter 10ms I space n e e d space h e l p ! enter)"; - "alt.g" = "macro(enter 10ms g g enter)"; - "alt.j" = "macro(enter 10ms G o o d space j o b enter)"; - "alt.k" = "macro(enter 10ms O k a y enter)"; - "alt.l" = "macro(enter 10ms L e a f space l o v e r enter)"; - "alt.m" = "macro(enter 10ms I space r e p l y space u s i n g space m a c r o s . 10ms space U s e space s o f t w a r e space l i k e space k e y d , 10ms space o r space b u y space a space Q M K space k e y b o a r d . enter)"; - "alt.q" = "macro(enter 10ms S o r r y ! enter)"; - "alt.r" = "macro(enter 10ms N e e d space m o r e space a m m o enter)"; - "alt.s" = "macro(enter 10ms W a i t enter)"; - "alt.t" = "macro(enter 10ms M a y space I space t a k e space e x t r a ? enter)"; - "alt.v" = "macro(enter 10ms A F K enter)"; - "alt.w" = "macro(enter 10ms r enter)"; - "alt.x" = "macro(enter 10ms > space H e r e space < enter)"; - "alt.z" = "macro(enter 10ms < space L e f t enter)"; - leftshift = "timeout(leftcontrol, 150, leftshift)"; - }; - }; + pkgs, + ... +}: { + file = (pkgs.formats.ini { }).generate "KeydDrgConfig" { + steam-app-548430 = { + "alt.1" = "macro(enter 10ms L e t ' s 10ms space d o 10ms space t h i s 10ms space T e x a s 10ms space s t y l e ! 10ms enter)"; + "alt.2" = "macro(enter 10ms H e c k space y e s ! enter)"; + "alt.3" = "macro(enter 10ms J u s t space a space s i d e - j o b space w h i l e 10ms space w a i t i n g space f o r space a space s e x space u p d a t e . enter)"; + "alt.4" = "macro(enter 10ms < 3 enter)"; + "alt.[" = "macro(enter 10ms W h a t space i s space c r u n c h y 10ms space o n space t h e space o u t s i d e , 10ms space g o o e y space o n space 10ms t h e space i n s i d e ? enter)"; + "alt.]" = "macro(enter 10ms Q ' r o n a r space S h e l l b a c k ! enter)"; + "alt.a" = "macro(enter 10ms N o enter)"; + "alt.b" = "macro(enter 10ms I ' m space b a c k enter)"; + "alt.c" = "macro(enter 10ms > space R i g h t enter)"; + "alt.d" = "macro(enter 10ms Y e s enter)"; + "alt.e" = "macro(enter 10ms T h a n k s ! enter)"; + "alt.f" = "macro(enter 10ms I space n e e d space h e l p ! enter)"; + "alt.g" = "macro(enter 10ms g g enter)"; + "alt.j" = "macro(enter 10ms G o o d space j o b enter)"; + "alt.k" = "macro(enter 10ms O k a y enter)"; + "alt.l" = "macro(enter 10ms L e a f space l o v e r enter)"; + "alt.m" = "macro(enter 10ms I space r e p l y space u s i n g space m a c r o s . 10ms space U s e space s o f t w a r e space l i k e space k e y d , 10ms space o r space b u y space a space Q M K space k e y b o a r d . enter)"; + "alt.q" = "macro(enter 10ms S o r r y ! enter)"; + "alt.r" = "macro(enter 10ms N e e d space m o r e space a m m o enter)"; + "alt.s" = "macro(enter 10ms W a i t enter)"; + "alt.t" = "macro(enter 10ms M a y space I space t a k e space e x t r a ? enter)"; + "alt.v" = "macro(enter 10ms A F K enter)"; + "alt.w" = "macro(enter 10ms r enter)"; + "alt.x" = "macro(enter 10ms > space H e r e space < enter)"; + "alt.z" = "macro(enter 10ms < space L e f t enter)"; + leftshift = "timeout(leftcontrol, 150, leftshift)"; + }; + }; } diff --git a/home/config/keyd/module/Disable.nix b/home/config/keyd/module/Disable.nix index 62ae02e..652656a 100644 --- a/home/config/keyd/module/Disable.nix +++ b/home/config/keyd/module/Disable.nix @@ -1,28 +1,28 @@ -{ pkgs, ... }: -let - apps = [ - "gimp" - "gimp-*" - "steam-proton" - ]; - - keys = [ - "escape" - "leftcontrol" - ]; -in { - file = (pkgs.formats.ini { }).generate "KeydDisableConfig" ( - builtins.listToAttrs ( - builtins.map (app: { - name = app; - value = builtins.listToAttrs ( - builtins.map (key: { - name = key; - value = key; - }) keys - ); - }) apps - ) - ); + pkgs, + ... +}: let + apps = [ + "gimp" + "gimp-*" + "steam-proton" + ]; + + keys = [ + "escape" + "leftcontrol" + ]; +in { + file = let + keySets = builtins.map (key: { + name = key; + value = key; + }) keys; + + appSets = builtins.map (app: { + name = app; + value = builtins.listToAttrs keySets; + }) apps; + in + (pkgs.formats.ini { }).generate "KeydDisableConfig" (builtins.listToAttrs appSets); } diff --git a/home/config/keyd/module/Firefox.nix b/home/config/keyd/module/Firefox.nix index 992cf40..49fcfad 100644 --- a/home/config/keyd/module/Firefox.nix +++ b/home/config/keyd/module/Firefox.nix @@ -1,26 +1,28 @@ -{ pkgs, ... }: { - file = (pkgs.formats.ini { }).generate "KeydFirefoxConfig" { - "firefox-esr" = { - "alt.capslock" = "C-t"; # New tab. - "alt.x" = "C-w"; # Close tab. - "alt.u" = "C-S-t"; # Restore closed tab. - "alt.q" = "C-pageup"; # Prev tab. - "alt.e" = "C-pagedown"; # Next tab. - "alt.Q" = "C-S-pageup"; # Move tab left. - "alt.E" = "C-S-pagedown"; # Move tab right. - "alt.a" = "A-left"; # Go back. - "alt.d" = "A-right"; # Go forward. - "alt.s" = "down"; # Scroll down. - "alt.w" = "up"; # Scroll up. - "alt.f" = "C-f"; # Find text. - "alt.N" = "S-f3"; # Find prev. - "alt.n" = "f3"; # Find next. - "alt.space" = "f6"; # Focus address bar. - "alt.r" = "C-f5"; # Full refresh. - "alt.l" = "A-S-a"; # Toggle dark mode. - "alt.m" = "C-m"; # Toggle tab mute. - "alt.enter" = "C-S-l"; # Fill password. - }; - }; + pkgs, + ... +}: { + file = (pkgs.formats.ini { }).generate "KeydFirefoxConfig" { + "firefox-esr" = { + "alt.capslock" = "C-t"; # New tab. + "alt.x" = "C-w"; # Close tab. + "alt.u" = "C-S-t"; # Restore closed tab. + "alt.q" = "C-pageup"; # Prev tab. + "alt.e" = "C-pagedown"; # Next tab. + "alt.Q" = "C-S-pageup"; # Move tab left. + "alt.E" = "C-S-pagedown"; # Move tab right. + "alt.a" = "A-left"; # Go back. + "alt.d" = "A-right"; # Go forward. + "alt.s" = "down"; # Scroll down. + "alt.w" = "up"; # Scroll up. + "alt.f" = "C-f"; # Find text. + "alt.N" = "S-f3"; # Find prev. + "alt.n" = "f3"; # Find next. + "alt.space" = "f6"; # Focus address bar. + "alt.r" = "C-f5"; # Full refresh. + "alt.l" = "A-S-a"; # Toggle dark mode. + "alt.m" = "C-m"; # Toggle tab mute. + "alt.enter" = "C-S-l"; # Fill password. + }; + }; } diff --git a/home/config/keyd/module/Jetbrains.nix b/home/config/keyd/module/Jetbrains.nix index 6d43d46..6ea842b 100644 --- a/home/config/keyd/module/Jetbrains.nix +++ b/home/config/keyd/module/Jetbrains.nix @@ -1,29 +1,31 @@ -{ pkgs, ... }: { - file = (pkgs.formats.ini { }).generate "KeydJetbrainsConfig" { - "jetbrains-*" = { - "alt./" = "C-/"; # Toggle comment. - "alt.." = "C-f8"; # Toggle line breakpoint. - "alt.equal" = "C-A-l"; # Reformat. - "alt.c" = "S-escape"; # Close panel. - "alt.capslock" = "C-A-S-insert"; # New scratch file. - "alt.q" = "A-left"; # Prev tab. - "alt.e" = "A-right"; # Next tab. - "alt.x" = "C-f4"; # Close tab. - "alt.f" = "C-S-f"; # Find text. - "alt.n" = "C-A-n"; # Find next. - "alt.g" = "macro(gd)"; # Go to definition. - "alt.i" = "C-i"; # Implement. - "alt.o" = "C-o"; # Override. - "alt.r" = "S-f10"; # Run. - "alt.z" = "C-f2"; # Stop app. - "alt.d" = "S-f9"; # Run debugger. - "alt.a" = "C-A-5"; # Attach debugger. - "alt.m" = "C-A-s"; # Settings. - "alt.v" = "C-q"; # Show doc under cursor. - "alt.s" = "C-S-A-t"; # Refactor selection. + pkgs, + ... +}: { + file = (pkgs.formats.ini { }).generate "KeydJetbrainsConfig" { + "jetbrains-*" = { + "alt./" = "C-/"; # Toggle comment. + "alt.." = "C-f8"; # Toggle line breakpoint. + "alt.equal" = "C-A-l"; # Reformat. + "alt.c" = "S-escape"; # Close panel. + "alt.capslock" = "C-A-S-insert"; # New scratch file. + "alt.q" = "A-left"; # Prev tab. + "alt.e" = "A-right"; # Next tab. + "alt.x" = "C-f4"; # Close tab. + "alt.f" = "C-S-f"; # Find text. + "alt.n" = "C-A-n"; # Find next. + "alt.g" = "macro(gd)"; # Go to definition. + "alt.i" = "C-i"; # Implement. + "alt.o" = "C-o"; # Override. + "alt.r" = "S-f10"; # Run. + "alt.z" = "C-f2"; # Stop app. + "alt.d" = "S-f9"; # Run debugger. + "alt.a" = "C-A-5"; # Attach debugger. + "alt.m" = "C-A-s"; # Settings. + "alt.v" = "C-q"; # Show doc under cursor. + "alt.s" = "C-S-A-t"; # Refactor selection. - "alt.tab" = "timeout(f8, 150, macro2(0, 0, f7))"; # Tap to step over, hold to step into. - }; - }; + "alt.tab" = "timeout(f8, 150, macro2(0, 0, f7))"; # Tap to step over, hold to step into. + }; + }; } diff --git a/home/config/keyd/module/Nautilus.nix b/home/config/keyd/module/Nautilus.nix index 01bd7fb..8002a77 100644 --- a/home/config/keyd/module/Nautilus.nix +++ b/home/config/keyd/module/Nautilus.nix @@ -1,27 +1,29 @@ -{ pkgs, ... }: { - file = (pkgs.formats.ini { }).generate "KeydNautilusConfig" { - "org-gnome-nautilus" = { - "alt.capslock" = "C-t"; # New tab. - "alt.t" = "C-n"; # New window. - "alt.x" = "C-w"; # Close tab. - "alt.u" = "C-S-t"; # Restore tab. - "alt.e" = "C-pagedown"; # Next tab. - "alt.q" = "C-pageup"; # Prev tab. - "alt.E" = "C-S-pagedown"; # Move tab next. - "alt.Q" = "C-S-pageup"; # Move tab prev. - "alt.h" = "C-h"; # Toggle hidden files. - "alt.1" = "C-1"; # List view. - "alt.2" = "C-2"; # Grid view. - "alt.b" = "A-up"; # Go back. - "alt.space" = "C-l"; # Focus location bar. - "alt.i" = "C-S-i"; # Invert selection. - "alt.v" = "C-i"; # File info. - "alt.d" = "C-S-delete"; # Delete file. - "alt.s" = "f2"; # Rename. - "alt.a" = "C-S-n"; # Create dir. - "alt.f" = "C-f"; # Search dir. - "alt.r" = "f5"; # Refresh dir. - }; - }; + pkgs, + ... +}: { + file = (pkgs.formats.ini { }).generate "KeydNautilusConfig" { + "org-gnome-nautilus" = { + "alt.capslock" = "C-t"; # New tab. + "alt.t" = "C-n"; # New window. + "alt.x" = "C-w"; # Close tab. + "alt.u" = "C-S-t"; # Restore tab. + "alt.e" = "C-pagedown"; # Next tab. + "alt.q" = "C-pageup"; # Prev tab. + "alt.E" = "C-S-pagedown"; # Move tab next. + "alt.Q" = "C-S-pageup"; # Move tab prev. + "alt.h" = "C-h"; # Toggle hidden files. + "alt.1" = "C-1"; # List view. + "alt.2" = "C-2"; # Grid view. + "alt.b" = "A-up"; # Go back. + "alt.space" = "C-l"; # Focus location bar. + "alt.i" = "C-S-i"; # Invert selection. + "alt.v" = "C-i"; # File info. + "alt.d" = "C-S-delete"; # Delete file. + "alt.s" = "f2"; # Rename. + "alt.a" = "C-S-n"; # Create dir. + "alt.f" = "C-f"; # Search dir. + "alt.r" = "f5"; # Refresh dir. + }; + }; } diff --git a/home/config/mako/default.nix b/home/config/mako/default.nix index 72d7ac2..15c5b33 100644 --- a/home/config/mako/default.nix +++ b/home/config/mako/default.nix @@ -1,28 +1,28 @@ -{ pkgs, config, ... }: -let - alpha = config.style.opacity.hex; -in { - file = (pkgs.formats.iniWithGlobalSection { }).generate "MakoConfig" { - globalSection = let - color = config.style.color; - in { - anchor = "top-center"; - background-color = "#${color.hl}${alpha}"; - border-color = "#${color.border}${alpha}"; - default-timeout = 10000; - font = "${config.style.font.serif.name} ${toString config.style.font.size.popup}"; - height = 120; - icons = 0; - margin = 32; - text-color = "#${config.style.color.fg.light}"; - width = 480; - }; - - sections = { - "mode=dnd" = { - invisible = 1; - }; - }; - }; + pkgs, + config, + ... +}: let + alpha = config.module.style.opacity.hex; + color = config.module.style.color; +in { + file = (pkgs.formats.iniWithGlobalSection { }).generate "MakoConfig" { + globalSection = { + anchor = "top-center"; + background-color = "#${color.selection}${alpha}"; + border-color = "#${color.border}${alpha}"; + default-timeout = 10000; + font = "${config.module.style.font.serif.name} ${toString config.module.style.font.size.popup}"; + height = 120; + icons = 0; + margin = 32; + text-color = "#${config.module.style.color.fg.dark}"; + width = 480; + }; + sections = { + "mode=dnd" = { + invisible = 1; + }; + }; + }; } diff --git a/home/config/mangohud/default.nix b/home/config/mangohud/default.nix index e1a52ee..c253d32 100644 --- a/home/config/mangohud/default.nix +++ b/home/config/mangohud/default.nix @@ -1,45 +1,45 @@ -{ pkgs, ... }: { - config = (pkgs.formats.iniWithGlobalSection { }).generate "MangoConfig" { - globalSection = { - blacklist = "example"; - fps_sampling_period = 1000; - frame_timing = 0; - preset = "0,1,2"; - toggle_logging = "F2"; - toggle_preset = "F1"; - }; - }; + pkgs, + ... +}: { + config = (pkgs.formats.iniWithGlobalSection { }).generate "MangoConfig" { + globalSection = { + blacklist = "example"; + fps_sampling_period = 1000; + frame_timing = 0; + preset = "0,1,2"; + toggle_logging = "F2"; + toggle_preset = "F1"; + }; + }; - presets = (pkgs.formats.ini { }).generate "MangoPresets" { - "preset 0" = { - no_display = 1; - }; - - "preset 1" = { - alpha = 1.0; - arch = 0; - background_alpha = 0.5; - battery = 1; - battery_time = 1; - benchmark_percentiles = 0; - cpu_temp = 1; - device_battery = "gamepad,mouse"; - font_size = 12; - fps_sampling_period = 1000; - gpu_junction_temp = 0; - gpu_mem_temp = 1; - gpu_temp = 1; - hud_no_margin = 1; - ram = 1; - swap = 1; - throttling_status = 1; - time = 1; - vram = 1; - }; - - "preset 2" = { - full = 1; - }; - }; + presets = (pkgs.formats.ini { }).generate "MangoPresets" { + "preset 0" = { + no_display = 1; + }; + "preset 1" = { + alpha = 1.0; + arch = 0; + background_alpha = 0.5; + battery = 1; + battery_time = 1; + benchmark_percentiles = 0; + cpu_temp = 1; + device_battery = "gamepad,mouse"; + font_size = 12; + fps_sampling_period = 1000; + gpu_junction_temp = 0; + gpu_mem_temp = 1; + gpu_temp = 1; + hud_no_margin = 1; + ram = 1; + swap = 1; + throttling_status = 1; + time = 1; + vram = 1; + }; + "preset 2" = { + full = 1; + }; + }; } diff --git a/home/config/nvim/default.nix b/home/config/nvim/default.nix index 33e5f9e..52fcb8c 100644 --- a/home/config/nvim/default.nix +++ b/home/config/nvim/default.nix @@ -1,96 +1,93 @@ { - inputs, - pkgs, - util, - ... -}@args: -let - # Create Neovim configuration. - nvimRc = - { runtimes, configs }: - let - # Plugin paths to install. - runtimeRc = builtins.foldl' (acc: r: acc + "set runtimepath+=${r}\n") "" runtimes; + inputs, + pkgs, + util, + ... +} @args: let + nvimRc = { runtimes, configs }: let + # Plugin paths to install. + runtimeRc = builtins.foldl' (acc: r: + acc + "set runtimepath+=${r}\n" + ) "" runtimes; - # My configuration files combined into one big file. - config = pkgs.writeText "nvimRc" (util.catText configs args); + # My configuration files combined into one big file. + config = pkgs.writeText "nvimRc" (util.catText configs args); - # Tell Neovim to load this file. - configRc = "lua dofile(\"${config}\")"; - in - runtimeRc + configRc; -in -{ - text = nvimRc { - runtimes = [ - "~/.cache/nvim" - "~/.cache/nvim/treesitter" - "${inputs.nvimAlign}" - "${inputs.nvimAutoclose}" - "${inputs.nvimBufferline}" - "${inputs.nvimCloseBuffers}" - "${inputs.nvimColorizer}" - "${inputs.nvimDevicons}" - "${inputs.nvimDressing}" - "${inputs.nvimGen}" - "${inputs.nvimGitsigns}" - "${inputs.nvimGruvboxMaterial}" - "${inputs.nvimIndentoMatic}" - "${inputs.nvimLspconfig}" - "${inputs.nvimPlenary}" - "${inputs.nvimTelescope}" - "${inputs.nvimTodo}" - "${inputs.nvimTreesitter}" - "${inputs.nvimTree}" - "${inputs.nvimTrouble}" - ]; + # Tell Neovim to load this file. + configRc = "lua dofile(\"${config}\")"; + in + runtimeRc + configRc; +in { + text = nvimRc { + runtimes = [ + "~/.cache/nvim" + "~/.cache/nvim/treesitter" + "${inputs.nvimAlign}" + "${inputs.nvimAutoclose}" + "${inputs.nvimBufferline}" + "${inputs.nvimCloseBuffers}" + "${inputs.nvimColorizer}" + "${inputs.nvimDevicons}" + "${inputs.nvimDressing}" + "${inputs.nvimGen}" + "${inputs.nvimGitsigns}" + "${inputs.nvimGruvboxMaterial}" + "${inputs.nvimIndentoMatic}" + "${inputs.nvimLspconfig}" + "${inputs.nvimPlenary}" + "${inputs.nvimTelescope}" + "${inputs.nvimTodo}" + "${inputs.nvimTreesitter}" + "${inputs.nvimTree}" + "${inputs.nvimTrouble}" + ]; - configs = [ - ./module/key/Rekey.nix - ./module/key/Leader.nix - ./module/config/Autoread.nix - ./module/config/Etc.nix - ./module/config/Search.nix - ./module/config/Tab.nix - ./module/config/Highlight.nix - ./module/config/Notify.nix - ./module/plugin/Filetree.nix - ./module/plugin/Gruvbox.nix - ./module/plugin/Bufferline.nix - ./module/plugin/Autoclose.nix - ./module/plugin/Gitsigns.nix - ./module/plugin/Trouble.nix - ./module/plugin/Closebuffers.nix - ./module/plugin/Telescope.nix - ./module/plugin/Todo.nix - ./module/plugin/Indent.nix - ./module/plugin/Align.nix - ./module/plugin/Treesitter.nix - ./module/plugin/Fold.nix - ./module/plugin/Gen.nix - ./module/plugin/Colorizer.nix - ./module/plugin/Dressing.nix - ./module/plugin/lsp/Go.nix - ./module/plugin/lsp/Haskell.nix - ./module/plugin/lsp/Lua.nix - ./module/plugin/lsp/Nix.nix - ./module/plugin/lsp/Rust.nix - ./module/plugin/lsp/Tex.nix - ./module/key/Autocomplete.nix - ./module/key/Buffer.nix - ./module/key/Cmd.nix - ./module/key/Colorscheme.nix - ./module/key/Comment.nix - ./module/key/Filetree.nix - ./module/key/Gitsigns.nix - ./module/key/Navigation.nix - ./module/key/Prompt.nix - ./module/key/Save.nix - ./module/key/Sort.nix - ./module/key/TabWidth.nix - ./module/key/Telescope.nix - ./module/key/Terminal.nix - ./module/key/Trouble.nix - ]; - }; + configs = [ + ./module/key/Rekey.nix + ./module/key/Leader.nix + ./module/config/Autoread.nix + ./module/config/Etc.nix + ./module/config/Search.nix + ./module/config/Tab.nix + ./module/config/Highlight.nix + ./module/config/Notify.nix + ./module/plugin/Filetree.nix + ./module/plugin/Gruvbox.nix + ./module/plugin/Bufferline.nix + ./module/plugin/Autoclose.nix + ./module/plugin/Gitsigns.nix + ./module/plugin/Trouble.nix + ./module/plugin/Closebuffers.nix + ./module/plugin/Telescope.nix + ./module/plugin/Todo.nix + ./module/plugin/Indent.nix + ./module/plugin/Align.nix + ./module/plugin/Treesitter.nix + ./module/plugin/Fold.nix + ./module/plugin/Gen.nix + ./module/plugin/Colorizer.nix + ./module/plugin/Dressing.nix + ./module/plugin/lsp/Go.nix + ./module/plugin/lsp/Haskell.nix + ./module/plugin/lsp/Lua.nix + ./module/plugin/lsp/Nix.nix + ./module/plugin/lsp/Rust.nix + ./module/plugin/lsp/Tex.nix + ./module/key/Autocomplete.nix + ./module/key/Buffer.nix + ./module/key/Cmd.nix + ./module/key/Colorscheme.nix + ./module/key/Comment.nix + ./module/key/Filetree.nix + ./module/key/Gitsigns.nix + ./module/key/Navigation.nix + ./module/key/Prompt.nix + ./module/key/Save.nix + ./module/key/Sort.nix + ./module/key/TabWidth.nix + ./module/key/Telescope.nix + ./module/key/Terminal.nix + ./module/key/Trouble.nix + ]; + }; } diff --git a/home/config/nvim/module/config/Autoread.nix b/home/config/nvim/module/config/Autoread.nix index 54c04f8..d62589e 100644 --- a/home/config/nvim/module/config/Autoread.nix +++ b/home/config/nvim/module/config/Autoread.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - vim.o.autoread = true - vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "CursorHoldI", "FocusGained" }, { - command = "if mode() != 'c' | checktime | endif", - pattern = { "*" }, - }) - ''; +{ ... }: { + text = '' + vim.o.autoread = true + vim.api.nvim_create_autocmd({ "BufEnter", "CursorHold", "CursorHoldI", "FocusGained" }, { + command = "if mode() != 'c' | checktime | endif", + pattern = { "*" }, + }) + ''; } diff --git a/home/config/nvim/module/config/Etc.nix b/home/config/nvim/module/config/Etc.nix index 34ff0ca..86134cf 100644 --- a/home/config/nvim/module/config/Etc.nix +++ b/home/config/nvim/module/config/Etc.nix @@ -1,37 +1,36 @@ -{ ... }: -{ - text = '' - -- TODO: Add comments and separate files. - vim.opt.clipboard = "unnamedplus" - vim.opt.cursorline = false - vim.opt.fixeol = false - vim.opt.incsearch = true - vim.opt.number = true - vim.opt.scrolloff = 4 - vim.opt.splitbelow = true - vim.opt.splitright = true - vim.opt.termguicolors = true - vim.opt.ttyfast = true - vim.opt.wildmode = "longest,list" - -- vim.opt.completeopt = "menuone,noselect" +{ ... }: { + text = '' + -- TODO: Add comments and separate files. + vim.opt.clipboard = "unnamedplus" + vim.opt.cursorline = false + vim.opt.fixeol = false + vim.opt.incsearch = true + vim.opt.number = true + vim.opt.scrolloff = 4 + vim.opt.splitbelow = true + vim.opt.splitright = true + vim.opt.termguicolors = true + vim.opt.ttyfast = true + vim.opt.wildmode = "longest,list" + -- vim.opt.completeopt = "menuone,noselect" - -- Disable continuing comments on newline. - vim.cmd("autocmd BufEnter * set fo-=c fo-=r fo-=o") + -- Disable continuing comments on newline. + vim.cmd("autocmd BufEnter * set fo-=c fo-=r fo-=o") - -- Disable mouse. - vim.cmd("set mouse=") + -- Disable mouse. + vim.cmd("set mouse=") - -- Disable signs for diagnostics. - vim.diagnostic.config({ signs = false }) + -- Disable signs for diagnostics. + vim.diagnostic.config({ signs = false }) - -- Display invisible characters. - -- vim.cmd("set list listchars=tab:>\\ ,trail:-,eol:,lead:.") - vim.cmd("set list listchars=tab:>\\ ,trail:-,lead:·") + -- Display invisible characters. + -- vim.cmd("set list listchars=tab:>\\ ,trail:-,eol:,lead:.") + vim.cmd("set list listchars=tab:>\\ ,trail:-,lead:·") - -- Relative line numbers. - vim.wo.relativenumber = true + -- Relative line numbers. + vim.wo.relativenumber = true - -- Disable swap files. - vim.opt.swapfile = false - ''; + -- Disable swap files. + vim.opt.swapfile = false + ''; } diff --git a/home/config/nvim/module/config/Highlight.nix b/home/config/nvim/module/config/Highlight.nix index 5a30e2a..c419c2e 100644 --- a/home/config/nvim/module/config/Highlight.nix +++ b/home/config/nvim/module/config/Highlight.nix @@ -1,56 +1,49 @@ -{ config, lib, ... }: -let - color = config.style.color; - - mkHighlight = - name: value: - ''vim.api.nvim_set_hl(0, "${name}", ${ - lib.generators.toLua { - multiline = false; - asBindings = false; - } value - })''; - - bg = { - bg = "#${color.bg.regular}"; - }; - selection = { - bg = "#${color.selection}"; - fg = "#${color.fg.dark}"; - bold = true; - }; - transparent = { - bg = lib.generators.mkLuaInline "clear"; - }; - border = { - bg = lib.generators.mkLuaInline "clear"; - fg = "#${color.accent}"; - }; -in { - text = '' - vim.api.nvim_create_autocmd({"ColorScheme", "VimEnter"}, { - group = vim.api.nvim_create_augroup('Color', {}), - pattern = "*", - callback = function () - -- Background. - ${mkHighlight "CursorLine" bg} - ${mkHighlight "Pmenu" bg} - ${mkHighlight "PmenuExtra" bg} + config, + lib, + ... +}: let + color = config.module.style.color; + mkHighlight = name: value: ''vim.api.nvim_set_hl(0, "${name}", ${lib.generators.toLua { multiline = false; asBindings = false; } value})''; + bg = { + bg = "#${color.bg.regular}"; + }; + selection = { + bg = "#${color.selection}"; + bold = true; + fg = "#${color.fg.dark}"; + }; + transparent = { + bg = lib.generators.mkLuaInline "clear"; + }; + border = { + bg = lib.generators.mkLuaInline "clear"; + fg = "#${color.accent}"; + }; +in { + text = '' + vim.api.nvim_create_autocmd({"ColorScheme", "VimEnter"}, { + group = vim.api.nvim_create_augroup('Color', {}), + pattern = "*", + callback = function () + -- Background. + ${mkHighlight "CursorLine" bg} + ${mkHighlight "Pmenu" bg} + ${mkHighlight "PmenuExtra" bg} - -- Selection. - ${mkHighlight "Visual" selection} - ${mkHighlight "PmenuSel" selection} - ${mkHighlight "TelescopeSelection" selection} + -- Selection. + ${mkHighlight "Visual" selection} + ${mkHighlight "PmenuSel" selection} + ${mkHighlight "TelescopeSelection" selection} - -- Transparent. - ${mkHighlight "NormalFloat" transparent} + -- Transparent. + ${mkHighlight "NormalFloat" transparent} - -- Border. - ${mkHighlight "FloatBorder" border} - ${mkHighlight "FloatTitle" border} - ${mkHighlight "TelescopeBorder" border} - end - }) - ''; + -- Border. + ${mkHighlight "FloatBorder" border} + ${mkHighlight "FloatTitle" border} + ${mkHighlight "TelescopeBorder" border} + end + }) + ''; } diff --git a/home/config/nvim/module/config/Notify.nix b/home/config/nvim/module/config/Notify.nix index 6b0190b..5a38740 100644 --- a/home/config/nvim/module/config/Notify.nix +++ b/home/config/nvim/module/config/Notify.nix @@ -1,19 +1,18 @@ -{ ... }: -{ - text = '' - -- Disable error messages popup. - -- Instead print them and write to system journal. - bequiet = function(msg, log_level, opts) - print(string.sub(tostring(msg), 1, vim.v.echospace)) +{ ... }: { + text = '' + -- Disable error messages popup. + -- Instead print them and write to system journal. + bequiet = function(msg, log_level, opts) + print(string.sub(tostring(msg), 1, vim.v.echospace)) - local log = io.popen("systemd-cat -t nvim", "w") - log:write(tostring(msg)) - log:close() - end + local log = io.popen("systemd-cat -t nvim", "w") + log:write(tostring(msg)) + log:close() + end - vim.notify = bequiet - vim.api.nvim_out_write = bequiet - vim.api.nvim_err_write = bequiet - vim.api.nvim_err_writeln = bequiet - ''; + vim.notify = bequiet + vim.api.nvim_out_write = bequiet + vim.api.nvim_err_write = bequiet + vim.api.nvim_err_writeln = bequiet + ''; } diff --git a/home/config/nvim/module/config/Search.nix b/home/config/nvim/module/config/Search.nix index 21842a3..5731e34 100644 --- a/home/config/nvim/module/config/Search.nix +++ b/home/config/nvim/module/config/Search.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - vim.opt.hlsearch = true - vim.opt.ignorecase = true - vim.opt.incsearch = true - vim.opt.showmatch = true - vim.opt.smartcase = true - ''; +{ ... }: { + text = '' + vim.opt.hlsearch = true + vim.opt.ignorecase = true + vim.opt.incsearch = true + vim.opt.showmatch = true + vim.opt.smartcase = true + ''; } diff --git a/home/config/nvim/module/config/Tab.nix b/home/config/nvim/module/config/Tab.nix index 4db277c..1dfaffb 100644 --- a/home/config/nvim/module/config/Tab.nix +++ b/home/config/nvim/module/config/Tab.nix @@ -1,17 +1,15 @@ -{ ... }: -let - indentDefault = 2; -in -{ - text = '' - vim.opt.autoindent = true - vim.opt.expandtab = false - -- vim.opt.smartindent = true - vim.opt.shiftwidth = ${toString indentDefault} - vim.opt.softtabstop = ${toString indentDefault} - vim.opt.tabstop = ${toString indentDefault} +{ ... }: let + indentDefault = 2; +in { + text = '' + vim.opt.autoindent = true + vim.opt.expandtab = false + -- vim.opt.smartindent = true + vim.opt.shiftwidth = ${toString indentDefault} + vim.opt.softtabstop = ${toString indentDefault} + vim.opt.tabstop = ${toString indentDefault} - -- Disable Markdown forced formatting. - vim.g.markdown_recommended_style = 0 - ''; + -- Disable Markdown forced formatting. + vim.g.markdown_recommended_style = 0 + ''; } diff --git a/home/config/nvim/module/key/Autocomplete.nix b/home/config/nvim/module/key/Autocomplete.nix index 9765db1..2ca8502 100644 --- a/home/config/nvim/module/key/Autocomplete.nix +++ b/home/config/nvim/module/key/Autocomplete.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - -- Autocomplete. - rekey_input("", "") +{ ... }: { + text = '' + -- Autocomplete. + rekey_input("", "") - -- LSP autocomplete. - rekey_normal("", "lua vim.lsp.buf.code_action()") - ''; + -- LSP autocomplete. + rekey_normal("", "lua vim.lsp.buf.code_action()") + ''; } diff --git a/home/config/nvim/module/key/Buffer.nix b/home/config/nvim/module/key/Buffer.nix index 4e468a8..7c29a87 100644 --- a/home/config/nvim/module/key/Buffer.nix +++ b/home/config/nvim/module/key/Buffer.nix @@ -1,17 +1,16 @@ -{ ... }: -{ - text = '' - -- New empty buffer. - remap_normal("n", "enew") +{ ... }: { + text = '' + -- New empty buffer. + remap_normal("n", "enew") - -- Close buffer. - function _buf_close() - pcall(vim.cmd, "w") - vim.cmd[[bp|sp|bn|bd!]] - end - rekey_normal("x", "lua _buf_close()") + -- Close buffer. + function _buf_close() + pcall(vim.cmd, "w") + vim.cmd[[bp|sp|bn|bd!]] + end + rekey_normal("x", "lua _buf_close()") - -- Close all hidden buffers. - rekey_normal("X", "BDelete hidden") - ''; + -- Close all hidden buffers. + rekey_normal("X", "BDelete hidden") + ''; } diff --git a/home/config/nvim/module/key/Cmd.nix b/home/config/nvim/module/key/Cmd.nix index acc11f0..01138e0 100644 --- a/home/config/nvim/module/key/Cmd.nix +++ b/home/config/nvim/module/key/Cmd.nix @@ -1,12 +1,11 @@ -{ ... }: -{ - text = '' - -- Remap ; to :. - rekey_normal(";", ":") - rekey_visual(";", ":") +{ ... }: { + text = '' + -- Remap ; to :. + rekey_normal(";", ":") + rekey_visual(";", ":") - -- Repeat previous command. - rekey_normal(".", "@:") - rekey_visual(".", "@:") - ''; + -- Repeat previous command. + rekey_normal(".", "@:") + rekey_visual(".", "@:") + ''; } diff --git a/home/config/nvim/module/key/Colorscheme.nix b/home/config/nvim/module/key/Colorscheme.nix index 98e76bb..3f92dda 100644 --- a/home/config/nvim/module/key/Colorscheme.nix +++ b/home/config/nvim/module/key/Colorscheme.nix @@ -1,27 +1,26 @@ -{ ... }: -{ - text = '' - function toggle_contrast() - if vim.g.gruvbox_material_background == "light" then - vim.g.gruvbox_material_background = "medium" - elseif vim.g.gruvbox_material_background == "medium" then - vim.g.gruvbox_material_background = "hard" - elseif vim.g.gruvbox_material_background == "hard" then - vim.g.gruvbox_material_background = "light" - end - vim.cmd("colorscheme gruvbox-material") - end +{ ... }: { + text = '' + function toggle_contrast() + if vim.g.gruvbox_material_background == "light" then + vim.g.gruvbox_material_background = "medium" + elseif vim.g.gruvbox_material_background == "medium" then + vim.g.gruvbox_material_background = "hard" + elseif vim.g.gruvbox_material_background == "hard" then + vim.g.gruvbox_material_background = "light" + end + vim.cmd("colorscheme gruvbox-material") + end - function toggle_light() - if vim.o.background == "light" then - vim.o.background = "dark" - elseif vim.o.background == "dark" then - vim.o.background = "light" - end - -- require("lualine").setup() - end + function toggle_light() + if vim.o.background == "light" then + vim.o.background = "dark" + elseif vim.o.background == "dark" then + vim.o.background = "light" + end + -- require("lualine").setup() + end - rekey_normal("[", "lua toggle_contrast()") - rekey_normal("]", "lua toggle_light()") - ''; + rekey_normal("[", "lua toggle_contrast()") + rekey_normal("]", "lua toggle_light()") + ''; } diff --git a/home/config/nvim/module/key/Comment.nix b/home/config/nvim/module/key/Comment.nix index 0c5c4a6..d13ffa7 100644 --- a/home/config/nvim/module/key/Comment.nix +++ b/home/config/nvim/module/key/Comment.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - remap_normal("/", "gcc") - remap_visual("/", "gc") - ''; +{ ... }: { + text = '' + remap_normal("/", "gcc") + remap_visual("/", "gc") + ''; } diff --git a/home/config/nvim/module/key/Filetree.nix b/home/config/nvim/module/key/Filetree.nix index f0cb68a..a9847d8 100644 --- a/home/config/nvim/module/key/Filetree.nix +++ b/home/config/nvim/module/key/Filetree.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - -- Toggle file tree. - rekey_normal("1", "NvimTreeToggle") - ''; +{ ... }: { + text = '' + -- Toggle file tree. + rekey_normal("1", "NvimTreeToggle") + ''; } diff --git a/home/config/nvim/module/key/Gitsigns.nix b/home/config/nvim/module/key/Gitsigns.nix index bbd4190..d6192e3 100644 --- a/home/config/nvim/module/key/Gitsigns.nix +++ b/home/config/nvim/module/key/Gitsigns.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - -- Toggle Git inspection mode. - rekey_normal("g", "Gitsigns toggle_current_line_blameGitsigns toggle_word_diffGitsigns toggle_linehl") - ''; +{ ... }: { + text = '' + -- Toggle Git inspection mode. + rekey_normal("g", "Gitsigns toggle_current_line_blameGitsigns toggle_word_diffGitsigns toggle_linehl") + ''; } diff --git a/home/config/nvim/module/key/Leader.nix b/home/config/nvim/module/key/Leader.nix index 50b832f..625e37c 100644 --- a/home/config/nvim/module/key/Leader.nix +++ b/home/config/nvim/module/key/Leader.nix @@ -1,12 +1,11 @@ -{ ... }: -{ - text = '' - leader = " " +{ ... }: { + text = '' + leader = " " - vim.g.mapleader = leader - vim.g.maplocalleader = leader + vim.g.mapleader = leader + vim.g.maplocalleader = leader - -- Disable key press timeout. - vim.cmd("set notimeout nottimeout") - ''; + -- Disable key press timeout. + vim.cmd("set notimeout nottimeout") + ''; } diff --git a/home/config/nvim/module/key/Navigation.nix b/home/config/nvim/module/key/Navigation.nix index f8ffc90..b7021cc 100644 --- a/home/config/nvim/module/key/Navigation.nix +++ b/home/config/nvim/module/key/Navigation.nix @@ -1,38 +1,36 @@ -{ ... }: -let - stepVertical = 2; - stepHorizontal = 4; -in -{ - text = '' - -- Switch windows. - rekey_normal("a", "h") - rekey_normal("d", "l") - rekey_normal("s", "j") - rekey_normal("w", "k") +{ ... }: let + stepHorizontal = 4; + stepVertical = 2; +in { + text = '' + -- Switch windows. + rekey_normal("a", "h") + rekey_normal("d", "l") + rekey_normal("s", "j") + rekey_normal("w", "k") - -- Switch buffers. - rekey_normal("E", "BufferLineMoveNext") - rekey_normal("Q", "BufferLineMovePrev") - rekey_normal("e", "BufferLineCycleNext") - rekey_normal("q", "BufferLineCyclePrev") + -- Switch buffers. + rekey_normal("E", "BufferLineMoveNext") + rekey_normal("Q", "BufferLineMovePrev") + rekey_normal("e", "BufferLineCycleNext") + rekey_normal("q", "BufferLineCyclePrev") - -- Splits. - rekey_normal("\\", "vsplit") - rekey_normal("-", "split") - rekey_normal("=", "=") -- Equalize split sizes. - rekey_normal("c", "q") -- Close split. + -- Splits. + rekey_normal("\\", "vsplit") + rekey_normal("-", "split") + rekey_normal("=", "=") -- Equalize split sizes. + rekey_normal("c", "q") -- Close split. - -- Resize splits. - rekey_normal("h", "${toString stepHorizontal}<") - rekey_normal("l", "${toString stepHorizontal}>") - rekey_normal("j", "${toString stepVertical}+") - rekey_normal("k", "${toString stepVertical}-") + -- Resize splits. + rekey_normal("h", "${toString stepHorizontal}<") + rekey_normal("l", "${toString stepHorizontal}>") + rekey_normal("j", "${toString stepVertical}+") + rekey_normal("k", "${toString stepVertical}-") - -- Move splits. - rekey_normal("A", "A") - rekey_normal("D", "D") - rekey_normal("S", "S") - rekey_normal("W", "W") - ''; + -- Move splits. + rekey_normal("A", "A") + rekey_normal("D", "D") + rekey_normal("S", "S") + rekey_normal("W", "W") + ''; } diff --git a/home/config/nvim/module/key/Prompt.nix b/home/config/nvim/module/key/Prompt.nix index 86a567c..a295039 100644 --- a/home/config/nvim/module/key/Prompt.nix +++ b/home/config/nvim/module/key/Prompt.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - rekey_normal("p", ":Gen") - rekey_visual("p", ":Gen") - ''; +{ ... }: { + text = '' + rekey_normal("p", ":Gen") + rekey_visual("p", ":Gen") + ''; } diff --git a/home/config/nvim/module/key/Rekey.nix b/home/config/nvim/module/key/Rekey.nix index a12a2fe..00e052a 100644 --- a/home/config/nvim/module/key/Rekey.nix +++ b/home/config/nvim/module/key/Rekey.nix @@ -1,54 +1,53 @@ -{ ... }: -{ - text = '' - -- Base rekey function. - local function rekey(t, key, command) - vim.api.nvim_set_keymap(t, key, command, { noremap = true }) - end +{ ... }: { + text = '' + -- Base rekey function. + local function rekey(t, key, command) + vim.api.nvim_set_keymap(t, key, command, { noremap = true }) + end - -- Base remap function. - local function remap(t, key, command) - vim.api.nvim_set_keymap(t, key, command, { noremap = false }) - end + -- Base remap function. + local function remap(t, key, command) + vim.api.nvim_set_keymap(t, key, command, { noremap = false }) + end - -- Rekey in normal mode. - function rekey_normal(key, command) - rekey("n", key, command) - end + -- Rekey in normal mode. + function rekey_normal(key, command) + rekey("n", key, command) + end - -- Rekey in input mode. - function rekey_input(key, command) - rekey("i", key, command) - end + -- Rekey in input mode. + function rekey_input(key, command) + rekey("i", key, command) + end - -- Rekey in visual mode. - function rekey_visual(key, command) - rekey("v", key, command) - end + -- Rekey in visual mode. + function rekey_visual(key, command) + rekey("v", key, command) + end - -- Rekey in terminal mode. - function rekey_terminal(key, command) - rekey("t", key, command) - end + -- Rekey in terminal mode. + function rekey_terminal(key, command) + rekey("t", key, command) + end - -- Remap in normal mode. - function remap_normal(key, command) - remap("n", key, command) - end + -- Remap in normal mode. + function remap_normal(key, command) + remap("n", key, command) + end - -- Remap in input mode. - function remap_input(key, command) - remap("i", key, command) - end + -- Remap in input mode. + function remap_input(key, command) + remap("i", key, command) + end - -- Remap in visual mode. - function remap_visual(key, command) - remap("v", key, command) - end + -- Remap in visual mode. + function remap_visual(key, command) + remap("v", key, command) + end - -- Remap in terminal mode. - function remap_terminal(key, command) - remap("t", key, command) - end - ''; + -- Remap in terminal mode. + function remap_terminal(key, command) + remap("t", key, command) + end + ''; } diff --git a/home/config/nvim/module/key/Save.nix b/home/config/nvim/module/key/Save.nix index be1b72d..c7d3cba 100644 --- a/home/config/nvim/module/key/Save.nix +++ b/home/config/nvim/module/key/Save.nix @@ -1,20 +1,19 @@ -{ ... }: -{ - text = '' - -- Write all we can and exit. Created this to drop non-writable stuff when piping to nvim. - function bye() - pcall(vim.cmd, "wa") - vim.cmd[[qa!]] - end +{ ... }: { + text = '' + -- Write all we can and exit. Created this to drop non-writable stuff when piping to nvim. + function bye() + pcall(vim.cmd, "wa") + vim.cmd[[qa!]] + end - -- Save everything. - rekey_normal("", "wa!") - rekey_input("", "wa!") + -- Save everything. + rekey_normal("", "wa!") + rekey_input("", "wa!") - -- Save all we can and leave. - rekey_normal("z", "lua bye()") + -- Save all we can and leave. + rekey_normal("z", "lua bye()") - -- Just leave, no saves. - rekey_normal("Z", "qa!") - ''; + -- Just leave, no saves. + rekey_normal("Z", "qa!") + ''; } diff --git a/home/config/nvim/module/key/Sort.nix b/home/config/nvim/module/key/Sort.nix index 59e496a..d73396d 100644 --- a/home/config/nvim/module/key/Sort.nix +++ b/home/config/nvim/module/key/Sort.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - -- Sort visual selection alphabetically. - rekey_visual("A", ":'<,'>sort") - ''; +{ ... }: { + text = '' + -- Sort visual selection alphabetically. + rekey_visual("A", ":'<,'>sort") + ''; } diff --git a/home/config/nvim/module/key/TabWidth.nix b/home/config/nvim/module/key/TabWidth.nix index 6037dcb..741760a 100644 --- a/home/config/nvim/module/key/TabWidth.nix +++ b/home/config/nvim/module/key/TabWidth.nix @@ -1,22 +1,21 @@ -{ ... }: -{ - text = '' - function toggle_tab_width() - if vim.bo.shiftwidth == 2 then - vim.bo.shiftwidth = 4 - vim.bo.tabstop = 4 - vim.bo.softtabstop = 4 - elseif vim.bo.shiftwidth == 4 then - vim.bo.shiftwidth = 8 - vim.bo.tabstop = 8 - vim.bo.softtabstop = 8 - elseif vim.bo.shiftwidth == 8 then - vim.bo.shiftwidth = 2 - vim.bo.tabstop = 2 - vim.bo.softtabstop = 2 - end - end +{ ... }: { + text = '' + function toggle_tab_width() + if vim.bo.shiftwidth == 2 then + vim.bo.shiftwidth = 4 + vim.bo.tabstop = 4 + vim.bo.softtabstop = 4 + elseif vim.bo.shiftwidth == 4 then + vim.bo.shiftwidth = 8 + vim.bo.tabstop = 8 + vim.bo.softtabstop = 8 + elseif vim.bo.shiftwidth == 8 then + vim.bo.shiftwidth = 2 + vim.bo.tabstop = 2 + vim.bo.softtabstop = 2 + end + end - rekey_normal("", "lua toggle_tab_width()") - ''; + rekey_normal("", "lua toggle_tab_width()") + ''; } diff --git a/home/config/nvim/module/key/Telescope.nix b/home/config/nvim/module/key/Telescope.nix index 17f5c84..8c51331 100644 --- a/home/config/nvim/module/key/Telescope.nix +++ b/home/config/nvim/module/key/Telescope.nix @@ -1,14 +1,12 @@ -{ ... }: -let - mod = "f"; -in -{ - text = '' - rekey_normal("${mod}a", "Telescope") - rekey_normal("${mod}b", "lua require('telescope.builtin').buffers()") - rekey_normal("${mod}f", "lua require('telescope.builtin').find_files()") - rekey_normal("${mod}g", "lua require('telescope.builtin').live_grep()") - rekey_normal("${mod}h", "lua require('telescope.builtin').help_tags()") - rekey_normal("${mod}t", "Telescope treesitter") - ''; +{ ... }: let + mod = "f"; +in { + text = '' + rekey_normal("${mod}a", "Telescope") + rekey_normal("${mod}b", "lua require('telescope.builtin').buffers()") + rekey_normal("${mod}f", "lua require('telescope.builtin').find_files()") + rekey_normal("${mod}g", "lua require('telescope.builtin').live_grep()") + rekey_normal("${mod}h", "lua require('telescope.builtin').help_tags()") + rekey_normal("${mod}t", "Telescope treesitter") + ''; } diff --git a/home/config/nvim/module/key/Terminal.nix b/home/config/nvim/module/key/Terminal.nix index f41ba73..319fdd0 100644 --- a/home/config/nvim/module/key/Terminal.nix +++ b/home/config/nvim/module/key/Terminal.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - -- Open terminal window. - rekey_normal("4", "terminal") +{ ... }: { + text = '' + -- Open terminal window. + rekey_normal("4", "terminal") - -- Detach from terminal with Esc key. - rekey_terminal("", "") - ''; + -- Detach from terminal with Esc key. + rekey_terminal("", "") + ''; } diff --git a/home/config/nvim/module/key/Trouble.nix b/home/config/nvim/module/key/Trouble.nix index 06eb18c..5b1bd2d 100644 --- a/home/config/nvim/module/key/Trouble.nix +++ b/home/config/nvim/module/key/Trouble.nix @@ -1,13 +1,11 @@ -{ ... }: -let - focus = true; -in -{ - text = '' - -- Toggle diagnostics window. - rekey_normal("2", "Trouble diagnostics toggle focus=${toString focus}") +{ ... }: let + focus = true; +in { + text = '' + -- Toggle diagnostics window. + rekey_normal("2", "Trouble diagnostics toggle focus=${toString focus}") - -- Toggle To-do window. - rekey_normal("3", "Trouble todo toggle focus=${toString focus}") - ''; + -- Toggle To-do window. + rekey_normal("3", "Trouble todo toggle focus=${toString focus}") + ''; } diff --git a/home/config/nvim/module/plugin/Align.nix b/home/config/nvim/module/plugin/Align.nix index c23fd6c..76bc586 100644 --- a/home/config/nvim/module/plugin/Align.nix +++ b/home/config/nvim/module/plugin/Align.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - text = '' - require("mini.align").setup { - mappings = { - start = "a", - -- start_with_preview = 'A', - }, - } - ''; +{ ... }: { + text = '' + require("mini.align").setup { + mappings = { + start = "a", + -- start_with_preview = 'A', + }, + } + ''; } diff --git a/home/config/nvim/module/plugin/Autoclose.nix b/home/config/nvim/module/plugin/Autoclose.nix index c2c6487..28964c4 100644 --- a/home/config/nvim/module/plugin/Autoclose.nix +++ b/home/config/nvim/module/plugin/Autoclose.nix @@ -1,18 +1,17 @@ -{ ... }: -{ - text = '' - require("autoclose").setup({ - keys = { - ["'"] = { escape = false, close = false, pair = "''''''", disabled_filetypes = {} }, - ["("] = { escape = true, close = true, pair = "()", disabled_filetypes = {} }, - ["<"] = { escape = true, close = true, pair = "<>", disabled_filetypes = {} }, - ["\""] = { escape = true, close = true, pair = "\"\"", disabled_filetypes = {} }, - ["`"] = { escape = true, close = true, pair = "``", disabled_filetypes = {} }, - ["{"] = { escape = true, close = true, pair = "{}", disabled_filetypes = {} }, - }, - -- options = { - -- disabled_filetypes = { "text", "markdown" }, - -- } - }) - ''; +{ ... }: { + text = '' + require("autoclose").setup({ + keys = { + ["'"] = { escape = false, close = false, pair = "''''''", disabled_filetypes = {} }, + ["("] = { escape = true, close = true, pair = "()", disabled_filetypes = {} }, + ["<"] = { escape = true, close = true, pair = "<>", disabled_filetypes = {} }, + ["\""] = { escape = true, close = true, pair = "\"\"", disabled_filetypes = {} }, + ["`"] = { escape = true, close = true, pair = "``", disabled_filetypes = {} }, + ["{"] = { escape = true, close = true, pair = "{}", disabled_filetypes = {} }, + }, + -- options = { + -- disabled_filetypes = { "text", "markdown" }, + -- } + }) + ''; } diff --git a/home/config/nvim/module/plugin/Bufferline.nix b/home/config/nvim/module/plugin/Bufferline.nix index 0339f53..13bb09a 100644 --- a/home/config/nvim/module/plugin/Bufferline.nix +++ b/home/config/nvim/module/plugin/Bufferline.nix @@ -1,6 +1,5 @@ -{ ... }: -{ - text = '' - require("bufferline").setup() - ''; +{ ... }: { + text = '' + require("bufferline").setup() + ''; } diff --git a/home/config/nvim/module/plugin/Closebuffers.nix b/home/config/nvim/module/plugin/Closebuffers.nix index 6736b05..3aa1f0a 100644 --- a/home/config/nvim/module/plugin/Closebuffers.nix +++ b/home/config/nvim/module/plugin/Closebuffers.nix @@ -1,12 +1,11 @@ -{ ... }: -{ - text = '' - require("close_buffers").setup({ - file_glob_ignore = {}, - file_regex_ignore = {}, - filetype_ignore = {}, - next_buffer_cmd = nil, - preserve_window_layout = { "this", "nameless" }, - }) - ''; +{ ... }: { + text = '' + require("close_buffers").setup({ + file_glob_ignore = {}, + file_regex_ignore = {}, + filetype_ignore = {}, + next_buffer_cmd = nil, + preserve_window_layout = { "this", "nameless" }, + }) + ''; } diff --git a/home/config/nvim/module/plugin/Colorizer.nix b/home/config/nvim/module/plugin/Colorizer.nix index 33c47e8..1554f84 100644 --- a/home/config/nvim/module/plugin/Colorizer.nix +++ b/home/config/nvim/module/plugin/Colorizer.nix @@ -1,9 +1,8 @@ -{ ... }: -{ - text = '' - -- Ensure termguicolors is enabled if not already - vim.opt.termguicolors = true +{ ... }: { + text = '' + -- Ensure termguicolors is enabled if not already + vim.opt.termguicolors = true - require('nvim-highlight-colors').setup({}) - ''; + require('nvim-highlight-colors').setup({}) + ''; } diff --git a/home/config/nvim/module/plugin/Dressing.nix b/home/config/nvim/module/plugin/Dressing.nix index 1f50c94..e48d2d8 100644 --- a/home/config/nvim/module/plugin/Dressing.nix +++ b/home/config/nvim/module/plugin/Dressing.nix @@ -1,6 +1,5 @@ -{ ... }: -{ - text = '' - require("dressing").setup({ }) - ''; +{ ... }: { + text = '' + require("dressing").setup({ }) + ''; } diff --git a/home/config/nvim/module/plugin/Filetree.nix b/home/config/nvim/module/plugin/Filetree.nix index 20c99b9..7acbc96 100644 --- a/home/config/nvim/module/plugin/Filetree.nix +++ b/home/config/nvim/module/plugin/Filetree.nix @@ -1,41 +1,40 @@ -{ ... }: -{ - text = '' - -- Disable netrw at the very start of your init.lua. - vim.g.loaded_netrw = 1 - vim.g.loaded_netrwPlugin = 1 +{ ... }: { + text = '' + -- Disable netrw at the very start of your init.lua. + vim.g.loaded_netrw = 1 + vim.g.loaded_netrwPlugin = 1 - local function my_on_attach(bufnr) - local api = require "nvim-tree.api" + local function my_on_attach(bufnr) + local api = require "nvim-tree.api" - local function opts(desc) - return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } - end + local function opts(desc) + return { desc = "nvim-tree: " .. desc, buffer = bufnr, noremap = true, silent = true, nowait = true } + end - -- Default mappings. - api.config.mappings.default_on_attach(bufnr) + -- Default mappings. + api.config.mappings.default_on_attach(bufnr) - -- Custom mappings. - -- vim.keymap.set('n', '', api.tree.change_root_to_node, opts('Cd into')) - end + -- Custom mappings. + -- vim.keymap.set('n', '', api.tree.change_root_to_node, opts('Cd into')) + end - -- Set termguicolors to enable highlight groups. - vim.opt.termguicolors = true + -- Set termguicolors to enable highlight groups. + vim.opt.termguicolors = true - -- Setup nvim-tree. - require("nvim-tree").setup({ - on_attach = my_on_attach, - sort_by = "case_sensitive", - view = { - width = 30, - }, - renderer = { - group_empty = true, - }, - filters = { - dotfiles = false, - git_ignored = false - }, - }) - ''; + -- Setup nvim-tree. + require("nvim-tree").setup({ + on_attach = my_on_attach, + sort_by = "case_sensitive", + view = { + width = 30, + }, + renderer = { + group_empty = true, + }, + filters = { + dotfiles = false, + git_ignored = false + }, + }) + ''; } diff --git a/home/config/nvim/module/plugin/Fold.nix b/home/config/nvim/module/plugin/Fold.nix index e10ae3c..b67202c 100644 --- a/home/config/nvim/module/plugin/Fold.nix +++ b/home/config/nvim/module/plugin/Fold.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - vim.opt.foldexpr = "nvim_treesitter#foldexpr()" - vim.opt.foldlevel = 99 - vim.opt.foldmethod = "expr" - ''; +{ ... }: { + text = '' + vim.opt.foldexpr = "nvim_treesitter#foldexpr()" + vim.opt.foldlevel = 99 + vim.opt.foldmethod = "expr" + ''; } diff --git a/home/config/nvim/module/plugin/Gen.nix b/home/config/nvim/module/plugin/Gen.nix index 0f55d57..7d741eb 100644 --- a/home/config/nvim/module/plugin/Gen.nix +++ b/home/config/nvim/module/plugin/Gen.nix @@ -1,8 +1,10 @@ -{ config, ... }: { - text = '' - require("gen").setup { - model = "${config.setting.ollama.primaryModel}" - } - ''; + config, + ... +}: { + text = '' + require("gen").setup { + model = "${config.module.ollama.primaryModel}" + } + ''; } diff --git a/home/config/nvim/module/plugin/Gitsigns.nix b/home/config/nvim/module/plugin/Gitsigns.nix index ed357c7..dfa413f 100644 --- a/home/config/nvim/module/plugin/Gitsigns.nix +++ b/home/config/nvim/module/plugin/Gitsigns.nix @@ -1,45 +1,44 @@ -{ ... }: -{ - text = '' - require("gitsigns").setup { - signs = { - add = { text = "│" }, - change = { text = "│" }, - changedelete = { text = "~" }, - delete = { text = "_" }, - topdelete = { text = "‾" }, - untracked = { text = "┆" }, - }, - linehl = false, - numhl = true, - signcolumn = false, - word_diff = false, - watch_gitdir = { - follow_files = true, - }, - attach_to_untracked = true, - current_line_blame = false, - current_line_blame_opts = { - delay = 1000, - ignore_whitespace = false, - virt_text = true, - virt_text_pos = "eol", - }, - current_line_blame_formatter = ", - ", - max_file_length = 40000, - sign_priority = 6, - status_formatter = nil, - update_debounce = 100, - preview_config = { - border = "single", - col = 1, - relative = "cursor", - row = 0, - style = "minimal", - }, - } +{ ... }: { + text = '' + require("gitsigns").setup { + signs = { + add = { text = "│" }, + change = { text = "│" }, + changedelete = { text = "~" }, + delete = { text = "_" }, + topdelete = { text = "‾" }, + untracked = { text = "┆" }, + }, + linehl = false, + numhl = true, + signcolumn = false, + word_diff = false, + watch_gitdir = { + follow_files = true, + }, + attach_to_untracked = true, + current_line_blame = false, + current_line_blame_opts = { + delay = 1000, + ignore_whitespace = false, + virt_text = true, + virt_text_pos = "eol", + }, + current_line_blame_formatter = ", - ", + max_file_length = 40000, + sign_priority = 6, + status_formatter = nil, + update_debounce = 100, + preview_config = { + border = "single", + col = 1, + relative = "cursor", + row = 0, + style = "minimal", + }, + } - -- Set custom color. - vim.cmd("highlight gitsignscurrentlineblame guibg=#00000000 guifg=#aaaaaa") - ''; + -- Set custom color. + vim.cmd("highlight gitsignscurrentlineblame guibg=#00000000 guifg=#aaaaaa") + ''; } diff --git a/home/config/nvim/module/plugin/Gruvbox.nix b/home/config/nvim/module/plugin/Gruvbox.nix index 01edadf..16e338d 100644 --- a/home/config/nvim/module/plugin/Gruvbox.nix +++ b/home/config/nvim/module/plugin/Gruvbox.nix @@ -1,20 +1,19 @@ -{ ... }: -{ - text = '' - vim.cmd([[ - if has('termguicolors') - set termguicolors - endif - ]]) +{ ... }: { + text = '' + vim.cmd([[ + if has('termguicolors') + set termguicolors + endif + ]]) - vim.o.background = "dark" - vim.g.gruvbox_material_background = "medium" - vim.g.gruvbox_material_foreground = "original" - vim.g.gruvbox_material_transparent_background = 2 - -- vim.g.gruvbox_material_better_performance = 1 -- NOTE: Broken on NixOS. + vim.o.background = "dark" + vim.g.gruvbox_material_background = "medium" + vim.g.gruvbox_material_foreground = "original" + vim.g.gruvbox_material_transparent_background = 2 + -- vim.g.gruvbox_material_better_performance = 1 -- NOTE: Broken on NixOS. - -- vim.cmd("autocmd ColorScheme * highlight Normal ctermbg=NONE guibg=NONE") - vim.cmd("colorscheme gruvbox-material") - vim.cmd("let g:lightline = {'colorscheme' : 'gruvbox_material'}") - ''; + -- vim.cmd("autocmd ColorScheme * highlight Normal ctermbg=NONE guibg=NONE") + vim.cmd("colorscheme gruvbox-material") + vim.cmd("let g:lightline = {'colorscheme' : 'gruvbox_material'}") + ''; } diff --git a/home/config/nvim/module/plugin/Indent.nix b/home/config/nvim/module/plugin/Indent.nix index e944139..58280ca 100644 --- a/home/config/nvim/module/plugin/Indent.nix +++ b/home/config/nvim/module/plugin/Indent.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - text = '' - -- Auto-detect indentation type. - require("indent-o-matic").setup { - max_lines = 1024, - skip_multiline = true, - standard_widths = { 2, 4, 8 }, - } - ''; +{ ... }: { + text = '' + -- Auto-detect indentation type. + require("indent-o-matic").setup { + max_lines = 1024, + skip_multiline = true, + standard_widths = { 2, 4, 8 }, + } + ''; } diff --git a/home/config/nvim/module/plugin/Init.nix b/home/config/nvim/module/plugin/Init.nix index 74d8e33..b85ed58 100644 --- a/home/config/nvim/module/plugin/Init.nix +++ b/home/config/nvim/module/plugin/Init.nix @@ -1,54 +1,53 @@ -{ ... }: -{ - text = '' - local ensure_packer = function() - local fn = vim.fn - local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim" - if fn.empty(fn.glob(install_path)) > 0 then - fn.system({"git", "clone", "--depth", "1", "https://git.voronind.com/mirror/packer.nvim.git", install_path}) - vim.cmd [[packadd packer.nvim]] - return true - end - return false - end +{ ... }: { + text = '' + local ensure_packer = function() + local fn = vim.fn + local install_path = fn.stdpath("data").."/site/pack/packer/start/packer.nvim" + if fn.empty(fn.glob(install_path)) > 0 then + fn.system({"git", "clone", "--depth", "1", "https://git.voronind.com/mirror/packer.nvim.git", install_path}) + vim.cmd [[packadd packer.nvim]] + return true + end + return false + end - local packer_bootstrap = ensure_packer() + local packer_bootstrap = ensure_packer() - local available = function(commands) - for _, command in ipairs(commands) do - if vim.fn.executable(command) ~= 1 then - return false - end - end - return true - end + local available = function(commands) + for _, command in ipairs(commands) do + if vim.fn.executable(command) ~= 1 then + return false + end + end + return true + end - return require("packer").startup(function(use) - use "https://git.voronind.com/mirror/SingleComment.nvim.git" - use "https://git.voronind.com/mirror/autoclose.nvim.git" - use "https://git.voronind.com/mirror/bufferline.nvim.git" - use "https://git.voronind.com/mirror/close-buffers.nvim.git" - use "https://git.voronind.com/mirror/gitsigns.nvim.git" - use "https://git.voronind.com/mirror/gruvbox-material.git" - use "https://git.voronind.com/mirror/indent-o-matic.git" - use "https://git.voronind.com/mirror/lualine.nvim.git" - use "https://git.voronind.com/mirror/mini.align.git" - use "https://git.voronind.com/mirror/nvim-lspconfig.git" - use "https://git.voronind.com/mirror/nvim-tree.lua.git" - use "https://git.voronind.com/mirror/nvim-treesitter.git" - use "https://git.voronind.com/mirror/nvim-web-devicons.git" - use "https://git.voronind.com/mirror/packer.nvim.git" - use "https://git.voronind.com/mirror/plenary.nvim.git" - use "https://git.voronind.com/mirror/telescope.nvim.git" - use "https://git.voronind.com/mirror/todo-comments.nvim.git" - use "https://git.voronind.com/mirror/tokyonight.nvim.git" - use "https://git.voronind.com/mirror/trouble.nvim.git" - use "https://git.voronind.com/mirror/which-key.nvim.git" + return require("packer").startup(function(use) + use "https://git.voronind.com/mirror/SingleComment.nvim.git" + use "https://git.voronind.com/mirror/autoclose.nvim.git" + use "https://git.voronind.com/mirror/bufferline.nvim.git" + use "https://git.voronind.com/mirror/close-buffers.nvim.git" + use "https://git.voronind.com/mirror/gitsigns.nvim.git" + use "https://git.voronind.com/mirror/gruvbox-material.git" + use "https://git.voronind.com/mirror/indent-o-matic.git" + use "https://git.voronind.com/mirror/lualine.nvim.git" + use "https://git.voronind.com/mirror/mini.align.git" + use "https://git.voronind.com/mirror/nvim-lspconfig.git" + use "https://git.voronind.com/mirror/nvim-tree.lua.git" + use "https://git.voronind.com/mirror/nvim-treesitter.git" + use "https://git.voronind.com/mirror/nvim-web-devicons.git" + use "https://git.voronind.com/mirror/packer.nvim.git" + use "https://git.voronind.com/mirror/plenary.nvim.git" + use "https://git.voronind.com/mirror/telescope.nvim.git" + use "https://git.voronind.com/mirror/todo-comments.nvim.git" + use "https://git.voronind.com/mirror/tokyonight.nvim.git" + use "https://git.voronind.com/mirror/trouble.nvim.git" + use "https://git.voronind.com/mirror/which-key.nvim.git" - -- Auto-install. - if packer_bootstrap then - require("packer").sync() - end - end) - ''; + -- Auto-install. + if packer_bootstrap then + require("packer").sync() + end + end) + ''; } diff --git a/home/config/nvim/module/plugin/Telescope.nix b/home/config/nvim/module/plugin/Telescope.nix index 3524d95..9c27059 100644 --- a/home/config/nvim/module/plugin/Telescope.nix +++ b/home/config/nvim/module/plugin/Telescope.nix @@ -1,17 +1,16 @@ -{ ... }: -{ - text = '' - require("telescope").setup{ - defaults = { - mappings = { - i = { - [""] = "move_selection_previous", - [""] = "move_selection_next", - }, - }, - }, - extensions = { }, - pickers = { }, - } - ''; +{ ... }: { + text = '' + require("telescope").setup{ + defaults = { + mappings = { + i = { + [""] = "move_selection_previous", + [""] = "move_selection_next", + }, + }, + }, + extensions = { }, + pickers = { }, + } + ''; } diff --git a/home/config/nvim/module/plugin/Todo.nix b/home/config/nvim/module/plugin/Todo.nix index 970bbbb..e6bc820 100644 --- a/home/config/nvim/module/plugin/Todo.nix +++ b/home/config/nvim/module/plugin/Todo.nix @@ -1,56 +1,55 @@ -{ ... }: -{ - text = '' - require("todo-comments").setup { - sign_priority = 8, - signs = false, - keywords = { - FIX = { icon = " ", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, }, - HACK = { icon = " ", color = "warning", alt = { "WTF", "LOL", "KEKW" } }, - LINK = { icon = "󰌷 ", color = "info", alt = { "REF", "SEE", "MORE", "ALSO", "SOURCE", "SRC" } }, - NOTE = { icon = "󰎚 ", color = "hint", alt = { "INFO" } }, - PERF = { icon = " ", color = "default", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, - TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, - TODO = { icon = " ", color = "info", alt = { "LATER", "FUTURE", "ROADMAP" }}, - WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, - WIP = { icon = " ", color = "warning", alt = { "PROGRESS" } }, - }, - gui_style = { - bg = "BOLD", - fg = "NONE", - }, - merge_keywords = true, - highlight = { - after = "fg", - before = "", - comments_only = true, - exclude = {}, - keyword = "wide", - max_line_len = 400, - multiline = true, - multiline_context = 10, - multiline_pattern = "^.", - pattern = [[.*<(KEYWORDS)\s*:]], - }, - colors = { - default = { "Identifier", "#7C3AED" }, - error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, - hint = { "DiagnosticHint", "#10B981" }, - info = { "DiagnosticInfo", "#2563EB" }, - test = { "Identifier", "#FF00FF" }, - warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, - }, - search = { - command = "rg", - args = { - "--color=never", - "--no-heading", - "--with-filename", - "--line-number", - "--column", - }, - pattern = [[\b(KEYWORDS):]], - }, - } - ''; +{ ... }: { + text = '' + require("todo-comments").setup { + sign_priority = 8, + signs = false, + keywords = { + FIX = { icon = " ", color = "error", alt = { "FIXME", "BUG", "FIXIT", "ISSUE" }, }, + HACK = { icon = " ", color = "warning", alt = { "WTF", "LOL", "KEKW" } }, + LINK = { icon = "󰌷 ", color = "info", alt = { "REF", "SEE", "MORE", "ALSO", "SOURCE", "SRC" } }, + NOTE = { icon = "󰎚 ", color = "hint", alt = { "INFO" } }, + PERF = { icon = " ", color = "default", alt = { "OPTIM", "PERFORMANCE", "OPTIMIZE" } }, + TEST = { icon = "⏲ ", color = "test", alt = { "TESTING", "PASSED", "FAILED" } }, + TODO = { icon = " ", color = "info", alt = { "LATER", "FUTURE", "ROADMAP" }}, + WARN = { icon = " ", color = "warning", alt = { "WARNING", "XXX" } }, + WIP = { icon = " ", color = "warning", alt = { "PROGRESS" } }, + }, + gui_style = { + bg = "BOLD", + fg = "NONE", + }, + merge_keywords = true, + highlight = { + after = "fg", + before = "", + comments_only = true, + exclude = {}, + keyword = "wide", + max_line_len = 400, + multiline = true, + multiline_context = 10, + multiline_pattern = "^.", + pattern = [[.*<(KEYWORDS)\s*:]], + }, + colors = { + default = { "Identifier", "#7C3AED" }, + error = { "DiagnosticError", "ErrorMsg", "#DC2626" }, + hint = { "DiagnosticHint", "#10B981" }, + info = { "DiagnosticInfo", "#2563EB" }, + test = { "Identifier", "#FF00FF" }, + warning = { "DiagnosticWarn", "WarningMsg", "#FBBF24" }, + }, + search = { + command = "rg", + args = { + "--color=never", + "--no-heading", + "--with-filename", + "--line-number", + "--column", + }, + pattern = [[\b(KEYWORDS):]], + }, + } + ''; } diff --git a/home/config/nvim/module/plugin/Treesitter.nix b/home/config/nvim/module/plugin/Treesitter.nix index 4655911..c711d7c 100644 --- a/home/config/nvim/module/plugin/Treesitter.nix +++ b/home/config/nvim/module/plugin/Treesitter.nix @@ -1,26 +1,25 @@ -{ ... }: -{ - text = '' - require("nvim-treesitter.configs").setup { - parser_install_dir = "~/.cache/nvim/treesitter", - auto_install = true, - -- ensure_installed = "all", - sync_install = false, - highlight = { - additional_vim_regex_highlighting = false, - enable = true, - use_languagetree = true, - disable = { "lua" }, - }, - indent = { - enable = true, - }, - autotag = { - enable = true - }, - rainbow = { - enable = true - }, - } - ''; +{ ... }: { + text = '' + require("nvim-treesitter.configs").setup { + parser_install_dir = "~/.cache/nvim/treesitter", + auto_install = true, + -- ensure_installed = "all", + sync_install = false, + highlight = { + additional_vim_regex_highlighting = false, + enable = true, + use_languagetree = true, + disable = { "lua" }, + }, + indent = { + enable = true, + }, + autotag = { + enable = true + }, + rainbow = { + enable = true + }, + } + ''; } diff --git a/home/config/nvim/module/plugin/Trouble.nix b/home/config/nvim/module/plugin/Trouble.nix index f2f04fc..73da358 100644 --- a/home/config/nvim/module/plugin/Trouble.nix +++ b/home/config/nvim/module/plugin/Trouble.nix @@ -1,6 +1,5 @@ -{ ... }: -{ - text = '' - require("trouble").setup() - ''; +{ ... }: { + text = '' + require("trouble").setup() + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Go.nix b/home/config/nvim/module/plugin/lsp/Go.nix index a78a641..7fdadd0 100644 --- a/home/config/nvim/module/plugin/lsp/Go.nix +++ b/home/config/nvim/module/plugin/lsp/Go.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.gopls.setup {} - ''; + lspconfig.gopls.setup {} + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Haskell.nix b/home/config/nvim/module/plugin/lsp/Haskell.nix index fb312fc..676fbcd 100644 --- a/home/config/nvim/module/plugin/lsp/Haskell.nix +++ b/home/config/nvim/module/plugin/lsp/Haskell.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.hls.setup { - filetypes = { 'haskell', 'lhaskell', 'cabal' }, - } - ''; + lspconfig.hls.setup { + filetypes = { 'haskell', 'lhaskell', 'cabal' }, + } + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Kotlin.nix b/home/config/nvim/module/plugin/lsp/Kotlin.nix index 089145c..5c71fbe 100644 --- a/home/config/nvim/module/plugin/lsp/Kotlin.nix +++ b/home/config/nvim/module/plugin/lsp/Kotlin.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.kotlin_language_server.setup {} - ''; + lspconfig.kotlin_language_server.setup {} + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Lua.nix b/home/config/nvim/module/plugin/lsp/Lua.nix index 325d1a6..8aba464 100644 --- a/home/config/nvim/module/plugin/lsp/Lua.nix +++ b/home/config/nvim/module/plugin/lsp/Lua.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.lua_ls.setup {} - ''; + lspconfig.lua_ls.setup {} + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Nix.nix b/home/config/nvim/module/plugin/lsp/Nix.nix index 9a12516..de8d4ce 100644 --- a/home/config/nvim/module/plugin/lsp/Nix.nix +++ b/home/config/nvim/module/plugin/lsp/Nix.nix @@ -1,18 +1,17 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.nixd.setup({ - settings = { - nixd = { - diagnostic = { - suppress = { - "sema-escaping-with" - }, - }, - }, - }, - }) - ''; + lspconfig.nixd.setup({ + settings = { + nixd = { + diagnostic = { + suppress = { + "sema-escaping-with" + }, + }, + }, + }, + }) + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Python.nix b/home/config/nvim/module/plugin/lsp/Python.nix index 650f444..7019fbc 100644 --- a/home/config/nvim/module/plugin/lsp/Python.nix +++ b/home/config/nvim/module/plugin/lsp/Python.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.pyright.setup {} - ''; + lspconfig.pyright.setup {} + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Rust.nix b/home/config/nvim/module/plugin/lsp/Rust.nix index 141cac1..f9cc4c6 100644 --- a/home/config/nvim/module/plugin/lsp/Rust.nix +++ b/home/config/nvim/module/plugin/lsp/Rust.nix @@ -1,21 +1,20 @@ -{ ... }: -{ - text = '' - local lspconfig = require("lspconfig") +{ ... }: { + text = '' + local lspconfig = require("lspconfig") - lspconfig.rust_analyzer.setup { - settings = { - ["rust-analyzer"] = { - rustfmt = { - extraArgs = { - "--config", - "hard_tabs=true", - } - } - }, - }, - } + lspconfig.rust_analyzer.setup { + settings = { + ["rust-analyzer"] = { + rustfmt = { + extraArgs = { + "--config", + "hard_tabs=true", + } + } + }, + }, + } - vim.g.rust_recommended_style = false - ''; + vim.g.rust_recommended_style = false + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Tex.nix b/home/config/nvim/module/plugin/lsp/Tex.nix index 8cef79d..783eefd 100644 --- a/home/config/nvim/module/plugin/lsp/Tex.nix +++ b/home/config/nvim/module/plugin/lsp/Tex.nix @@ -1,65 +1,64 @@ -{ ... }: -{ - text = '' - local lspconfig = require('lspconfig') - local config = { - filetypes = { - "bib", - "gitcommit", - "markdown", - "org", - "pandoc", - "plaintex", - "rnoweb", - "rst", - "tex", - "text", - }, - settings = { - ["ltex"] = { - language = "auto" - } - } - } +{ ... }: { + text = '' + local lspconfig = require('lspconfig') + local config = { + filetypes = { + "bib", + "gitcommit", + "markdown", + "org", + "pandoc", + "plaintex", + "rnoweb", + "rst", + "tex", + "text", + }, + settings = { + ["ltex"] = { + language = "auto" + } + } + } - lspconfig.ltex.setup(config) + lspconfig.ltex.setup(config) - -- Use TeX LSP for spellcheck. - vim.api.nvim_create_user_command("SCOn", function (args) - lspconfig.ltex.setup(config) - end, { desc = "Enable spellcheck." }) + -- Use TeX LSP for spellcheck. + vim.api.nvim_create_user_command("SCOn", function (args) + lspconfig.ltex.setup(config) + end, { desc = "Enable spellcheck." }) - vim.api.nvim_create_user_command("SCOff", function (args) - lspconfig.ltex.setup { filetypes = {} } - end, { desc = "Disable spellcheck." }) + vim.api.nvim_create_user_command("SCOff", function (args) + lspconfig.ltex.setup { filetypes = {} } + end, { desc = "Disable spellcheck." }) - vim.api.nvim_create_user_command("SCLangRU", function (args) - config.settings['ltex'].language = "ru-RU" - lspconfig.ltex.setup(config) - end, { desc = "Set spellcheck to Russian." }) + vim.api.nvim_create_user_command("SCLangRU", function (args) + config.settings['ltex'].language = "ru-RU" + lspconfig.ltex.setup(config) + end, { desc = "Set spellcheck to Russian." }) - vim.api.nvim_create_user_command("SCLangEN", function (args) - config.settings['ltex'].language = "en-US" - lspconfig.ltex.setup(config) - end, { desc = "Set spellcheck to English." }) + vim.api.nvim_create_user_command("SCLangEN", function (args) + config.settings['ltex'].language = "en-US" + lspconfig.ltex.setup(config) + end, { desc = "Set spellcheck to English." }) - vim.api.nvim_create_user_command("SCLangAuto", function (args) - config.settings['ltex'].language = "auto" - lspconfig.ltex.setup(config) - end, { desc = "Set spellcheck to Auto." }) + vim.api.nvim_create_user_command("SCLangAuto", function (args) + config.settings['ltex'].language = "auto" + lspconfig.ltex.setup(config) + end, { desc = "Set spellcheck to Auto." }) - vim.api.nvim_create_user_command("SCForce", function (args) - vim.cmd("setfiletype text") - vim.cmd("SCOn") - end, { desc = "Set buffer type to text." }) + vim.api.nvim_create_user_command("SCForce", function (args) + vim.cmd("setfiletype text") + vim.cmd("SCOn") + end, { desc = "Set buffer type to text." }) - vim.api.nvim_create_user_command("SCReset", function (args) - vim.cmd("filetype detect") - vim.cmd("SCLangAuto") - end, { desc = "Set buffer type to auto." }) + vim.api.nvim_create_user_command("SCReset", function (args) + vim.cmd("filetype detect") + vim.cmd("SCLangAuto") + end, { desc = "Set buffer type to auto." }) - vim.api.nvim_create_user_command("SCInfo", function (args) - vim.cmd("LspInfo") - end, { desc = "Show info about spellcheck." }) - ''; + vim.api.nvim_create_user_command("SCInfo", function (args) + vim.cmd("LspInfo") + end, { desc = "Show info about spellcheck." }) + ''; } diff --git a/home/config/ssh/default.nix b/home/config/ssh/default.nix index 86c74c1..8425406 100644 --- a/home/config/ssh/default.nix +++ b/home/config/ssh/default.nix @@ -1,31 +1,28 @@ -# SSH client configuration. -{ ... }: -let - mkHost = - name: address: port: user: extra: - '' - Host ${name} - HostName ${address} - User ${user} - Port ${toString port} - '' - + extra; -in { - text = - '' - Host * - ControlMaster auto - ControlPath ~/.ssh/%r@%h:%p.socket - ControlPersist yes - '' - + mkHost "dasha" "10.0.0.7" 22143 "root" "" - + mkHost "desktop" "10.0.0.3" 22143 "root" "" - + mkHost "fmpmaven" "10.30.22.10" 22 "root" "" - + mkHost "home" "10.0.0.1" 22143 "root" "" - + mkHost "laptop" "192.168.1.9" 22143 "root" "" - + mkHost "nixbuilder" "10.0.0.1" 22143 "nixbuilder" "" - + mkHost "pi" "192.168.1.6" 22143 "root" "" - + mkHost "vpn" "194.113.233.38" 22143 "root" "" - + mkHost "work" "192.168.1.5" 22143 "root" ""; + util, + ... +}: let + mkHost = name: address: port: user: (util.trimTabs '' + Host ${name} + HostName ${address} + User ${user} + Port ${toString port} + ''); +in { + text = (util.trimTabs '' + Host * + ControlMaster auto + ControlPath ~/.ssh/%r@%h:%p.socket + ControlPersist yes + '') + + mkHost "dasha" "10.0.0.7" 22143 "root" + + mkHost "desktop" "10.0.0.3" 22143 "root" + + mkHost "fmpmaven" "10.30.22.10" 22 "root" + + mkHost "home" "10.0.0.1" 22143 "root" + + mkHost "laptop" "192.168.1.9" 22143 "root" + + mkHost "nixbuilder" "10.0.0.1" 22143 "nixbuilder" + + mkHost "pi" "192.168.1.6" 22143 "root" + + mkHost "vpn" "194.113.233.38" 22143 "root" + + mkHost "work" "192.168.1.5" 22143 "root" + ; } diff --git a/home/config/swappy/default.nix b/home/config/swappy/default.nix index 84c786c..c1b36e6 100644 --- a/home/config/swappy/default.nix +++ b/home/config/swappy/default.nix @@ -1,15 +1,18 @@ -{ pkgs, config, ... }: { - config = (pkgs.formats.ini { }).generate "SwappyConfig" { - Default = { - custom_color = with config.style.color; "rgba(${accent-r},${accent-g},${accent-b},1)"; - early_exit = true; - fill_shape = false; - line_size = 4; - paint_mode = "arrow"; - show_panel = false; - text_font = config.style.font.serif.name; - text_size = config.style.font.size.popup; - }; - }; + pkgs, + config, + ... +}: { + config = (pkgs.formats.ini { }).generate "SwappyConfig" { + Default = { + custom_color = with config.module.style.color; "rgba(${accent-r},${accent-g},${accent-b},1)"; + early_exit = true; + fill_shape = false; + line_size = 4; + paint_mode = "arrow"; + show_panel = false; + text_font = config.module.style.font.serif.name; + text_size = config.module.style.font.size.popup; + }; + }; } diff --git a/home/config/sway/default.nix b/home/config/sway/default.nix index d60d2f1..30e96fe 100644 --- a/home/config/sway/default.nix +++ b/home/config/sway/default.nix @@ -1,36 +1,37 @@ -{ util, config, ... }@args: -let - # Order is required for Sway configuration. - swayRc = util.catText [ - ./module/Mod.nix - ./module/Style.nix - ./module/Display.nix - ./module/Input.nix - ./module/Font.nix - ./module/Launcher.nix - ./module/Terminal.nix - ./module/TitleBar.nix - ./module/Navigation.nix - ./module/Notification.nix - ./module/Resize.nix - ./module/ScratchPad.nix - ./module/Screenshot.nix - ./module/Sound.nix - ./module/Tiling.nix - ./module/Workspace.nix - ./module/Session.nix - ./module/Keyd.nix - ./module/Waybar.nix - ./module/System.nix - ./module/Mouse.nix - ] args; -in { - text = - '' - # Read `man 5 sway` for a complete reference. - include /etc/sway/config.d/* - '' - + swayRc - + config.module.desktop.sway.extraConfig or ""; + util, + config, + ... +} @args: let + swayRc = util.catText [ + ./module/Mod.nix + ./module/Style.nix + ./module/Display.nix + ./module/Input.nix + ./module/Font.nix + ./module/Launcher.nix + ./module/Terminal.nix + ./module/TitleBar.nix + ./module/Navigation.nix + ./module/Notification.nix + ./module/Resize.nix + ./module/ScratchPad.nix + ./module/Screenshot.nix + ./module/Sound.nix + ./module/Tiling.nix + ./module/Workspace.nix + ./module/Session.nix + ./module/Keyd.nix + ./module/Waybar.nix + ./module/System.nix + ./module/Mouse.nix + ] args; +in { + text = (util.trimTabs '' + # Read `man 5 sway` for a complete reference. + include /etc/sway/config.d/* + '') + + swayRc + + config.module.desktop.sway.extraConfig or "" + ; } diff --git a/home/config/sway/module/Display.nix b/home/config/sway/module/Display.nix index 94f33b7..405067b 100644 --- a/home/config/sway/module/Display.nix +++ b/home/config/sway/module/Display.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - # You can get the names of your outputs by running: swaymsg -t get_outputs - output * scale 1 - ''; +{ ... }: { + text = '' + # You can get the names of your outputs by running: swaymsg -t get_outputs + output * scale 1 + ''; } diff --git a/home/config/sway/module/Font.nix b/home/config/sway/module/Font.nix index fae64f0..2b66999 100644 --- a/home/config/sway/module/Font.nix +++ b/home/config/sway/module/Font.nix @@ -1,10 +1,10 @@ -{ config, ... }: -let - fontName = config.style.font.sansSerif.name; -in -# fontSize = toString config.style.font.size.desktop; { - text = '' - font "${fontName} Medium 0.01" - ''; + config, + ... +}: let + fontName = config.module.style.font.sansSerif.name; +in { + text = '' + font "${fontName} Medium 0.01" + ''; } diff --git a/home/config/sway/module/Input.nix b/home/config/sway/module/Input.nix index 85ba0bf..3a048ce 100644 --- a/home/config/sway/module/Input.nix +++ b/home/config/sway/module/Input.nix @@ -1,47 +1,49 @@ -{ config, ... }: { - text = '' - ### Input configuration - # - # Example configuration: - # - # input "2:14:SynPS/2_Synaptics_TouchPad" { - # dwt enabled - # tap enabled - # natural_scroll enabled - # middle_emulation enabled - # } - # - # You can get the names of your inputs by running: swaymsg -t get_inputs - # Read `man 5 sway-input` for more information about this section. + config, + ... +}:{ + text = '' + ### Input configuration + # + # Example configuration: + # + # input "2:14:SynPS/2_Synaptics_TouchPad" { + # dwt enabled + # tap enabled + # natural_scroll enabled + # middle_emulation enabled + # } + # + # You can get the names of your inputs by running: swaymsg -t get_inputs + # Read `man 5 sway-input` for more information about this section. - input type:pointer { - accel_profile flat - pointer_accel 0 - dwt enabled - tap enabled - natural_scroll enabled - middle_emulation enabled - } + input type:pointer { + accel_profile flat + pointer_accel 0 + dwt enabled + tap enabled + natural_scroll enabled + middle_emulation enabled + } - input type:touchpad { - accel_profile flat - pointer_accel 0 - dwt enabled - tap enabled - natural_scroll enabled - middle_emulation enabled - } + input type:touchpad { + accel_profile flat + pointer_accel 0 + dwt enabled + tap enabled + natural_scroll enabled + middle_emulation enabled + } - input type:keyboard { - xkb_layout ${config.setting.keyboard.layouts} - xkb_options ${config.setting.keyboard.options} - } + input type:keyboard { + xkb_layout ${config.module.keyboard.layouts} + xkb_options ${config.module.keyboard.options} + } - # Hide mouse cursor after a period of inactivity. - seat seat0 hide_cursor 5000 + # Hide mouse cursor after a period of inactivity. + seat seat0 hide_cursor 5000 - # Per-window languages. - exec swaykbdd - ''; + # Per-window languages. + exec swaykbdd + ''; } diff --git a/home/config/sway/module/Keyd.nix b/home/config/sway/module/Keyd.nix index 7429d2e..6975b56 100644 --- a/home/config/sway/module/Keyd.nix +++ b/home/config/sway/module/Keyd.nix @@ -1,6 +1,5 @@ -{ ... }: -{ - text = '' - exec keyd-application-mapper -d - ''; +{ ... }: { + text = '' + exec keyd-application-mapper -d + ''; } diff --git a/home/config/sway/module/Launcher.nix b/home/config/sway/module/Launcher.nix index 82b9949..efc852f 100644 --- a/home/config/sway/module/Launcher.nix +++ b/home/config/sway/module/Launcher.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - text = '' - # Application launcher. - # Note: pass the final command to swaymsg so that the resulting window can be opened - # on the original workspace that the command was run on. - set $menu fuzzel +{ ... }: { + text = '' + # Application launcher. + # Note: pass the final command to swaymsg so that the resulting window can be opened + # on the original workspace that the command was run on. + set $menu fuzzel - bindsym $mod+space exec $menu - ''; + bindsym $mod+space exec $menu + ''; } diff --git a/home/config/sway/module/Mod.nix b/home/config/sway/module/Mod.nix index 0022441..82e040f 100644 --- a/home/config/sway/module/Mod.nix +++ b/home/config/sway/module/Mod.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - # Meta key. Use Mod1 for Alt. - set $mod Mod4 - ''; +{ ... }: { + text = '' + # Meta key. Use Mod1 for Alt. + set $mod Mod4 + ''; } diff --git a/home/config/sway/module/Mouse.nix b/home/config/sway/module/Mouse.nix index cb5c66f..b846df2 100644 --- a/home/config/sway/module/Mouse.nix +++ b/home/config/sway/module/Mouse.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - bindsym --whole-window $mod+button2 kill - bindsym --whole-window $mod+button8 floating toggle - bindsym --whole-window $mod+button9 fullscreen - ''; +{ ... }: { + text = '' + bindsym --whole-window $mod+button2 kill + bindsym --whole-window $mod+button8 floating toggle + bindsym --whole-window $mod+button9 fullscreen + ''; } diff --git a/home/config/sway/module/Navigation.nix b/home/config/sway/module/Navigation.nix index 361eb27..8eeb99e 100644 --- a/home/config/sway/module/Navigation.nix +++ b/home/config/sway/module/Navigation.nix @@ -1,19 +1,18 @@ -{ ... }: -{ - text = '' - # Move focus. - bindsym --to-code $mod+a focus left - bindsym --to-code $mod+d focus right - bindsym --to-code $mod+s focus down - bindsym --to-code $mod+w focus up +{ ... }: { + text = '' + # Move focus. + bindsym --to-code $mod+a focus left + bindsym --to-code $mod+d focus right + bindsym --to-code $mod+s focus down + bindsym --to-code $mod+w focus up - # Move the focused window. - bindsym --to-code $mod+Shift+a move left - bindsym --to-code $mod+Shift+d move right - bindsym --to-code $mod+Shift+s move down - bindsym --to-code $mod+Shift+w move up + # Move the focused window. + bindsym --to-code $mod+Shift+a move left + bindsym --to-code $mod+Shift+d move right + bindsym --to-code $mod+Shift+s move down + bindsym --to-code $mod+Shift+w move up - # Focus mouse following. - focus_follows_mouse yes - ''; + # Focus mouse following. + focus_follows_mouse yes + ''; } diff --git a/home/config/sway/module/Notification.nix b/home/config/sway/module/Notification.nix index 928e8fd..28e21b1 100644 --- a/home/config/sway/module/Notification.nix +++ b/home/config/sway/module/Notification.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - # Show last notification. - bindsym --to-code $mod+shift+n exec makoctl restore +{ ... }: { + text = '' + # Show last notification. + bindsym --to-code $mod+shift+n exec makoctl restore - # Hide all notifications. - bindsym --to-code $mod+n exec makoctl dismiss --all - ''; + # Hide all notifications. + bindsym --to-code $mod+n exec makoctl dismiss --all + ''; } diff --git a/home/config/sway/module/Resize.nix b/home/config/sway/module/Resize.nix index e826fd4..6519614 100644 --- a/home/config/sway/module/Resize.nix +++ b/home/config/sway/module/Resize.nix @@ -1,13 +1,11 @@ -{ ... }: -let - stepVertical = 10; - stepHorizontal = 10; -in -{ - text = '' - bindsym --to-code $mod+j resize grow height ${toString stepVertical}px - bindsym --to-code $mod+k resize shrink height ${toString stepVertical}px - bindsym --to-code $mod+h resize shrink width ${toString stepHorizontal}px - bindsym --to-code $mod+l resize grow width ${toString stepHorizontal}px - ''; +{ ... }: let + stepHorizontal = 10; + stepVertical = 10; +in { + text = '' + bindsym --to-code $mod+j resize grow height ${toString stepVertical}px + bindsym --to-code $mod+k resize shrink height ${toString stepVertical}px + bindsym --to-code $mod+h resize shrink width ${toString stepHorizontal}px + bindsym --to-code $mod+l resize grow width ${toString stepHorizontal}px + ''; } diff --git a/home/config/sway/module/ScratchPad.nix b/home/config/sway/module/ScratchPad.nix index 08239ef..a763261 100644 --- a/home/config/sway/module/ScratchPad.nix +++ b/home/config/sway/module/ScratchPad.nix @@ -1,54 +1,53 @@ -{ ... }: -{ - text = '' - # Sway has a "scratchpad", which is a bag of holding for windows. - # You can send windows there and get them back later. - # NOTE: Get id with `swaymsg -t get_tree`. +{ ... }: { + text = '' + # Sway has a "scratchpad", which is a bag of holding for windows. + # You can send windows there and get them back later. + # NOTE: Get id with `swaymsg -t get_tree`. - # Move the currently focused window to the scratchpad - bindsym $mod+shift+C move scratchpad + # Move the currently focused window to the scratchpad + bindsym $mod+shift+C move scratchpad - # Show the next scratchpad window or hide the focused scratchpad window. - # If there are multiple scratchpad windows, this command cycles through them. - bindsym $mod+c scratchpad show + # Show the next scratchpad window or hide the focused scratchpad window. + # If there are multiple scratchpad windows, this command cycles through them. + bindsym $mod+c scratchpad show - # Fix for a goddamn Firefox WebRTC indicator. - for_window [app_id="firefox" title="Firefox — Sharing Indicator"] { - kill - } + # Fix for a goddamn Firefox WebRTC indicator. + for_window [app_id="firefox" title="Firefox — Sharing Indicator"] { + kill + } - # NetworkManager. - for_window [app_id="nm-connection-editor"] { - move scratchpad - scratchpad show - } + # NetworkManager. + for_window [app_id="nm-connection-editor"] { + move scratchpad + scratchpad show + } - # Bluetooth. - for_window [app_id=".blueman-manager-wrapped"] { - move scratchpad - scratchpad show - } + # Bluetooth. + for_window [app_id=".blueman-manager-wrapped"] { + move scratchpad + scratchpad show + } - # Sound. - for_window [app_id="pavucontrol"] { - move scratchpad - scratchpad show - } + # Sound. + for_window [app_id="pavucontrol"] { + move scratchpad + scratchpad show + } - # Android emulator controls. - for_window [title="Emulator" window_type="utility"] { - move scratchpad - } + # Android emulator controls. + for_window [title="Emulator" window_type="utility"] { + move scratchpad + } - # Calculator. - for_window [app_id="org.gnome.Calculator"] { - move scratchpad - scratchpad show - } + # Calculator. + for_window [app_id="org.gnome.Calculator"] { + move scratchpad + scratchpad show + } - # JamesDsp. - for_window [title="JamesDSP for Linux"] { - move scratchpad - } - ''; + # JamesDsp. + for_window [title="JamesDSP for Linux"] { + move scratchpad + } + ''; } diff --git a/home/config/sway/module/Screenshot.nix b/home/config/sway/module/Screenshot.nix index 8509dfa..3825091 100644 --- a/home/config/sway/module/Screenshot.nix +++ b/home/config/sway/module/Screenshot.nix @@ -1,153 +1,150 @@ { - config, - pkgs, - lib, - ... -}: -let - codec = "libsvtav1"; - color = config.style.color; - container = "mp4"; - format = "%Y-%m-%d_%H-%M-%S"; - framerate = 10; - opacity = "26"; - selection = "slurp -d -b ${color.bg.light}${opacity} -c ${color.fg.light} -w 0 -s 00000000"; - pixfmt = "yuv420p10le"; -in -{ - text = - let - picEdit = ''swappy -f - -o -''; - picFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; - picPrepFile = prepFile "\${XDG_PICTURES_DIR[0]}" "png"; - picRefLatestFile = refLatestFile "png"; - picSelected = ''-g "''${scrSelection}" -''; - picToBuffer = ''wl-copy -t image/png''; - picToFile = ''tee "''${scrFile}"''; - screenshot = ''grim''; - updateWaybar = ''{ pkill -RTMIN+4 waybar; } & disown''; # NOTE: Might need to add a delay here if it becomes inconsistent one day. - vidFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; - vidPrepFile = prepFile "\${XDG_VIDEOS_DIR[0]}" container; - vidRefLatestFile = refLatestFile container; - vidSelected = ''--geometry "''${scrSelection}"''; - vidStop = ''pkill -SIGINT wf-recorder''; + config, + lib, + pkgs, + util, + ... +}: let + codec = "libsvtav1"; + color = config.module.style.color; + container = "mp4"; + format = "%Y-%m-%d_%H-%M-%S"; + framerate = 10; + opacity = "26"; + pixfmt = "yuv420p10le"; + selection = "slurp -d -b ${color.bg.light}${opacity} -c ${color.fg.light} -w 0 -s 00000000"; +in { + text = let + picEdit = ''swappy -f - -o -''; + picFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; + picPrepFile = prepFile "\${XDG_PICTURES_DIR[0]}" "png"; + picRefLatestFile = refLatestFile "png"; + picSelected = ''-g "''${scrSelection}" -''; + picToBuffer = ''wl-copy -t image/png''; + picToFile = ''tee "''${scrFile}"''; + screenshot = ''grim''; + updateWaybar = ''{ pkill -RTMIN+4 waybar; } & disown''; # NOTE: Might need to add a delay here if it becomes inconsistent one day. + vidFull = ''-o $(swaymsg -t get_outputs | jq -r ".[] | select(.focused) | .name") -''; + vidPrepFile = prepFile "\${XDG_VIDEOS_DIR[0]}" container; + vidRefLatestFile = refLatestFile container; + vidSelected = ''--geometry "''${scrSelection}"''; + vidStop = ''pkill -SIGINT wf-recorder''; - prepFile = path: ext: '' - # Focused app id by default. - curWindow=$(parse_snake $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .app_id')) + prepFile = path: ext: util.trimTabs '' + # Focused app id by default. + curWindow=$(parse_snake $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .app_id')) - # If no id (i.e. xwayland), then use a name (title). - [[ "''${curWindow}" = "null" ]] && curWindow=$(parse_snake $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .name')) + # If no id (i.e. xwayland), then use a name (title). + [[ "''${curWindow}" = "null" ]] && curWindow=$(parse_snake $(swaymsg -t get_tree | jq '.. | select(.type?) | select(.focused==true) | .name')) - # If no app in focus, use "unknown" dir. - [[ "''${curWindow}" =~ ^[0-9]+$ ]] && curWindow="unknown" + # If no app in focus, use "unknown" dir. + [[ "''${curWindow}" =~ ^[0-9]+$ ]] && curWindow="unknown" - # Prepare dir and file path. - scrPath="${path}" - scrDir="${path}/''${curWindow}" - mkdir -p "''${scrDir}" - scrName="$(date +${format}).${ext}" - scrFile="''${scrDir}/''${scrName}" - scrLatestRef="./''${curWindow}/''${scrName}" - ''; + # Prepare dir and file path. + scrPath="${path}" + scrDir="${path}/''${curWindow}" + mkdir -p "''${scrDir}" + scrName="$(date +${format}).${ext}" + scrFile="''${scrDir}/''${scrName}" + scrLatestRef="./''${curWindow}/''${scrName}" + ''; - refLatestFile = ext: '' - scrLatest="''${scrPath}/Latest.${ext}" - rm "''${scrLatest}" - ln -s "''${scrLatestRef}" "''${scrLatest}" - ''; + refLatestFile = ext: util.trimTabs '' + scrLatest="''${scrPath}/Latest.${ext}" + rm "''${scrLatest}" + ln -s "''${scrLatestRef}" "''${scrLatest}" + ''; - getSelection = '' - scrSelection=$(${selection}) - [[ -n "''${scrSelection}" ]] || exit - ''; + getSelection = util.trimTabs '' + scrSelection=$(${selection}) + [[ -n "''${scrSelection}" ]] || exit + ''; - getTransform = '' - scrTransform="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .transform')" - [[ "''${scrTransform}" = "normal" ]] && scrTransform="" - ''; + getTransform = util.trimTabs '' + scrTransform="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .transform')" + [[ "''${scrTransform}" = "normal" ]] && scrTransform="" + ''; - vidStart = '' - wf-recorder \ - --no-damage \ - --codec ${codec} \ - --file "''${scrFile}" \ - --framerate ${toString framerate} \ - --pixel-format ${pixfmt} \ - ''; + vidStart = util.trimTabs '' + wf-recorder \ + --no-damage \ + --codec ${codec} \ + --file "''${scrFile}" \ + --framerate ${toString framerate} \ + --pixel-format ${pixfmt} \ + ''; - vidMuxAudio = '' - ffmpeg \ - -f lavfi \ - -i anullsrc=channel_layout=stereo:sample_rate=44100 \ - -i "''${scrFile}" \ - -c:v copy \ - -c:a libopus \ - -shortest \ - -f ${container} \ - "''${scrFile}_" \ - && mv "''${scrFile}_" "''${scrFile}" \ - || rm "''${scrFile}_" - ''; + vidMuxAudio = util.trimTabs '' + ffmpeg \ + -f lavfi \ + -i anullsrc=channel_layout=stereo:sample_rate=44100 \ + -i "''${scrFile}" \ + -c:v copy \ + -c:a libopus \ + -shortest \ + -f ${container} \ + "''${scrFile}_" \ + && mv "''${scrFile}_" "''${scrFile}" \ + || rm "''${scrFile}_" + ''; - vidTransform = '' - if [[ -n "''${scrTransform}" ]]; then - ffmpeg \ - -display_rotation ''${scrTransform} \ - -i "''${scrFile}" \ - -c copy \ - -f ${container} \ - "''${scrFile}_" \ - && mv "''${scrFile}_" "''${scrFile}" \ - || rm "''${scrFile}_" - fi - ''; + vidTransform = util.trimTabs '' + if [[ -n "''${scrTransform}" ]]; then + ffmpeg \ + -display_rotation ''${scrTransform} \ + -i "''${scrFile}" \ + -c copy \ + -f ${container} \ + "''${scrFile}_" \ + && mv "''${scrFile}_" "''${scrFile}" \ + || rm "''${scrFile}_" + fi + ''; - SelectRecording = pkgs.writeShellScriptBin "SelectRecording" '' - ${vidStop} || { - ${getSelection} - ${getTransform} - ${vidPrepFile} - ${updateWaybar} - ${vidStart} ${vidSelected} - ${vidMuxAudio} - ${vidTransform} - ${vidRefLatestFile} - ${updateWaybar} - }; - ''; + SelectRecording = pkgs.writeShellScriptBin "SelectRecording" (util.trimTabs '' + ${vidStop} || { + ${getSelection} + ${getTransform} + ${vidPrepFile} + ${updateWaybar} + ${vidStart} ${vidSelected} + ${vidMuxAudio} + ${vidTransform} + ${vidRefLatestFile} + ${updateWaybar} + }; + ''); - FullscreenRecording = pkgs.writeShellScriptBin "FullscreenRecording" '' - ${vidStop} || { - ${getTransform} - ${vidPrepFile} - ${updateWaybar} - ${vidStart} ${vidFull} - ${vidMuxAudio} - ${vidTransform} - ${vidRefLatestFile} - ${updateWaybar} - }; - ''; + FullscreenRecording = pkgs.writeShellScriptBin "FullscreenRecording" (util.trimTabs '' + ${vidStop} || { + ${getTransform} + ${vidPrepFile} + ${updateWaybar} + ${vidStart} ${vidFull} + ${vidMuxAudio} + ${vidTransform} + ${vidRefLatestFile} + ${updateWaybar} + }; + ''); - FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" '' - ${picPrepFile} + FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" (util.trimTabs '' + ${picPrepFile} - ${screenshot} ${picFull} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile} - ''; + ${screenshot} ${picFull} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile} + ''); - SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" '' - ${getSelection} - ${picPrepFile} + SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" (util.trimTabs '' + ${getSelection} + ${picPrepFile} - ${screenshot} ${picSelected} | ${picEdit} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile} - ''; - in - '' - bindsym --to-code $mod+y exec ${lib.getExe FullscreenScreenshot} - bindsym --to-code $mod+shift+y exec ${lib.getExe FullscreenRecording} + ${screenshot} ${picSelected} | ${picEdit} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile} + ''); + in '' + bindsym --to-code $mod+y exec ${lib.getExe FullscreenScreenshot} + bindsym --to-code $mod+shift+y exec ${lib.getExe FullscreenRecording} - bindsym --to-code $mod+v exec ${lib.getExe SelectScreenshot} - bindsym --to-code $mod+shift+v exec ${lib.getExe SelectRecording} - ''; + bindsym --to-code $mod+v exec ${lib.getExe SelectScreenshot} + bindsym --to-code $mod+shift+v exec ${lib.getExe SelectRecording} + ''; } diff --git a/home/config/sway/module/Session.nix b/home/config/sway/module/Session.nix index 170c640..f2821e5 100644 --- a/home/config/sway/module/Session.nix +++ b/home/config/sway/module/Session.nix @@ -1,10 +1,11 @@ -{ config, ... }: -let - lock = "swaylock -f -F -c 000000 -k --font \"${config.style.font.serif.name}\" --font-size ${toString config.style.font.size.desktop}"; -in { - text = '' - bindsym --to-code $mod+z exec '_twice 1 ${lock}' - bindsym --to-code $mod+Shift+Z exec _twice 1 bash -c '${lock}; systemctl suspend -i' - ''; + config, + ... +}: let + lock = "swaylock -f -F -c 000000 -k --font \"${config.module.style.font.serif.name}\" --font-size ${toString config.module.style.font.size.desktop}"; +in { + text = '' + bindsym --to-code $mod+z exec '_twice 1 ${lock}' + bindsym --to-code $mod+Shift+Z exec _twice 1 bash -c '${lock}; systemctl suspend -i' + ''; } diff --git a/home/config/sway/module/Sound.nix b/home/config/sway/module/Sound.nix index eb6e9a9..e5b7b9d 100644 --- a/home/config/sway/module/Sound.nix +++ b/home/config/sway/module/Sound.nix @@ -1,22 +1,20 @@ -{ ... }: -let - step_volume = 5; - step_music = 10; -in -{ - text = '' - bindsym --to-code XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +${toString step_volume}%' - bindsym --to-code XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -${toString step_volume}%' - bindsym --to-code XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle' - bindsym --to-code XF86AudioMicMute exec 'pactl set-source-mute @DEFAULT_SOURCE@ toggle' +{ ... }: let + step_music = 10; + step_volume = 5; +in { + text = '' + bindsym --to-code XF86AudioRaiseVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ +${toString step_volume}%' + bindsym --to-code XF86AudioLowerVolume exec 'pactl set-sink-volume @DEFAULT_SINK@ -${toString step_volume}%' + bindsym --to-code XF86AudioMute exec 'pactl set-sink-mute @DEFAULT_SINK@ toggle' + bindsym --to-code XF86AudioMicMute exec 'pactl set-source-mute @DEFAULT_SOURCE@ toggle' - bindsym --to-code XF86AudioPlay exec 'playerctl play-pause' - bindsym --to-code XF86AudioPause exec 'playerctl pause' - bindsym --to-code XF86AudioStop exec 'playerctl stop' - bindsym --to-code XF86AudioNext exec 'playerctl next' - bindsym --to-code XF86AudioPrev exec 'playerctl previous' - bindsym --to-code XF86Forward exec 'playerctl position ${toString step_music}+' - bindsym --to-code XF86Back exec 'playerctl position ${toString step_music}-' - bindsym --to-code XF86Eject exec 'swayscript sound_output_cycle' - ''; + bindsym --to-code XF86AudioPlay exec 'playerctl play-pause' + bindsym --to-code XF86AudioPause exec 'playerctl pause' + bindsym --to-code XF86AudioStop exec 'playerctl stop' + bindsym --to-code XF86AudioNext exec 'playerctl next' + bindsym --to-code XF86AudioPrev exec 'playerctl previous' + bindsym --to-code XF86Forward exec 'playerctl position ${toString step_music}+' + bindsym --to-code XF86Back exec 'playerctl position ${toString step_music}-' + bindsym --to-code XF86Eject exec 'swayscript sound_output_cycle' + ''; } diff --git a/home/config/sway/module/Style.nix b/home/config/sway/module/Style.nix index d77e05b..cadbdc7 100644 --- a/home/config/sway/module/Style.nix +++ b/home/config/sway/module/Style.nix @@ -1,18 +1,19 @@ -{ config, ... }: -let - alpha = config.style.opacity.hex; - accent = config.style.color.accent + alpha; - bg = config.style.color.bg.dark + alpha; - border = config.style.color.border + alpha; - fg = config.style.color.fg.light; -in { - text = '' - output * bg ${config.module.wallpaper.path} fill - client.focused "#${accent}" "#${bg}" "#${fg}" "#${accent}" "#${accent}" - client.focused_inactive "#${border}" "#${bg}" "#${fg}" "#${border}" "#${border}" - client.unfocused "#${border}" "#${bg}" "#${fg}" "#${border}" "#${border}" - client.urgent "#${border}" "#${bg}" "#${fg}" "#${border}" "#${border}" - client.placeholder "#${bg}" "#${bg}" "#${fg}" "#${bg}" "#${bg}" - ''; + config, + ... +}: let + accent = config.module.style.color.accent + alpha; + alpha = config.module.style.opacity.hex; + bg = config.module.style.color.bg.dark + alpha; + border = config.module.style.color.border + alpha; + fg = config.module.style.color.fg.light; +in { + text = '' + output * bg ${config.module.wallpaper.path} fill + client.focused "#${accent}" "#${bg}" "#${fg}" "#${accent}" "#${accent}" + client.focused_inactive "#${border}" "#${bg}" "#${fg}" "#${border}" "#${border}" + client.unfocused "#${border}" "#${bg}" "#${fg}" "#${border}" "#${border}" + client.urgent "#${border}" "#${bg}" "#${fg}" "#${border}" "#${border}" + client.placeholder "#${bg}" "#${bg}" "#${fg}" "#${bg}" "#${bg}" + ''; } diff --git a/home/config/sway/module/System.nix b/home/config/sway/module/System.nix index cffd5cc..bd51c89 100644 --- a/home/config/sway/module/System.nix +++ b/home/config/sway/module/System.nix @@ -1,25 +1,23 @@ -{ ... }: -let - mod = "print"; - brstep = 5; -in -{ - text = '' - bindsym ${mod} input * xkb_switch_layout 0 - bindsym --to-code ${mod}+c exec 'systemctl reboot -i' - bindsym --to-code ${mod}+g exec 'swayscript gaming' - bindsym --to-code ${mod}+l exec 'powerlimit toggle' - bindsym --to-code ${mod}+m exec 'swayscript monitor' - bindsym --to-code ${mod}+n exec 'swayscript dnd' - bindsym --to-code ${mod}+p exec 'powersave toggle' - bindsym --to-code ${mod}+r exec 'swayscript reload' - bindsym --to-code ${mod}+v exec 'swayscript vpn' - bindsym --to-code ${mod}+x exec 'systemctl poweroff -i' - bindsym --to-code ${mod}+z exec 'systemctl suspend -i' +{ ... }: let + brstep = 5; + mod = "print"; +in { + text = '' + bindsym ${mod} input * xkb_switch_layout 0 + bindsym --to-code ${mod}+c exec 'systemctl reboot -i' + bindsym --to-code ${mod}+g exec 'swayscript gaming' + bindsym --to-code ${mod}+l exec 'powerlimit toggle' + bindsym --to-code ${mod}+m exec 'swayscript monitor' + bindsym --to-code ${mod}+n exec 'swayscript dnd' + bindsym --to-code ${mod}+p exec 'powersave toggle' + bindsym --to-code ${mod}+r exec 'swayscript reload' + bindsym --to-code ${mod}+v exec 'swayscript vpn' + bindsym --to-code ${mod}+x exec 'systemctl poweroff -i' + bindsym --to-code ${mod}+z exec 'systemctl suspend -i' - bindsym --to-code ${mod}+w exec light -A ${toString brstep} - bindsym XF86MonBrightnessUp exec light -A ${toString brstep} - bindsym --to-code ${mod}+s exec light -U ${toString brstep} - bindsym XF86MonBrightnessDown exec light -U ${toString brstep} - ''; + bindsym --to-code ${mod}+w exec light -A ${toString brstep} + bindsym XF86MonBrightnessUp exec light -A ${toString brstep} + bindsym --to-code ${mod}+s exec light -U ${toString brstep} + bindsym XF86MonBrightnessDown exec light -U ${toString brstep} + ''; } diff --git a/home/config/sway/module/Terminal.nix b/home/config/sway/module/Terminal.nix index c7cd357..57214ed 100644 --- a/home/config/sway/module/Terminal.nix +++ b/home/config/sway/module/Terminal.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - text = '' - set $term foot +{ ... }: { + text = '' + set $term foot - bindsym --to-code $mod+Escape exec $term -e bash -i -c "tmux new-session -A -s $USER; bash -i" - ''; + bindsym --to-code $mod+Escape exec $term -e bash -i -c "tmux new-session -A -s $USER; bash -i" + ''; } diff --git a/home/config/sway/module/Tiling.nix b/home/config/sway/module/Tiling.nix index d8699d9..5ad64b7 100644 --- a/home/config/sway/module/Tiling.nix +++ b/home/config/sway/module/Tiling.nix @@ -1,36 +1,38 @@ -{ config, ... }: { - text = '' - # Toggle tiling. - bindsym --to-code $mod+shift+f floating toggle + config, + ... +}: { + text = '' + # Toggle tiling. + bindsym --to-code $mod+shift+f floating toggle - # Swap focus between the tiling area and the floating area - bindsym --to-code $mod+r focus mode_toggle + # Swap focus between the tiling area and the floating area + bindsym --to-code $mod+r focus mode_toggle - # Split directions. - bindsym --to-code $mod+backslash splith - bindsym --to-code $mod+minus splitv + # Split directions. + bindsym --to-code $mod+backslash splith + bindsym --to-code $mod+minus splitv - # Switch the current container between different layout styles. - bindsym --to-code $mod+Tab layout toggle split tabbed + # Switch the current container between different layout styles. + bindsym --to-code $mod+Tab layout toggle split tabbed - # Fullscreen. - bindsym --to-code $mod+f fullscreen + # Fullscreen. + bindsym --to-code $mod+f fullscreen - # Drag floating windows by holding down $mod and left mouse button. - # Resize them with right mouse button + $mod. - # Despite the name, also works for non-floating windows. - # Change normal to inverse to use left mouse button for resizing and right - # mouse button for dragging. - floating_modifier $mod normal + # Drag floating windows by holding down $mod and left mouse button. + # Resize them with right mouse button + $mod. + # Despite the name, also works for non-floating windows. + # Change normal to inverse to use left mouse button for resizing and right + # mouse button for dragging. + floating_modifier $mod normal - # Kill focused window. - bindsym --to-code $mod+x kill + # Kill focused window. + bindsym --to-code $mod+x kill - # Add gaps. - gaps inner ${toString config.style.window.gap} + # Add gaps. + gaps inner ${toString config.module.style.window.gap} - # Launch everything tiled. - # for_window [all] floating disable - ''; + # Launch everything tiled. + # for_window [all] floating disable + ''; } diff --git a/home/config/sway/module/TitleBar.nix b/home/config/sway/module/TitleBar.nix index 792f113..9644e43 100644 --- a/home/config/sway/module/TitleBar.nix +++ b/home/config/sway/module/TitleBar.nix @@ -1,13 +1,14 @@ -{ config, ... }: -let - borderSize = toString config.style.window.border; -in { - text = '' - # Disable title bar. - default_border pixel ${borderSize} - default_floating_border pixel ${borderSize} - titlebar_padding 1 - titlebar_border_thickness 0 - ''; + config, + ... +}: let + borderSize = toString config.module.style.window.border; +in { + text = '' + # Disable title bar. + default_border pixel ${borderSize} + default_floating_border pixel ${borderSize} + titlebar_padding 1 + titlebar_border_thickness 0 + ''; } diff --git a/home/config/sway/module/Waybar.nix b/home/config/sway/module/Waybar.nix index dfacb5a..d846516 100644 --- a/home/config/sway/module/Waybar.nix +++ b/home/config/sway/module/Waybar.nix @@ -1,9 +1,8 @@ -{ ... }: -{ - text = '' - bindsym --to-code $mod+shift+r exec 'pkill waybar || exec waybar' - exec waybar - exec nm-applet - exec blueman-applet - ''; +{ ... }: { + text = '' + bindsym --to-code $mod+shift+r exec 'pkill waybar || exec waybar' + exec waybar + exec nm-applet + exec blueman-applet + ''; } diff --git a/home/config/sway/module/Workspace.nix b/home/config/sway/module/Workspace.nix index da9e393..7e9930a 100644 --- a/home/config/sway/module/Workspace.nix +++ b/home/config/sway/module/Workspace.nix @@ -1,38 +1,37 @@ -{ ... }: -{ - text = '' - # Switch to workspace. - bindsym --to-code $mod+1 workspace number 1 - bindsym --to-code $mod+2 workspace number 2 - bindsym --to-code $mod+3 workspace number 3 - bindsym --to-code $mod+4 workspace number 4 - bindsym --to-code $mod+5 workspace number 5 - bindsym --to-code $mod+6 workspace number 6 - bindsym --to-code $mod+7 workspace number 7 - bindsym --to-code $mod+8 workspace number 8 - bindsym --to-code $mod+9 workspace number 9 - bindsym --to-code $mod+0 workspace number 10 +{ ... }: { + text = '' + # Switch to workspace. + bindsym --to-code $mod+1 workspace number 1 + bindsym --to-code $mod+2 workspace number 2 + bindsym --to-code $mod+3 workspace number 3 + bindsym --to-code $mod+4 workspace number 4 + bindsym --to-code $mod+5 workspace number 5 + bindsym --to-code $mod+6 workspace number 6 + bindsym --to-code $mod+7 workspace number 7 + bindsym --to-code $mod+8 workspace number 8 + bindsym --to-code $mod+9 workspace number 9 + bindsym --to-code $mod+0 workspace number 10 - # Move focused container to workspace. - bindsym --to-code $mod+Shift+1 move container to workspace number 1 - bindsym --to-code $mod+Shift+2 move container to workspace number 2 - bindsym --to-code $mod+Shift+3 move container to workspace number 3 - bindsym --to-code $mod+Shift+4 move container to workspace number 4 - bindsym --to-code $mod+Shift+5 move container to workspace number 5 - bindsym --to-code $mod+Shift+6 move container to workspace number 6 - bindsym --to-code $mod+Shift+7 move container to workspace number 7 - bindsym --to-code $mod+Shift+8 move container to workspace number 8 - bindsym --to-code $mod+Shift+9 move container to workspace number 9 - bindsym --to-code $mod+Shift+0 move container to workspace number 10 - # Note: workspaces can have any name you want, not just numbers. - # We just use 1-10 as the default. + # Move focused container to workspace. + bindsym --to-code $mod+Shift+1 move container to workspace number 1 + bindsym --to-code $mod+Shift+2 move container to workspace number 2 + bindsym --to-code $mod+Shift+3 move container to workspace number 3 + bindsym --to-code $mod+Shift+4 move container to workspace number 4 + bindsym --to-code $mod+Shift+5 move container to workspace number 5 + bindsym --to-code $mod+Shift+6 move container to workspace number 6 + bindsym --to-code $mod+Shift+7 move container to workspace number 7 + bindsym --to-code $mod+Shift+8 move container to workspace number 8 + bindsym --to-code $mod+Shift+9 move container to workspace number 9 + bindsym --to-code $mod+Shift+0 move container to workspace number 10 + # Note: workspaces can have any name you want, not just numbers. + # We just use 1-10 as the default. - # Switch left-right. - bindsym --to-code $mod+e workspace next - bindsym --to-code $mod+q workspace prev + # Switch left-right. + bindsym --to-code $mod+e workspace next + bindsym --to-code $mod+q workspace prev - # Move left-right. - bindsym --to-code $mod+Shift+e move container to workspace next - bindsym --to-code $mod+Shift+q move container to workspace prev - ''; + # Move left-right. + bindsym --to-code $mod+Shift+e move container to workspace next + bindsym --to-code $mod+Shift+q move container to workspace prev + ''; } diff --git a/home/config/template/Android.nix b/home/config/template/Android.nix index 08e62ec..5e98f24 100644 --- a/home/config/template/Android.nix +++ b/home/config/template/Android.nix @@ -1,66 +1,67 @@ { - description = "Android dev environment."; + description = "Android dev environment."; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; - outputs = - { self, nixpkgs }@inputs: - let - system = "x86_64-linux"; - lib = nixpkgs.lib; - pkgs = import nixpkgs { - system = system; - config = { - allowUnfree = true; - android_sdk.accept_license = true; - }; - }; - jdk = pkgs.jdk11; - buildTools = "31.0.0"; - androidComposition = pkgs.androidenv.composeAndroidPackages { - abiVersions = [ - "armeabi-v7a" - "arm64-v8a" - ]; - buildToolsVersions = [ buildTools ]; - cmdLineToolsVersion = "8.0"; - includeEmulator = false; - includeNDK = false; - includeSources = false; - includeSystemImages = false; - platformToolsVersion = "34.0.5"; - platformVersions = [ "31" ]; - toolsVersion = "26.1.1"; - useGoogleAPIs = false; - useGoogleTVAddOns = false; - # cmakeVersions = [ "3.10.2" ]; - # emulatorVersion = "30.3.4"; - # includeExtras = [ "extras;google;gcm" ]; - # ndkVersions = ["22.0.7026061"]; - # systemImageTypes = [ "google_apis_playstore" ]; - }; - androidSdk = androidComposition.androidsdk; - in - { - devShells.${system} = { - default = pkgs.mkShell rec { - nativeBuildInputs = with pkgs; [ - android-tools - androidSdk - glibc - gnumake - jdk - ]; - buildInputs = with pkgs; [ ]; + outputs = { self, nixpkgs } @inputs: let + buildTools = "31.0.0"; + jdk = pkgs.jdk11; + lib = nixpkgs.lib; + system = "x86_64-linux"; + androidSdk = androidComposition.androidsdk; + pkgs = import nixpkgs { + system = system; + config = { + allowUnfree = true; + android_sdk.accept_license = true; + }; + }; + androidComposition = pkgs.androidenv.composeAndroidPackages { + cmdLineToolsVersion = "8.0"; + includeEmulator = false; + includeNDK = false; + includeSources = false; + includeSystemImages = false; + platformToolsVersion = "34.0.5"; + toolsVersion = "26.1.1"; + useGoogleAPIs = false; + useGoogleTVAddOns = false; + abiVersions = [ + "arm64-v8a" + "armeabi-v7a" + ]; + buildToolsVersions = [ + buildTools + ]; + platformVersions = [ + "31" + ]; + # cmakeVersions = [ "3.10.2" ]; + # emulatorVersion = "30.3.4"; + # includeExtras = [ "extras;google;gcm" ]; + # ndkVersions = ["22.0.7026061"]; + # systemImageTypes = [ "google_apis_playstore" ]; + }; + in { + devShells.${system} = { + default = pkgs.mkShell rec { + nativeBuildInputs = with pkgs; [ + android-tools + androidSdk + glibc + gnumake + jdk + ]; + buildInputs = with pkgs; [ ]; - GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride = ${androidSdk}/libexec/android-sdk/build-tools/${buildTools}/aapt2"; - JAVA_HOME = "${jdk}"; - LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; - ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk/"; - SOURCE_DATE_EPOCH = "${toString self.lastModified}"; - }; - }; - }; + ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk/"; + GRADLE_OPTS = "-Dorg.gradle.project.android.aapt2FromMavenOverride = ${androidSdk}/libexec/android-sdk/build-tools/${buildTools}/aapt2"; + JAVA_HOME = "${jdk}"; + LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; + SOURCE_DATE_EPOCH = "${toString self.lastModified}"; + }; + }; + }; } diff --git a/home/config/template/DevShell.nix b/home/config/template/DevShell.nix index 65a4884..1d6700e 100644 --- a/home/config/template/DevShell.nix +++ b/home/config/template/DevShell.nix @@ -1,26 +1,23 @@ { - description = ""; + description = ""; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; - outputs = - { self, nixpkgs }@inputs: - let - system = "x86_64-linux"; - lib = nixpkgs.lib; - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.${system} = { - default = pkgs.mkShell rec { - nativeBuildInputs = with pkgs; [ ]; - buildInputs = with pkgs; [ ]; + outputs = { self, nixpkgs } @inputs: let + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}; + system = "x86_64-linux"; + in { + devShells.${system} = { + default = pkgs.mkShell rec { + nativeBuildInputs = with pkgs; [ ]; + buildInputs = with pkgs; [ ]; - LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; - SOURCE_DATE_EPOCH = "${toString self.lastModified}"; - }; - }; - }; + LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; + SOURCE_DATE_EPOCH = "${toString self.lastModified}"; + }; + }; + }; } diff --git a/home/config/template/FHSEnv.nix b/home/config/template/FHSEnv.nix index 07a079e..d216163 100644 --- a/home/config/template/FHSEnv.nix +++ b/home/config/template/FHSEnv.nix @@ -1,25 +1,20 @@ { - description = ""; + description = ""; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; - outputs = - { self, nixpkgs }@inputs: - let - system = "x86_64-linux"; - lib = nixpkgs.lib; - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.${system} = { - default = - with pkgs; - (buildFHSEnv { - name = "FHSEnv"; - targetPkgs = pkgs: with pkgs; [ ]; - }).env; - }; - }; + outputs = { self, nixpkgs } @inputs: let + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}; + system = "x86_64-linux"; + in { + devShells.${system} = { + default = with pkgs; (buildFHSEnv { + name = "FHSEnv"; + targetPkgs = pkgs: with pkgs; [ ]; + }).env; + }; + }; } diff --git a/home/config/template/Latex.nix b/home/config/template/Latex.nix index 2e4c0da..d1f4941 100644 --- a/home/config/template/Latex.nix +++ b/home/config/template/Latex.nix @@ -1,59 +1,57 @@ { - description = "LuaLaTeX build env."; + description = "LuaLaTeX build env."; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; - outputs = - { self, nixpkgs }@inputs: - let - system = "x86_64-linux"; - lib = nixpkgs.lib; - pkgs = nixpkgs.legacyPackages.${system}; - tex = ( - pkgs.texlive.combine { - inherit (pkgs.texlive) - scheme-basic - amsmath - babel - capt-of - catchfile - collection-fontsextra - cyrillic - dvipng - dvisvgm - environ - etoolbox - fancyhdr - fontspec - geometry - hyperref - listofitems - luacode - luatexbase - montserrat - parskip - pgf - tcolorbox - tocloft - ulem - wrapfig - xcolor - ; + outputs = { self, nixpkgs } @inputs: let + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}; + system = "x86_64-linux"; + tex = ( + pkgs.texlive.combine { + inherit (pkgs.texlive) + amsmath + babel + capt-of + catchfile + collection-fontsextra + cyrillic + dvipng + dvisvgm + environ + etoolbox + fancyhdr + fontspec + geometry + hyperref + listofitems + luacode + luatexbase + montserrat + parskip + pgf + scheme-basic + tcolorbox + tocloft + ulem + wrapfig + xcolor + ; - #(setq org-latex-compiler "lualatex") - #(setq org-preview-latex-default-process 'dvisvgm) - } - ); - in - { - devShells.${system} = { - default = pkgs.mkShell rec { - nativeBuildInputs = with pkgs; [ tex ]; - buildInputs = with pkgs; [ ]; - SOURCE_DATE_EPOCH = "${toString self.lastModified}"; - }; - }; - }; + #(setq org-latex-compiler "lualatex") + #(setq org-preview-latex-default-process 'dvisvgm) + } + ); + in + { + devShells.${system} = { + default = pkgs.mkShell rec { + nativeBuildInputs = with pkgs; [ tex ]; + buildInputs = with pkgs; [ ]; + SOURCE_DATE_EPOCH = "${toString self.lastModified}"; + }; + }; + }; } diff --git a/home/config/template/Rust.nix b/home/config/template/Rust.nix index 8122364..9434676 100644 --- a/home/config/template/Rust.nix +++ b/home/config/template/Rust.nix @@ -1,41 +1,37 @@ { - description = "Rust shell env."; + description = "Rust shell env."; - inputs = { - nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; - }; + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable"; + }; - outputs = - { self, nixpkgs }@inputs: - let - system = "x86_64-linux"; - pkgs = nixpkgs.legacyPackages.${system}; - lib = nixpkgs.lib; - in - { - devShell.${system} = pkgs.mkShell rec { - nativeBuildInputs = with pkgs; [ - cargo - rustc - rust-analyzer - rustfmt - - cmake - pkg-config - fontconfig - ]; - buildInputs = with pkgs; [ - libxkbcommon - wayland - libGL - xorg.libX11 - xorg.libXrandr - xorg.libXinerama - xorg.libXcursor - xorg.libXi - ]; - LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; - SOURCE_DATE_EPOCH = "${toString self.lastModified}"; - }; - }; + outputs = { self, nixpkgs } @inputs: let + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}; + system = "x86_64-linux"; + in { + devShell.${system} = pkgs.mkShell rec { + nativeBuildInputs = with pkgs; [ + cargo + cmake + fontconfig + pkg-config + rust-analyzer + rustc + rustfmt + ]; + buildInputs = with pkgs; [ + libGL + libxkbcommon + wayland + xorg.libX11 + xorg.libXcursor + xorg.libXi + xorg.libXinerama + xorg.libXrandr + ]; + LD_LIBRARY_PATH = "${lib.makeLibraryPath buildInputs}"; + SOURCE_DATE_EPOCH = "${toString self.lastModified}"; + }; + }; } diff --git a/home/config/tmux/default.nix b/home/config/tmux/default.nix index 7f756ad..0f43d62 100644 --- a/home/config/tmux/default.nix +++ b/home/config/tmux/default.nix @@ -1,4 +1,7 @@ -{ util, config, ... }@args: { - text = util.catText (util.ls ./module) args; + util, + config, + ... +} @args: { + text = util.catText (util.ls ./module) args; } diff --git a/home/config/tmux/module/Config.nix b/home/config/tmux/module/Config.nix index 3b7f4a7..57863a5 100644 --- a/home/config/tmux/module/Config.nix +++ b/home/config/tmux/module/Config.nix @@ -1,9 +1,8 @@ -{ ... }: -{ - text = '' - unbind-key C-b - set-option -g prefix C-[ - bind-key C-[ send-prefix - bind -n M-r source-file ~/.config/tmux/tmux.conf - ''; +{ ... }: { + text = '' + unbind-key C-b + set-option -g prefix C-[ + bind-key C-[ send-prefix + bind -n M-r source-file ~/.config/tmux/tmux.conf + ''; } diff --git a/home/config/tmux/module/Copy.nix b/home/config/tmux/module/Copy.nix index 1d8b041..4ff69c7 100644 --- a/home/config/tmux/module/Copy.nix +++ b/home/config/tmux/module/Copy.nix @@ -1,16 +1,17 @@ -{ config, ... }: -let - fg = config.style.color.fg.dark; - selection = config.style.color.selection; -in { - text = '' - setw -g mode-keys vi - bind -n M-v copy-mode - bind -n M-p choose-buffer; - bind -T copy-mode-vi v send -X begin-selection - bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" + config, + ... +}: let + fg = config.module.style.color.fg.dark; + selection = config.module.style.color.selection; +in { + text = '' + setw -g mode-keys vi + bind -n M-v copy-mode + bind -n M-p choose-buffer; + bind -T copy-mode-vi v send -X begin-selection + bind -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" - set -g mode-style "fg=#${fg} bg=#${selection} bold" - ''; + set -g mode-style "fg=#${fg} bg=#${selection} bold" + ''; } diff --git a/home/config/tmux/module/Env.nix b/home/config/tmux/module/Env.nix index 513710e..4e7ea75 100644 --- a/home/config/tmux/module/Env.nix +++ b/home/config/tmux/module/Env.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - text = '' - set -sg escape-time 0 - set-option -g default-terminal "tmux-256color" - set-option -g focus-events on - set-option -sa terminal-features "RGB" - set -g allow-passthrough on - set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH SWAY_SOCK TERM TERM_PROGRAM" - ''; +{ ... }: { + text = '' + set -sg escape-time 0 + set-option -g default-terminal "tmux-256color" + set-option -g focus-events on + set-option -sa terminal-features "RGB" + set -g allow-passthrough on + set-option -g update-environment "SSH_CLIENT SSH_TTY DOCKER_CONFIG DOCKER_HOST DISPLAY XAUTHORITY BASH_PATH SWAY_SOCK TERM TERM_PROGRAM" + ''; } diff --git a/home/config/tmux/module/Scroll.nix b/home/config/tmux/module/Scroll.nix index cf8a145..7c7f362 100644 --- a/home/config/tmux/module/Scroll.nix +++ b/home/config/tmux/module/Scroll.nix @@ -1,7 +1,6 @@ -{ ... }: -{ - text = '' - bind -n M-K copy-mode -u - bind -n M-J send-keys Pagedown - ''; +{ ... }: { + text = '' + bind -n M-K copy-mode -u + bind -n M-J send-keys Pagedown + ''; } diff --git a/home/config/tmux/module/Session.nix b/home/config/tmux/module/Session.nix index 4cf290b..248c468 100644 --- a/home/config/tmux/module/Session.nix +++ b/home/config/tmux/module/Session.nix @@ -1,13 +1,12 @@ -{ ... }: -{ - text = '' - bind -n M-z detach-client - bind -n M-Z detach-client -a +{ ... }: { + text = '' + bind -n M-z detach-client + bind -n M-Z detach-client -a - bind -n M-, switch-client -p - bind -n M-. switch-client -n - bind -n M-g choose-session -Z + bind -n M-, switch-client -p + bind -n M-. switch-client -n + bind -n M-g choose-session -Z - set -g window-size smallest - ''; + set -g window-size smallest + ''; } diff --git a/home/config/tmux/module/Split.nix b/home/config/tmux/module/Split.nix index 7a394fb..9447a3d 100644 --- a/home/config/tmux/module/Split.nix +++ b/home/config/tmux/module/Split.nix @@ -1,40 +1,40 @@ -{ config, ... }: -let - accent = config.style.color.accent; - bg = config.style.color.bg.regular; - # fg = style.color.fg.light; - - stepVertical = 1; - stepHorizontal = 1; -in { - text = '' - bind -n M-\\ split-window -h -c "#{pane_current_path}" - bind -n M-- split-window -v -c "#{pane_current_path}" - bind -n M-= select-layout tiled - bind -n M-_ select-layout even-vertical - bind -n M-| select-layout even-horizontal - bind -n M-+ select-layout main-vertical - bind -n M-k resize-pane -U ${toString stepVertical} - bind -n M-j resize-pane -D ${toString stepVertical} - bind -n M-h resize-pane -L ${toString stepHorizontal} - bind -n M-l resize-pane -R ${toString stepHorizontal} - bind -n M-A swap-pane -U - bind -n M-W swap-pane -U - bind -n M-D swap-pane -D - bind -n M-S swap-pane -D - unbind '"' - unbind % + config, + ... +}: let + accent = config.module.style.color.accent; + bg = config.module.style.color.bg.regular; - bind -n M-a select-pane -L - bind -n M-d select-pane -R - bind -n M-w select-pane -U - bind -n M-s select-pane -D + stepHorizontal = 1; + stepVertical = 1; +in { + text = '' + bind -n M-\\ split-window -h -c "#{pane_current_path}" + bind -n M-- split-window -v -c "#{pane_current_path}" + bind -n M-= select-layout tiled + bind -n M-_ select-layout even-vertical + bind -n M-| select-layout even-horizontal + bind -n M-+ select-layout main-vertical + bind -n M-k resize-pane -U ${toString stepVertical} + bind -n M-j resize-pane -D ${toString stepVertical} + bind -n M-h resize-pane -L ${toString stepHorizontal} + bind -n M-l resize-pane -R ${toString stepHorizontal} + bind -n M-A swap-pane -U + bind -n M-W swap-pane -U + bind -n M-D swap-pane -D + bind -n M-S swap-pane -D + unbind '"' + unbind % - bind -n M-c kill-pane - bind -n M-C kill-pane -a + bind -n M-a select-pane -L + bind -n M-d select-pane -R + bind -n M-w select-pane -U + bind -n M-s select-pane -D - set -g pane-border-style "fg=#${bg}" - set -g pane-active-border-style "fg=#${accent}" - ''; + bind -n M-c kill-pane + bind -n M-C kill-pane -a + + set -g pane-border-style "fg=#${bg}" + set -g pane-active-border-style "fg=#${accent}" + ''; } diff --git a/home/config/tmux/module/Status.nix b/home/config/tmux/module/Status.nix index 7f8e709..37e16f6 100644 --- a/home/config/tmux/module/Status.nix +++ b/home/config/tmux/module/Status.nix @@ -1,29 +1,29 @@ -{ config, ... }: -let - accent = config.style.color.accent; - # bg = style.color.bg.dark; - fg = config.style.color.fg.light; -in { - text = '' - bind-key -n M-f set-option -g status; - set -g status-left-length 50 - set -g status-position bottom - set -g status-justify left - set -g status-style "fg=#${fg}" + config, + ... +}: let + accent = config.module.style.color.accent; + fg = config.module.style.color.fg.light; +in { + text = '' + bind-key -n M-f set-option -g status; + set -g status-left-length 50 + set -g status-position bottom + set -g status-justify left + set -g status-style "fg=#${fg}" - set -g status-left "#[bold] #H-#S #[default]" - set -g status-right "" + set -g status-left "#[bold] #H-#S #[default]" + set -g status-right "" - set-window-option -g window-status-separator "" + set-window-option -g window-status-separator "" - setw -g window-status-current-style "fg=#${accent} bold" - setw -g window-status-current-format " #W " + setw -g window-status-current-style "fg=#${accent} bold" + setw -g window-status-current-format " #W " - setw -g window-status-style "" - setw -g window-status-format " #W " + setw -g window-status-style "" + setw -g window-status-format " #W " - set-window-option -g visual-bell off - setw -g window-status-bell-style "bold blink" - ''; + set-window-option -g visual-bell off + setw -g window-status-bell-style "bold blink" + ''; } diff --git a/home/config/tmux/module/Window.nix b/home/config/tmux/module/Window.nix index 5adfeb2..f8721c8 100644 --- a/home/config/tmux/module/Window.nix +++ b/home/config/tmux/module/Window.nix @@ -1,16 +1,15 @@ -{ ... }: -{ - text = '' - bind -n M-Escape new-window -c "#{pane_current_path}" - bind -n M-t new-window -c "#{pane_current_path}" +{ ... }: { + text = '' + bind -n M-Escape new-window -c "#{pane_current_path}" + bind -n M-t new-window -c "#{pane_current_path}" - bind -n M-x kill-window - bind -n M-X kill-window -a + bind -n M-x kill-window + bind -n M-X kill-window -a - bind -n M-e next-window - bind -n M-q previous-window + bind -n M-e next-window + bind -n M-q previous-window - bind -n M-E swap-window -t +1\; select-window -t +1 - bind -n M-Q swap-window -t -1\; select-window -t -1 - ''; + bind -n M-E swap-window -t +1\; select-window -t +1 + bind -n M-Q swap-window -t -1\; select-window -t -1 + ''; } diff --git a/home/config/waybar/config/default.nix b/home/config/waybar/config/default.nix index 28a1113..b04b5f9 100644 --- a/home/config/waybar/config/default.nix +++ b/home/config/waybar/config/default.nix @@ -1,182 +1,178 @@ -{ config, pkgs, ... }: -let - refreshInterval = 2; -in { - file = (pkgs.formats.json { }).generate "WaybarConfig" { - height = 34; - layer = "top"; - margin-left = config.style.window.gap; - margin-right = config.style.window.gap; - margin-top = config.style.window.gap; - mode = "dock"; - position = "top"; - spacing = 4; - start_hidden = false; - output = [ - "!Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" # Desktop monitor. - "!AOC 24G2W1G4 ATNL61A129625" # Dasha monitor. - "!UGD Artist15.6Pro 20200316" # XP-Pen Tablet. - "*" - ]; - modules-left = [ - "clock" - "sway/scratchpad" - "mpris" - ]; - modules-center = [ "sway/workspaces" ]; - modules-right = [ - "sway/language" - "pulseaudio" - "group/batteryinfo" - "group/hardware" - "custom/display" - "tray" - ]; - "sway/workspaces" = { - all-outputs = true; - }; - "sway/language" = { - tooltip = false; - on-click = "swaymsg 'input * xkb_switch_layout next'"; - on-click-right = "xdg-open https://translate.yandex.ru/"; - }; - "sway/scratchpad" = { - format = "{icon} {count}"; - show-empty = false; - format-icons = [ - "" - "" - ]; - tooltip = true; - tooltip-format = "{app}: {title}"; - on-click = "swaymsg 'scratchpad show'"; - on-click-middle = "swayscript scratchpad_kill"; - }; - tray = { - # icon-size = 21; - spacing = 8; - }; - clock = { - # timezone = "America/New_York"; - tooltip-format = "{calendar}"; - format-alt = "{:%d %a %H:%M}"; - on-click-right = "xdg-open https://cloud.voronind.com/apps/calendar/"; - }; - battery = { - states = { - good = 60; - warning = 40; - critical = 2; - }; - format = "{capacity}% {icon}"; - format-charging = "{capacity}% "; - format-plugged = "{capacity}% "; - format-alt = "{time} {icon}"; - format-icons = [ - "󰂎" - "󱊡" - "󱊢" - "󱊣" - "󱊣" - ]; - on-click-right = "powerlimit toggle"; - interval = refreshInterval; - }; - "custom/powerlimit" = { - exec = "powerlimit widget"; - on-click-right = "powerlimit toggle"; - signal = 6; - tooltip = false; - }; - "group/batteryinfo" = { - orientation = "horizontal"; - modules = [ - "battery" - "custom/powerlimit" - ]; - }; - pulseaudio = { - scroll-step = 5; - format = "{volume}%{icon}{format_source}"; - format-muted = "󰸈{format_source}"; - # format-icons = { - # default = [ " " " " " " ]; - # }; - format-source = ""; - format-source-muted = " 󰍭"; - on-click = "pactl set-sink-mute @DEFAULT_SINK@ toggle"; - on-click-middle = "pavucontrol"; - on-click-right = "pactl set-source-mute @DEFAULT_SOURCE@ toggle"; - }; - mpris = - let - maxLength = 32; - in - { - format = "{player_icon} {title} - {artist}"; - format-paused = "{status_icon} {title} - {artist}"; - tooltip-format = "{player}: {dynamic}"; - on-click-middle = "playerctl stop"; - album-len = maxLength; - artist-len = maxLength; - title-len = maxLength; - # ignored-players = [ "firefox" ]; - player-icons = { - "default" = ""; - "firefox" = "󰈹"; - "mpv" = ""; - }; - status-icons = { - "paused" = ""; - }; - }; - cpu = { - format = "{usage}% ({load})"; - interval = refreshInterval; - on-click = "foot -e bash -c btop"; - on-click-right = "powersave toggle"; - tooltip = false; - }; - memory = { - format = "{percentage}%"; - interval = refreshInterval; - on-click = "foot -e bash -c btop"; - on-click-right = "powersave toggle"; - }; - temperature = { - critical-threshold = 80; - format = "{temperatureC}°C"; - hwmon-path-abs = "${config.setting.cpu.hwmon.path}"; - input-filename = "${config.setting.cpu.hwmon.file}"; - interval = refreshInterval; - on-click = "foot -e bash -c btop"; - on-click-right = "powersave toggle"; - tooltip = false; - }; - "custom/powersave" = { - exec = "powersave widget"; - on-click = "foot -e bash -c btop"; - on-click-right = "powersave toggle"; - signal = 5; - tooltip = false; - }; - "group/hardware" = { - orientation = "horizontal"; - modules = [ - "cpu" - "memory" - "temperature" - "custom/powersave" - ]; - }; - "custom/display" = { - exec = "swayscript displaywidget"; - on-click = "sleep 0.1 && swayscript dnd"; # HACK: https://github.com/Alexays/Waybar/issues/2166 & https://github.com/Alexays/Waybar/issues/1968 - on-click-right = "sleep 0.1 && swayscript monitor"; - on-click-middle = "sleep 0.1 && swayscript displayreset"; - return-type = "json"; - signal = 4; - }; - }; + config, + pkgs, + ... +}: let + refreshInterval = 2; +in { + file = (pkgs.formats.json { }).generate "WaybarConfig" { + height = 34; + layer = "top"; + margin-left = config.module.style.window.gap; + margin-right = config.module.style.window.gap; + margin-top = config.module.style.window.gap; + mode = "dock"; + position = "top"; + spacing = 4; + start_hidden = false; + output = [ + "!AOC 24G2W1G4 ATNL61A129625" # Dasha monitor. + "!Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" # Desktop monitor. + "!UGD Artist15.6Pro 20200316" # XP-Pen Tablet. + "*" + ]; + modules-left = [ + "clock" + "sway/scratchpad" + "mpris" + ]; + modules-center = [ + "sway/workspaces" + ]; + modules-right = [ + "sway/language" + "pulseaudio" + "group/batteryinfo" + "group/hardware" + "custom/display" + "tray" + ]; + "sway/workspaces" = { + all-outputs = true; + }; + "sway/language" = { + on-click = "swaymsg 'input * xkb_switch_layout next'"; + on-click-right = "xdg-open https://translate.yandex.ru/"; + tooltip = false; + }; + "sway/scratchpad" = { + format = "{icon} {count}"; + on-click = "swaymsg 'scratchpad show'"; + on-click-middle = "swayscript scratchpad_kill"; + show-empty = false; + tooltip = true; + tooltip-format = "{app}: {title}"; + format-icons = [ + "" + "" + ]; + }; + tray = { + spacing = 8; + }; + clock = { + format-alt = "{:%d %a %H:%M}"; + on-click-right = "xdg-open https://cloud.voronind.com/apps/calendar/"; + tooltip-format = "{calendar}"; + }; + battery = { + format = "{capacity}% {icon}"; + format-alt = "{time} {icon}"; + format-charging = "{capacity}% "; + format-plugged = "{capacity}% "; + interval = refreshInterval; + on-click-right = "powerlimit toggle"; + states = { + good = 60; + warning = 40; + critical = 2; + }; + format-icons = [ + "󰂎" + "󱊡" + "󱊢" + "󱊣" + "󱊣" + ]; + }; + "custom/powerlimit" = { + exec = "powerlimit widget"; + on-click-right = "powerlimit toggle"; + signal = 6; + tooltip = false; + }; + "group/batteryinfo" = { + orientation = "horizontal"; + modules = [ + "battery" + "custom/powerlimit" + ]; + }; + pulseaudio = { + format = "{volume}%{icon}{format_source}"; + format-muted = "󰸈{format_source}"; + format-source = ""; + format-source-muted = " 󰍭"; + on-click = "pactl set-sink-mute @DEFAULT_SINK@ toggle"; + on-click-middle = "pavucontrol"; + on-click-right = "pactl set-source-mute @DEFAULT_SOURCE@ toggle"; + scroll-step = 5; + }; + mpris = let + maxLength = 32; + in { + album-len = maxLength; + artist-len = maxLength; + format = "{player_icon} {title} - {artist}"; + format-paused = "{status_icon} {title} - {artist}"; + on-click-middle = "playerctl stop"; + title-len = maxLength; + tooltip-format = "{player}: {dynamic}"; + player-icons = { + "default" = ""; + "firefox" = "󰈹"; + "mpv" = ""; + }; + status-icons = { + "paused" = ""; + }; + }; + cpu = { + format = "{usage}% ({load})"; + interval = refreshInterval; + on-click = "foot -e bash -c btop"; + on-click-right = "powersave toggle"; + tooltip = false; + }; + memory = { + format = "{percentage}%"; + interval = refreshInterval; + on-click = "foot -e bash -c btop"; + on-click-right = "powersave toggle"; + }; + temperature = { + critical-threshold = 80; + format = "{temperatureC}°C"; + hwmon-path-abs = "${config.module.hwmon.path}"; + input-filename = "${config.module.hwmon.file}"; + interval = refreshInterval; + on-click = "foot -e bash -c btop"; + on-click-right = "powersave toggle"; + tooltip = false; + }; + "custom/powersave" = { + exec = "powersave widget"; + on-click = "foot -e bash -c btop"; + on-click-right = "powersave toggle"; + signal = 5; + tooltip = false; + }; + "group/hardware" = { + orientation = "horizontal"; + modules = [ + "cpu" + "temperature" + "memory" + "custom/powersave" + ]; + }; + "custom/display" = { + exec = "swayscript displaywidget"; + on-click = "sleep 0.1 && swayscript dnd"; # HACK: https://github.com/Alexays/Waybar/issues/2166 & https://github.com/Alexays/Waybar/issues/1968 + on-click-middle = "sleep 0.1 && swayscript displayreset"; + on-click-right = "sleep 0.1 && swayscript monitor"; + return-type = "json"; + signal = 4; + }; + }; } diff --git a/home/config/waybar/default.nix b/home/config/waybar/default.nix index d314fbe..69c0a9f 100644 --- a/home/config/waybar/default.nix +++ b/home/config/waybar/default.nix @@ -1,5 +1,8 @@ -{ util, pkgs, ... }@args: { - config = (import ./config args).file; - style = pkgs.writeText "WaybarStyle" (util.catText (util.ls ./style) args); + util, + pkgs, + ... +} @args: { + config = (import ./config args).file; + style = pkgs.writeText "WaybarStyle" (util.catText (util.ls ./style) args); } diff --git a/home/config/waybar/style/Common.nix b/home/config/waybar/style/Common.nix index 56480e9..14fea4f 100644 --- a/home/config/waybar/style/Common.nix +++ b/home/config/waybar/style/Common.nix @@ -1,10 +1,12 @@ -{ config, ... }: { - text = '' - * { - font-family: "${config.style.font.serif.name}", "Terminess Nerd Font Propo"; - font-size: ${toString config.style.font.size.desktop}px; - color: #${config.style.color.fg.light}; - } - ''; + config, + ... +}: { + text = '' + * { + font-family: "${config.module.style.font.serif.name}", "Terminess Nerd Font Propo"; + font-size: ${toString config.module.style.font.size.desktop}px; + color: #${config.module.style.color.fg.light}; + } + ''; } diff --git a/home/config/waybar/style/Plugin.nix b/home/config/waybar/style/Plugin.nix index ecef8d2..8627a66 100644 --- a/home/config/waybar/style/Plugin.nix +++ b/home/config/waybar/style/Plugin.nix @@ -1,79 +1,80 @@ -{ config, ... }: -let - paddingV = "0"; - paddingH = "12px"; -in { - # ISSUE: https://github.com/Alexays/Waybar/issues/3303 - # This way I am forced to apply the padding to children of each group - # instead of the whole group. - text = '' - #clock, - #custom-display, - #language, - #mpris, - #pulseaudio, - #scratchpad, - #tray { - padding: ${paddingV} ${paddingH}; - border-top: ${toString config.style.window.border}px solid transparent; - border-bottom: ${toString config.style.window.border}px solid transparent; - } + config, + ... +}: let + paddingH = "12px"; + paddingV = "0"; +in { + # ISSUE: https://github.com/Alexays/Waybar/issues/3303 + # This way I am forced to apply the padding to children of each group + # instead of the whole group. + text = '' + #clock, + #custom-display, + #language, + #mpris, + #pulseaudio, + #scratchpad, + #tray { + padding: ${paddingV} ${paddingH}; + border-top: ${toString config.module.style.window.border}px solid transparent; + border-bottom: ${toString config.module.style.window.border}px solid transparent; + } - #cpu, - #battery { - padding-left: ${paddingH}; - } + #cpu, + #battery { + padding-left: ${paddingH}; + } - #custom-powersave, - #custom-powerlimit { - padding-right: ${paddingH}; - } + #custom-powersave, + #custom-powerlimit { + padding-right: ${paddingH}; + } - #clock { - font-weight: bold; - } + #clock { + font-weight: bold; + } - #custom-powerlimit, - #custom-powersave, - #memory, - #temperature { - padding-left: 4px; - border-top: ${toString config.style.window.border}px solid transparent; - border-bottom: ${toString config.style.window.border}px solid transparent; - } + #custom-powerlimit, + #custom-powersave, + #memory, + #temperature { + padding-left: 4px; + border-top: ${toString config.module.style.window.border}px solid transparent; + border-bottom: ${toString config.module.style.window.border}px solid transparent; + } - #batteryinfo:hover, - #clock:hover, - #custom-display:hover, - #hardware:hover, - #language:hover, - #mpris:hover, - #pulseaudio:hover, - #scratchpad:hover, - #tray:hover, - #workspaces button:hover { - background-color: rgba(${config.style.color.border-r},${config.style.color.border-g},${config.style.color.border-b},${toString config.style.opacity.desktop}); - } + #batteryinfo:hover, + #clock:hover, + #custom-display:hover, + #hardware:hover, + #language:hover, + #mpris:hover, + #pulseaudio:hover, + #scratchpad:hover, + #tray:hover, + #workspaces button:hover { + background-color: rgba(${config.module.style.color.border-r},${config.module.style.color.border-g},${config.module.style.color.border-b},${toString config.module.style.opacity.desktop}); + } - #pulseaudio.muted, - #pulseaudio.source-muted, - #battery.critical, - #temperature.critical, - #tray.needs-attention, - #custom-display.modified { - border-top: ${toString config.style.window.border}px solid #${config.style.color.accent}; - } + #pulseaudio.muted, + #pulseaudio.source-muted, + #battery.critical, + #temperature.critical, + #tray.needs-attention, + #custom-display.modified { + border-top: ${toString config.module.style.window.border}px solid #${config.module.style.color.accent}; + } - #workspaces button { - padding: ${paddingV} 4px; - border-top: ${toString config.style.window.border}px solid transparent; - border-bottom: ${toString config.style.window.border}px solid transparent; - border-radius: 0; - } + #workspaces button { + padding: ${paddingV} 4px; + border-top: ${toString config.module.style.window.border}px solid transparent; + border-bottom: ${toString config.module.style.window.border}px solid transparent; + border-radius: 0; + } - #workspaces button.focused { - border-top: ${toString config.style.window.border}px solid #${config.style.color.accent}; - } - ''; + #workspaces button.focused { + border-top: ${toString config.module.style.window.border}px solid #${config.module.style.color.accent}; + } + ''; } diff --git a/home/config/waybar/style/Window.nix b/home/config/waybar/style/Window.nix index a60af16..ea1a154 100644 --- a/home/config/waybar/style/Window.nix +++ b/home/config/waybar/style/Window.nix @@ -1,17 +1,19 @@ -{ config, ... }: { - text = '' - window#waybar { - background-color: rgba(${config.style.color.bg-r},${config.style.color.bg-g},${config.style.color.bg-b},${toString config.style.opacity.desktop}); - border: ${toString config.style.window.border}px solid rgba(${config.style.color.border-r},${config.style.color.border-g},${config.style.color.border-b},${toString config.style.opacity.desktop}); - } + config, + ... +}: { + text = '' + window#waybar { + background-color: rgba(${config.module.style.color.bg-r},${config.module.style.color.bg-g},${config.module.style.color.bg-b},${toString config.module.style.opacity.desktop}); + border: ${toString config.module.style.window.border}px solid rgba(${config.module.style.color.border-r},${config.module.style.color.border-g},${config.module.style.color.border-b},${toString config.module.style.opacity.desktop}); + } - .modules-left > widget:first-child > #workspaces { - margin-left: ${toString config.style.window.border}px; - } + .modules-left > widget:first-child > #workspaces { + margin-left: ${toString config.module.style.window.border}px; + } - .modules-right > widget:last-child > #workspaces { - margin-right: ${toString config.style.window.border}px; - } - ''; + .modules-right > widget:last-child > #workspaces { + margin-right: ${toString config.module.style.window.border}px; + } + ''; } diff --git a/home/config/yazi/default.nix b/home/config/yazi/default.nix index 4355133..8f633ac 100644 --- a/home/config/yazi/default.nix +++ b/home/config/yazi/default.nix @@ -1,12 +1,11 @@ { - pkgs, - config, - util, - ... -}@args: -{ - init = (import ./module/Init.nix args).file; - keymap = (import ./module/Keymap.nix args).file; - theme = (import ./module/Theme.nix args).file; - yazi = (import ./module/Yazi.nix args).file; + config, + pkgs, + util, + ... +} @args: { + init = (import ./module/Init.nix args).file; + keymap = (import ./module/Keymap.nix args).file; + theme = (import ./module/Theme.nix args).file; + yazi = (import ./module/Yazi.nix args).file; } diff --git a/home/config/yazi/module/Init.nix b/home/config/yazi/module/Init.nix index 8e745c9..5628220 100644 --- a/home/config/yazi/module/Init.nix +++ b/home/config/yazi/module/Init.nix @@ -1,11 +1,13 @@ -{ pkgs, ... }: { - file = pkgs.writeText "YaziInitConfig" '' - -- Hide Status Bar. - -- function Status:render() return {} end - -- local old_manager_render = Manager.render - -- function Manager:render(area) - -- return old_manager_render(self, ui.Rect { x = area.x, y = area.y, w = area.w, h = area.h + 1 }) - -- end - ''; + pkgs, + ... +}: { + file = pkgs.writeText "YaziInitConfig" '' + -- Hide Status Bar. + -- function Status:render() return {} end + -- local old_manager_render = Manager.render + -- function Manager:render(area) + -- return old_manager_render(self, ui.Rect { x = area.x, y = area.y, w = area.w, h = area.h + 1 }) + -- end + ''; } diff --git a/home/config/yazi/module/Keymap.nix b/home/config/yazi/module/Keymap.nix index 39f8c4f..7324dd3 100644 --- a/home/config/yazi/module/Keymap.nix +++ b/home/config/yazi/module/Keymap.nix @@ -1,54 +1,32 @@ -{ pkgs, ... }: -let - mkKeymap = desc: on: run: { inherit desc on run; }; -in { - # REF: https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/keymap.toml - file = (pkgs.formats.toml { }).generate "YaziKeymapConfig" { - manager = { - prepend_keymap = [ - # TODO: Swap description & keys for better sorting? - (mkKeymap "Delete" "d" "remove --permanently") - (mkKeymap "Delete no questions asked" "D" "remove --permanently --force") - (mkKeymap "Spawn shell here" "" ''shell "SHELL_NAME=yazi $SHELL" --block --confirm'') - (mkKeymap "Open interactively" "o" "open --interactive") - (mkKeymap "Open default" "O" "open") - (mkKeymap "Rename completely" "R" "rename --empty all") - (mkKeymap "Close tab" "c" "close") - (mkKeymap "Prev tab" "q" "tab_switch -1 --relative") - (mkKeymap "Next tab" "e" "tab_switch 1 --relative") - (mkKeymap "Move to prev tab" "Q" "tab_swap -1 --relative") - (mkKeymap "Move to next tab" "E" "tab_swap 1 --relative") - (mkKeymap "Exit yazi" "z" "quit") - (mkKeymap "Exit yazi w/o cwd" "Z" "quit --no-cwd-file") - (mkKeymap "New tab" "" "tab_create --current") - # I wanna die thanks to nixfmt. - (mkKeymap "Go to storage" [ - "g" - "s" - ] "cd /storage") - (mkKeymap "Go to tmp" [ - "g" - "t" - ] "cd ~/tmp") - (mkKeymap "Go to system tmp" [ - "g" - "T" - ] "cd /tmp") - (mkKeymap "Go to projects" [ - "g" - "p" - ] "cd ~/project") - # Yazi devs are... special. - (mkKeymap "Go to downloads" [ - "g" - "d" - ] "cd $XDG_DOWNLOAD_DIR") - (mkKeymap "Go to configs" [ - "g" - "c" - ] "cd $XDG_CONFIG_HOME") - ]; - }; - }; + pkgs, + ... +}: { + # REF: https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/keymap.toml + file = (pkgs.formats.toml { }).generate "YaziKeymapConfig" { + manager = { + prepend_keymap = [ + { on = ""; desc = "Spawn shell here"; run = ''shell "SHELL_NAME=yazi $SHELL" --block --confirm''; } + { on = ""; desc = "New tab"; run = "tab_create --current"; } + { on = "D"; desc = "Force delete"; run = "remove --permanently --force"; } + { on = "E"; desc = "Move to next tab"; run = "tab_swap 1 --relative"; } + { on = "O"; desc = "Open default"; run = "open"; } + { on = "Q"; desc = "Move to prev tab"; run = "tab_swap -1 --relative"; } + { on = "R"; desc = "Rename completely"; run = "rename --empty all"; } + { on = "Z"; desc = "Exit yazi w/o cwd"; run = "quit --no-cwd-file"; } + { on = "c"; desc = "Close tab"; run = "close"; } + { on = "d"; desc = "Delete"; run = "remove --permanently"; } + { on = "e"; desc = "Next tab"; run = "tab_switch 1 --relative"; } + { on = "o"; desc = "Open interactively";run = "open --interactive"; } + { on = "q"; desc = "Prev tab"; run = "tab_switch -1 --relative"; } + { on = "z"; desc = "Exit yazi"; run = "quit"; } + { on = [ "g" "T" ]; desc = "Go to system tmp"; run = "cd /tmp"; } + { on = [ "g" "c" ]; desc = "Go to configs"; run = "noop"; } + { on = [ "g" "d" ]; desc = "Go to downloads"; run = "cd $XDG_DOWNLOAD_DIR"; } + { on = [ "g" "p" ]; desc = "Go to projects"; run = "cd ~/project"; } + { on = [ "g" "s" ]; desc = "Go to storage"; run = "cd /storage"; } + { on = [ "g" "t" ]; desc = "Go to tmp"; run = "cd ~/tmp"; } + ]; + }; + }; } diff --git a/home/config/yazi/module/Theme.nix b/home/config/yazi/module/Theme.nix index 9fa7ad8..5fb3f87 100644 --- a/home/config/yazi/module/Theme.nix +++ b/home/config/yazi/module/Theme.nix @@ -1,106 +1,106 @@ -{ pkgs, config, ... }: -let - color = config.style.color; - border = { - fg = "#${color.border}"; - }; - borderLight = { - fg = "#${color.accent}"; - }; - hover = { - bg = "#${color.bg.regular}"; - fg = "#${color.fg.light}"; - }; - select = { - bg = "#${color.selection}"; - fg = "#${color.fg.dark}"; - }; - text = { - fg = "#${color.fg.light}"; - }; -in { - # REF: https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/theme.toml - file = (pkgs.formats.toml { }).generate "YaziThemeConfig" { - manager = - let - mkMarker = markerColor: { - bg = "#${markerColor}"; - fg = "#${markerColor}"; - }; + pkgs, + config, + ... +}: let + color = config.module.style.color; + border = { + fg = "#${color.border}"; + }; + borderLight = { + fg = "#${color.accent}"; + }; + hover = { + bg = "#${color.bg.regular}"; + fg = "#${color.fg.light}"; + }; + select = { + bg = "#${color.selection}"; + fg = "#${color.fg.dark}"; + }; + text = { + fg = "#${color.fg.light}"; + }; +in { + # REF: https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/theme.toml + file = (pkgs.formats.toml { }).generate "YaziThemeConfig" { + manager = let + mkMarker = markerColor: { + bg = "#${markerColor}"; + fg = "#${markerColor}"; + }; - mkCounter = counterColor: { - bg = "#${counterColor}"; - fg = "#${color.fg.light}"; - }; - in - { - border_style = border; - border_symbol = " "; - count_copied = mkCounter color.positive; - count_cut = mkCounter color.negative; - count_selected = mkCounter color.neutral; - cwd = text; - hovered = hover; - marker_copied = mkMarker color.accent; - marker_cut = mkMarker color.accent; - marker_marked = mkMarker color.hl; - marker_selected = mkMarker color.selection; - preview_hovered = hover; - tab_active = mkCounter color.selection; - }; - select = { - border = borderLight; - }; - input = { - border = borderLight; - }; - completion = { - border = borderLight; - active = hover; - inactive = text; - }; - tasks = { - border = borderLight; - }; - which = { - cand = text; - cols = 3; - desc = text; - mask = hover; - rest = text; - separator = " - "; - separator_style = text; - }; - confirm = { - border = borderLight; - title = borderLight; - }; - status = { - mode_normal = hover; - mode_select = select; - permissions_r = text; - permissions_s = text; - permissions_t = text; - permissions_w = text; - permissions_x = text; - progress_label = hover; - progress_normal = hover; - separator_close = ""; - separator_open = ""; - # NOTE: Inversed because yazi dev is fckin weird. Also add manpages ffs. - separator_style = { - bg = "#${config.style.color.fg.light}"; - fg = "#${config.style.color.bg.regular}"; - }; - mode_unset = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.neutral}"; - }; - progress_error = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.negative}"; - }; - }; - }; + mkCounter = counterColor: { + bg = "#${counterColor}"; + fg = "#${color.fg.light}"; + }; + in { + border_style = border; + border_symbol = " "; + count_copied = mkCounter color.positive; + count_cut = mkCounter color.negative; + count_selected = mkCounter color.neutral; + cwd = text; + hovered = hover; + marker_copied = mkMarker color.accent; + marker_cut = mkMarker color.accent; + marker_marked = mkMarker color.hl; + marker_selected = mkMarker color.selection; + preview_hovered = hover; + tab_active = mkCounter color.selection; + }; + select = { + border = borderLight; + }; + input = { + border = borderLight; + }; + completion = { + active = hover; + border = borderLight; + inactive = text; + }; + tasks = { + border = borderLight; + }; + which = { + cand = text; + cols = 3; + desc = text; + mask = hover; + rest = text; + separator = " - "; + separator_style = text; + }; + confirm = { + border = borderLight; + title = borderLight; + }; + status = { + mode_normal = hover; + mode_select = select; + permissions_r = text; + permissions_s = text; + permissions_t = text; + permissions_w = text; + permissions_x = text; + progress_label = hover; + progress_normal = hover; + separator_close = ""; + separator_open = ""; + # NOTE: Inversed because yazi dev is fckin weird. Also add manpages ffs. + separator_style = { + bg = "#${config.module.style.color.fg.light}"; + fg = "#${config.module.style.color.bg.regular}"; + }; + mode_unset = { + bg = "#${config.module.style.color.neutral}"; + fg = "#${config.module.style.color.fg.light}"; + }; + progress_error = { + bg = "#${config.module.style.color.negative}"; + fg = "#${config.module.style.color.fg.light}"; + }; + }; + }; } diff --git a/home/config/yazi/module/Yazi.nix b/home/config/yazi/module/Yazi.nix index c4e263f..0189f82 100644 --- a/home/config/yazi/module/Yazi.nix +++ b/home/config/yazi/module/Yazi.nix @@ -1,183 +1,144 @@ -{ pkgs, config, ... }: { - # REF: https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/yazi.toml - file = (pkgs.formats.toml { }).generate "YaziYaziConfig" { - manager = { - # linemode = "mtime"; - mouse_events = [ ]; - ratio = [ - 1 - 4 - 3 - ]; - scrolloff = 1; - show_hidden = false; - show_symlink = true; - sort_by = "natural"; - sort_dir_first = true; - sort_sensitive = true; - sort_translit = true; - }; + pkgs, + ... +}: { + # REF: https://github.com/sxyazi/yazi/blob/main/yazi-config/preset/yazi.toml + file = (pkgs.formats.toml { }).generate "YaziYaziConfig" { + manager = { + # linemode = "mtime"; + mouse_events = [ ]; + ratio = [ 1 4 3 ]; + scrolloff = 1; + show_hidden = false; + show_symlink = true; + sort_by = "natural"; + sort_dir_first = true; + sort_sensitive = true; + sort_translit = true; + }; - preview = { - # image_filter = "triangle"; - image_filter = "lanczos3"; - image_quality = 80; - }; + preview = { + # image_filter = "triangle"; + image_filter = "lanczos3"; + image_quality = 80; + }; - opener = - let - openWith = app: "${app} \"$@\""; - in - { - default = [ - { - desc = "Default"; - orphan = true; - run = openWith "xdg-open"; - } - ]; - archive = [ - { - desc = "Archive"; - run = openWith "archive"; - } - ]; - archive_fast = [ - { - desc = "Archive Fast"; - run = openWith "archive_fast"; - } - ]; - audio = [ - { - desc = "Audio"; - orphan = true; - run = openWith "mpv --no-video"; - } - ]; - browser = [ - { - desc = "Browser"; - orphan = true; - run = openWith "firefox-esr"; - } - ]; - document = [ - { - desc = "Document"; - orphan = true; - run = openWith "onlyoffice-desktopeditors"; - } - ]; - hex = [ - { - desc = "Hex"; - block = true; - run = openWith "radare2 -c V -w"; - } - ]; - image = [ - { - desc = "Image"; - orphan = true; - run = openWith "loupe"; - } - ]; - image_edit = [ - { - desc = "Image Edit"; - orphan = true; - run = openWith "gimp"; - } - ]; - mount = [ - { - desc = "Mount"; - run = openWith "fmount"; - } - ]; - pdf = [ - { - desc = "Pdf"; - orphan = true; - run = openWith "evince"; - } - ]; - text = [ - { - desc = "Text"; - block = true; - run = openWith "nvim"; - } - ]; - video = [ - { - desc = "Video"; - orphan = true; - run = openWith "mpv"; - } - ]; - unlock = [ - { - desc = "Unlock"; - block = true; - run = openWith "funlock"; - } - ]; - unpack = [ - { - desc = "Unpack"; - run = openWith "unpack"; - } - ]; - }; + opener = let + openWith = app: "${app} \"$@\""; + in { + default = [{ + desc = "Default"; + orphan = true; + run = openWith "xdg-open"; + }]; + archive = [{ + desc = "Archive"; + run = openWith "archive"; + }]; + archive_fast = [{ + desc = "Archive Fast"; + run = openWith "archive_fast"; + }]; + audio = [{ + desc = "Audio"; + orphan = true; + run = openWith "mpv --no-video"; + }]; + browser = [{ + desc = "Browser"; + orphan = true; + run = openWith "firefox-esr"; + }]; + document = [{ + desc = "Document"; + orphan = true; + run = openWith "onlyoffice-desktopeditors"; + }]; + hex = [{ + desc = "Hex"; + block = true; + run = openWith "radare2 -c V -w"; + }]; + image = [{ + desc = "Image"; + orphan = true; + run = openWith "loupe"; + }]; + image_edit = [{ + desc = "Image Edit"; + orphan = true; + run = openWith "gimp"; + }]; + mount = [{ + desc = "Mount"; + run = openWith "fmount"; + }]; + pdf = [{ + desc = "Pdf"; + orphan = true; + run = openWith "evince"; + }]; + text = [{ + desc = "Text"; + block = true; + run = openWith "nvim"; + }]; + video = [{ + desc = "Video"; + orphan = true; + run = openWith "mpv"; + }]; + unlock = [{ + desc = "Unlock"; + block = true; + run = openWith "funlock"; + }]; + unpack = [{ + desc = "Unpack"; + run = openWith "unpack"; + }]; + }; - open = { - rules = - let - defaultUse = [ - "text" - "archive" - "archive_fast" - "hex" - ]; - mkMime = mime: use: { - inherit mime; - use = use ++ defaultUse; - }; - mkName = name: use: { - inherit name; - use = use ++ defaultUse; - }; - in - [ - # Use `file -i file.txt` to find file mime type. - # Use `xdg-mime query default "text/plain"` to find default app. - (mkMime "application/gzip" [ "unpack" ]) - (mkMime "application/x-tar" [ "unpack" ]) - (mkMime "application/x-xz" [ "unpack" ]) - (mkMime "application/zip" [ "unpack" ]) - (mkMime "application/x-7z-compressed" [ "unpack" ]) - (mkMime "application/x-iso9660-image" [ "mount" ]) - (mkMime "application/x-raw-disk-image" [ "unlock" ]) - (mkMime "application/pdf" [ "pdf" ]) - (mkMime "audio/*" [ "audio" ]) - (mkName "*.mka" [ "audio" ]) - (mkMime "image/*" [ - "image" - "image_edit" - ]) - (mkMime "video/*" [ "video" ]) - (mkMime "text/html" [ "browser" ]) - (mkMime "application/vnd.openxmlformats-officedocument.*" [ "document" ]) - (mkMime "*" [ ]) - ]; - }; + open = { + rules = let + defaultUse = [ + "text" + "archive" + "archive_fast" + "hex" + ]; + mkMime = mime: use: { + inherit mime; + use = use ++ defaultUse; + }; + mkName = name: use: { + inherit name; + use = use ++ defaultUse; + }; + in [ + # Use `file -i file.txt` to find file mime type. + # Use `xdg-mime query default "text/plain"` to find default app. + (mkMime "application/gzip" [ "unpack" ]) + (mkMime "application/x-tar" [ "unpack" ]) + (mkMime "application/x-xz" [ "unpack" ]) + (mkMime "application/zip" [ "unpack" ]) + (mkMime "application/x-7z-compressed" [ "unpack" ]) + (mkMime "application/x-iso9660-image" [ "mount" ]) + (mkMime "application/x-raw-disk-image" [ "unlock" ]) + (mkMime "application/pdf" [ "pdf" ]) + (mkMime "audio/*" [ "audio" ]) + (mkName "*.mka" [ "audio" ]) + (mkMime "image/*" [ "image" "image_edit" ]) + (mkMime "video/*" [ "video" ]) + (mkMime "text/html" [ "browser" ]) + (mkMime "application/vnd.openxmlformats-officedocument.*" [ "document" ]) + (mkMime "*" [ ]) + ]; + }; - which = { - sort_by = "key"; - sort_sensitive = false; - }; - }; + which = { + sort_by = "key"; + sort_sensitive = false; + }; + }; } diff --git a/home/program/bash/default.nix b/home/program/bash/default.nix index 9bc695c..5e0627e 100644 --- a/home/program/bash/default.nix +++ b/home/program/bash/default.nix @@ -1,42 +1,42 @@ -{ util, pkgs, ... }@args: -let - modules = util.catText (util.ls ./module) args; - modulesFile = pkgs.writeText "BashModules" modules; -in { - inherit modules modulesFile; + util, + pkgs, + ... +} @args: let + modules = util.catText (util.ls ./module) args; + modulesFile = pkgs.writeText "BashModules" modules; +in { + inherit modules modulesFile; - bashrc = - modules - + '' - # Find all functions. - function find_function() { - /usr/bin/env cat ${modulesFile} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//" - } + bashrc = modules + '' + # Find all functions. + function find_function() { + /usr/bin/env cat ${modulesFile} | /usr/bin/env grep "^function.*()" | /usr/bin/env sed -e "s/^function //" -e "s/().*//" + } - # Export all functions. - export -f $(find_function | tr '\n' ' ') - export -f find_function + # Export all functions. + export -f $(find_function | tr '\n' ' ') + export -f find_function - # Autostart Sway. - if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then - exec sway - fi - ''; + # Autostart Sway. + if [[ -z $DISPLAY ]] && [[ "$(tty)" = "/dev/tty1" ]]; then + exec sway + fi + ''; - # bash_profile = '' - # # Home manager. - # [ -e ~/.nix-profile/etc/profile.d/nix.sh ] && source ~/.nix-profile/etc/profile.d/nix.sh + # bash_profile = '' + # # Home manager. + # [ -e ~/.nix-profile/etc/profile.d/nix.sh ] && source ~/.nix-profile/etc/profile.d/nix.sh - # # Bashrc. - # [ -f ~/.bashrc ] && source ~/.bashrc + # # Bashrc. + # [ -f ~/.bashrc ] && source ~/.bashrc - # # Profile. - # [ -f ~/.profile ] && source ~/.profile - # ''; + # # Profile. + # [ -f ~/.profile ] && source ~/.profile + # ''; - # profile = '' - # # Load HM vars. - # [ -e ~/.nix-profile/etc/profile.d/hm-session-vars.sh ] && source ~/.nix-profile/etc/profile.d/hm-session-vars.sh - # ''; + # profile = '' + # # Load HM vars. + # [ -e ~/.nix-profile/etc/profile.d/hm-session-vars.sh ] && source ~/.nix-profile/etc/profile.d/hm-session-vars.sh + # ''; } diff --git a/home/program/bash/module/Archive.nix b/home/program/bash/module/Archive.nix index 8abe055..ca755ab 100644 --- a/home/program/bash/module/Archive.nix +++ b/home/program/bash/module/Archive.nix @@ -1,423 +1,422 @@ -{ ... }: -{ - text = '' - export _archive_pattern="_[0-9]{12}-[[:alnum:]]{40}" - export _archive_pattern_compressed="_[0-9]{12}-[[:alnum:]]{40}\.t(ar|gz|xz)$" - export _archive_pattern_fast="_[0-9]{12}-[[:alnum:]]{40}\.tar$" - - # Archive using multiple threads. Uses 75% of free RAM. - # All directories by default. - # Supports .archiveignore exclude file. - # Usage: archive [DIRS] - function archive() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_dir)) - - process() { - # Skip if already an archive. - _is_archive "''${target}" && { - _iterate_skip "Already an archive." - return 0 - }; - - # Cut full paths. - [[ "''${target##*/}" = "" ]] || target="''${target##*/}" - - local date=$(_archive_date) - - # Parse name. - local name=$(parse_pascal ''${target}) - - # Exclude support. - local exclude="" - [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" - [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" - - # Create archive. - local hash=$(tar ''${exclude} -c ''${target} | pv -s $(/usr/bin/env du -sb ''${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=$(_archive_memlimit) | tee ''${name}.txz | sha1sum | cut -d\ -f1) - - # Append hash to target name. - local new_name="''${name}_''${date}-''${hash}.txz" - mv -- ''${name}.txz ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Creates a simple archive. - # If it is a file, it just reformats file name to match archive name. - # For dirs, it first creates a tar archive. - # All files by default. - # Usage: archive_fast [DIRS] - function archive_fast() { - local IFS=$'\n' - local targets=("''${@}") - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - - process() { - # Skip if already an archive. - _is_archive "''${target}" && { - _iterate_skip "Already an archive." - return 0 - }; - - # Cut full paths. - [[ "''${target##*/}" = "" ]] || target="''${target##*/}" - - # Start timestamp. - local date=$(_archive_date) - - # Exclude support. - local exclude - [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" - [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" - - local name - local extension - - if [[ -d "''${target}" ]]; then - name=$(parse_pascal "''${target}") - - # Create archive. - local hash=$(tar ''${exclude} -c "''${target}" | pv -s $(/usr/bin/env du -sb "''${target}" | awk '{print $1}') | tee "''${name}".tar | sha1sum | cut -d\ -f1) - - # Append hash to target name. - local new_name="''${name}_''${date}-''${hash}.tar" - mv -- "''${name}".tar ''${new_name} && echo ''${new_name} - else - name=$(parse_pascal "''${target%.*}") - extension=".''${target##*.}" - - # Check if extension matches name, then drop it. - [[ "''${extension}" = ".''${target%.*}" ]] && extension="" - - local hash=$(pv "''${target}" | sha1sum | cut -d\ -f1) - local new_name="''${name}_''${date}-''${hash}''${extension}" - mv -- "''${target}" "''${new_name}" && echo ''${new_name} - fi - } - - _iterate_targets process ''${targets[@]} - } - - # Check archives integrity. - # Checks all archives by default. - # Usage: archive_check [FILES] - function archive_check() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) - - process() { - _archive_check "''${target}" - } - - _iterate_targets process ''${targets[@]} - } - - # Delete old versions of an archive. - # All archives with 1 version by default. - # Usage: archive_prune [NAME] [VERSIONS] - function archive_prune() { - local IFS=$'\n' - local targets=(''${1}) - local versions=''${2} - - [[ "''${targets}" = "" ]] && targets=($(_archive_names)) - [[ "''${versions}" = "" ]] && versions=1 - - if [[ ''${#} -gt 2 ]]; then - help archive_prune - return 2 - fi - - process() { - local prune=($(ls | grep -E "^''${target}''${_archive_pattern}" | sort -r | sed -e "1,''${versions}d")) - - for archive in ''${prune[@]}; do - rm -- "''${archive}" && echo "''${archive}" - done - } - - _iterate_targets process ''${targets[@]} - } - - # Delete specified or all archive files. - # Usage: archive_rm [FILES] - function archive_rm() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) - - process() { - rm -- "''${target}" && echo "''${target}" - } - - _iterate_targets process ''${targets[@]} - } - - # Recompress previously created archive_fast with better compression. - # Usage: archive_compress [FILES] - function archive_compress() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=$(_ls_archive_fast) - - process() { - local data=($(_archive_parse "''${target}")) - local tmp="''${data[0]}.txz" - - # Check that old format. - if [[ "''${data[3]}" != "tar" ]]; then - _iterate_skip "Not in .tar format!" - return 0 - fi - - # Check integrity. - _archive_check "''${target}" || return 1 - - # Recompress. - local hash=$(pv "''${target}" | xz -9e --threads=0 --memlimit=$(_archive_memlimit) | tee "''${tmp}" | sha1sum | cut -d\ -f1) - - # Rename. - local new_name="''${data[0]}_''${data[1]}-''${hash}.txz" - mv -- ''${tmp} ''${new_name} && rm ''${target} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Rename archives. - # If no name specified, it simplifies archive's name. - # If no archives specified, apply to all archives. - # Usage: archive_name [ARCHIVE] [NAME] - function archive_name() { - local IFS=$'\n' - local targets="''${1}" - local name="''${2}" - [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) - - process() { - # Simplify name by default. - if [[ "''${name}" = "" || ''${count} -gt 1 ]]; then - name="''${target%_*}" - name="$(parse_pascal ''${name})" - fi - - # Remove old name. - local data="''${target##*_}" - local new_name="''${name}_''${data}" - - # Check for the same name. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Check for existing target. - if [[ -f "''${new_name}" ]]; then - _error "''${new_name}: Already exists!" - return 1 - fi - - # Rename. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Extract previously created archive with checksum validation. - # Supports unarchiving exact paths from the remote machines (rsync syntax). - # Usage: unarchive [HOST:FILES] - function unarchive() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=$(_ls_archive_compressed) - - process() { - # Validate. - # _archive_check "''${target}" || return 1 - if ! _is_compressed_archive "''${target}"; then - _iterate_skip "Not a compressed archive." - return 0 - fi - - # Remote archives. - local remote - local file="''${target}" - - if [[ "''${target//\\:/}" == *:* ]]; then - local host="''${target%%:*}" - file="''${target#*:}" - remote=(trysudo ssh ''${host}) - fi - - # Extract. - case "''${file##*.}" in - "txz") - ''${remote[@]} pv -f ''${file} | xz -d | tar -xf - - ;; - "tar") - ''${remote[@]} pv -f ''${file} | tar -xf - - ;; - "tgz") - ''${remote[@]} pv -f ''${file} | gzip -d | tar -xf - - ;; - esac - } - - _iterate_targets process ''${targets[@]} - } - - # Change archive's filesystem time to match creation date. - # Usage: archive_touch [FILES] - function archive_touch() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=$(_ls_archive) - - process() { - local data=($(_archive_parse "''${target}")) - local date=''${data[1]} - touch -t ''${date} -- ''${target} - } - - _iterate_targets process ''${targets[@]} - } - - # Parse archive file name to get: name, date, hash and format. - # Usage: _archive_parse - function _archive_parse() { - local input="''${1}" - local name="''${input%_*}" - local format="''${input##*.}" - local data="''${input##*_}"; data="''${data%.*}" - local date="''${data%%-*}" - local hash="''${data##*-}" - - # No extension if no dots. - [[ "''${input}" = *\.* ]] || format="" - - echo "''${name}" - echo "''${date}" - echo "''${hash}" - echo "''${format}" - } - - # Autocomplete for archive_name function. - # First arg is the archives list, second one is selected archive's current name. - function _comp_archive_name() { - local IFS=$'\n' - COMPREPLY=() - - local cur="''${COMP_WORDS[COMP_CWORD]}" - local prev="''${COMP_WORDS[COMP_CWORD-1]}" - local command="''${COMP_WORDS[0]}" - - if [[ "''${prev}" = "''${command}" ]]; then - COMPREPLY=( $(compgen -W "$(ls | grep -E ''${_archive_pattern})" -- ''${cur}) ) - return 0 - else - local data=($(_archive_parse ''${prev})) - local name="''${data[0]}" - COMPREPLY=( $(compgen -W "''${name}" -- ''${cur}) ) - return 0 - fi - } - - # Autocomplete with archives in current dir. - function _comp_archive_grep() { - _autocomplete_grep ''${_archive_pattern} - } - - # Autocomplete with fast archives in current dir. - function _comp_archive_grep_fast() { - _autocomplete_grep ''${_archive_pattern_fast} - } - - # Get date for a new archive. - function _archive_date() { - date +%Y%m%d%H%M - } - - # Get names of all archives. - function _archive_names() { - local IFS=$'\n' - local archives=($(_ls_archive)) - local names=() - - for archive in ''${archives[@]}; do - local data=($(_archive_parse ''${archive})) - names+=(''${data[0]}) - done - - # Remove copies. - names=($(printf '%s\n' "''${names[@]}" | sort -u)) - - printf '%s\n' "''${names[@]}" - } - - # Autocomplete with names of all archives. - function _comp_archive_names() { - _autocomplete_first $(_archive_names) - } - - # Check if file is an archive. - function _is_archive() { - local target="''${*}" - local out=$(echo "''${target##*/}" | grep -E ''${_archive_pattern}) - - [[ "''${out}" != "" ]] - } - - # Check if file is a compressed archive. - function _is_compressed_archive() { - local out=$(echo "''${*}" | grep -E ''${_archive_pattern_compressed}) - - [[ "''${out}" != "" ]] - } - - # List all archives. - function _ls_archive() { - ls | grep -E ''${_archive_pattern} - } - - # List fast archives. - function _ls_archive_fast() { - ls | grep -E ''${_archive_pattern_fast} - } - - # List fast archives. - function _ls_archive_compressed() { - ls | grep -E ''${_archive_pattern_compressed} - } - - # Filter input for archives only. - function _filter_archive() { - grep -E ''${_archive_pattern} - } - - function _archive_memlimit() { - local mem_free=$(_mem_free) - local mem_limit=$((mem_free*3/4)) - - echo "''${mem_limit}MiB" - } - - function _archive_check() { - # Extract hash from name. - local data=($(_archive_parse ''${target})) - local saved=''${data[2]} - - # Calculate actual hash. - local actual=$(pv ''${target} | sha1sum | cut -d\ -f1) - - # Compare hashes. - [[ "''${actual}" = "''${saved}" ]] || _error "Archive check failed." - } - - # complete -o filenames -F _comp_archive_grep archive_check unarchive archive_rm archive_touch - # complete -o filenames -F _comp_archive_grep_fast archive_xz - complete -o filenames -F _comp_archive_name archive_name - complete -o filenames -F _comp_archive_names archive_prune - ''; +{ ... }: { + text = '' + export _archive_pattern="_[0-9]{12}-[[:alnum:]]{40}" + export _archive_pattern_compressed="_[0-9]{12}-[[:alnum:]]{40}\.t(ar|gz|xz)$" + export _archive_pattern_fast="_[0-9]{12}-[[:alnum:]]{40}\.tar$" + + # Archive using multiple threads. Uses 75% of free RAM. + # All directories by default. + # Supports .archiveignore exclude file. + # Usage: archive [DIRS] + function archive() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_dir)) + + process() { + # Skip if already an archive. + _is_archive "''${target}" && { + _iterate_skip "Already an archive." + return 0 + }; + + # Cut full paths. + [[ "''${target##*/}" = "" ]] || target="''${target##*/}" + + local date=$(_archive_date) + + # Parse name. + local name=$(parse_pascal ''${target}) + + # Exclude support. + local exclude="" + [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" + [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" + + # Create archive. + local hash=$(tar ''${exclude} -c ''${target} | pv -s $(/usr/bin/env du -sb ''${target} | awk '{print $1}') | xz -9e --threads=0 --memlimit=$(_archive_memlimit) | tee ''${name}.txz | sha1sum | cut -d\ -f1) + + # Append hash to target name. + local new_name="''${name}_''${date}-''${hash}.txz" + mv -- ''${name}.txz ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Creates a simple archive. + # If it is a file, it just reformats file name to match archive name. + # For dirs, it first creates a tar archive. + # All files by default. + # Usage: archive_fast [DIRS] + function archive_fast() { + local IFS=$'\n' + local targets=("''${@}") + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + process() { + # Skip if already an archive. + _is_archive "''${target}" && { + _iterate_skip "Already an archive." + return 0 + }; + + # Cut full paths. + [[ "''${target##*/}" = "" ]] || target="''${target##*/}" + + # Start timestamp. + local date=$(_archive_date) + + # Exclude support. + local exclude + [[ -f ".archiveignore" ]] && exclude="--exclude-from=.archiveignore" + [[ -f "''${target}/.archiveignore" ]] && exclude="--exclude-from=''${target}/.archiveignore" + + local name + local extension + + if [[ -d "''${target}" ]]; then + name=$(parse_pascal "''${target}") + + # Create archive. + local hash=$(tar ''${exclude} -c "''${target}" | pv -s $(/usr/bin/env du -sb "''${target}" | awk '{print $1}') | tee "''${name}".tar | sha1sum | cut -d\ -f1) + + # Append hash to target name. + local new_name="''${name}_''${date}-''${hash}.tar" + mv -- "''${name}".tar ''${new_name} && echo ''${new_name} + else + name=$(parse_pascal "''${target%.*}") + extension=".''${target##*.}" + + # Check if extension matches name, then drop it. + [[ "''${extension}" = ".''${target%.*}" ]] && extension="" + + local hash=$(pv "''${target}" | sha1sum | cut -d\ -f1) + local new_name="''${name}_''${date}-''${hash}''${extension}" + mv -- "''${target}" "''${new_name}" && echo ''${new_name} + fi + } + + _iterate_targets process ''${targets[@]} + } + + # Check archives integrity. + # Checks all archives by default. + # Usage: archive_check [FILES] + function archive_check() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) + + process() { + _archive_check "''${target}" + } + + _iterate_targets process ''${targets[@]} + } + + # Delete old versions of an archive. + # All archives with 1 version by default. + # Usage: archive_prune [NAME] [VERSIONS] + function archive_prune() { + local IFS=$'\n' + local targets=(''${1}) + local versions=''${2} + + [[ "''${targets}" = "" ]] && targets=($(_archive_names)) + [[ "''${versions}" = "" ]] && versions=1 + + if [[ ''${#} -gt 2 ]]; then + help archive_prune + return 2 + fi + + process() { + local prune=($(ls | grep -E "^''${target}''${_archive_pattern}" | sort -r | sed -e "1,''${versions}d")) + + for archive in ''${prune[@]}; do + rm -- "''${archive}" && echo "''${archive}" + done + } + + _iterate_targets process ''${targets[@]} + } + + # Delete specified or all archive files. + # Usage: archive_rm [FILES] + function archive_rm() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) + + process() { + rm -- "''${target}" && echo "''${target}" + } + + _iterate_targets process ''${targets[@]} + } + + # Recompress previously created archive_fast with better compression. + # Usage: archive_compress [FILES] + function archive_compress() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=$(_ls_archive_fast) + + process() { + local data=($(_archive_parse "''${target}")) + local tmp="''${data[0]}.txz" + + # Check that old format. + if [[ "''${data[3]}" != "tar" ]]; then + _iterate_skip "Not in .tar format!" + return 0 + fi + + # Check integrity. + _archive_check "''${target}" || return 1 + + # Recompress. + local hash=$(pv "''${target}" | xz -9e --threads=0 --memlimit=$(_archive_memlimit) | tee "''${tmp}" | sha1sum | cut -d\ -f1) + + # Rename. + local new_name="''${data[0]}_''${data[1]}-''${hash}.txz" + mv -- ''${tmp} ''${new_name} && rm ''${target} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename archives. + # If no name specified, it simplifies archive's name. + # If no archives specified, apply to all archives. + # Usage: archive_name [ARCHIVE] [NAME] + function archive_name() { + local IFS=$'\n' + local targets="''${1}" + local name="''${2}" + [[ "''${targets}" = "" ]] && targets=($(_ls_archive)) + + process() { + # Simplify name by default. + if [[ "''${name}" = "" || ''${count} -gt 1 ]]; then + name="''${target%_*}" + name="$(parse_pascal ''${name})" + fi + + # Remove old name. + local data="''${target##*_}" + local new_name="''${name}_''${data}" + + # Check for the same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Check for existing target. + if [[ -f "''${new_name}" ]]; then + _error "''${new_name}: Already exists!" + return 1 + fi + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Extract previously created archive with checksum validation. + # Supports unarchiving exact paths from the remote machines (rsync syntax). + # Usage: unarchive [HOST:FILES] + function unarchive() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=$(_ls_archive_compressed) + + process() { + # Validate. + # _archive_check "''${target}" || return 1 + if ! _is_compressed_archive "''${target}"; then + _iterate_skip "Not a compressed archive." + return 0 + fi + + # Remote archives. + local remote + local file="''${target}" + + if [[ "''${target//\\:/}" == *:* ]]; then + local host="''${target%%:*}" + file="''${target#*:}" + remote=(trysudo ssh ''${host}) + fi + + # Extract. + case "''${file##*.}" in + "txz") + ''${remote[@]} pv -f ''${file} | xz -d | tar -xf - + ;; + "tar") + ''${remote[@]} pv -f ''${file} | tar -xf - + ;; + "tgz") + ''${remote[@]} pv -f ''${file} | gzip -d | tar -xf - + ;; + esac + } + + _iterate_targets process ''${targets[@]} + } + + # Change archive's filesystem time to match creation date. + # Usage: archive_touch [FILES] + function archive_touch() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=$(_ls_archive) + + process() { + local data=($(_archive_parse "''${target}")) + local date=''${data[1]} + touch -t ''${date} -- ''${target} + } + + _iterate_targets process ''${targets[@]} + } + + # Parse archive file name to get: name, date, hash and format. + # Usage: _archive_parse + function _archive_parse() { + local input="''${1}" + local name="''${input%_*}" + local format="''${input##*.}" + local data="''${input##*_}"; data="''${data%.*}" + local date="''${data%%-*}" + local hash="''${data##*-}" + + # No extension if no dots. + [[ "''${input}" = *\.* ]] || format="" + + echo "''${name}" + echo "''${date}" + echo "''${hash}" + echo "''${format}" + } + + # Autocomplete for archive_name function. + # First arg is the archives list, second one is selected archive's current name. + function _comp_archive_name() { + local IFS=$'\n' + COMPREPLY=() + + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" + + if [[ "''${prev}" = "''${command}" ]]; then + COMPREPLY=( $(compgen -W "$(ls | grep -E ''${_archive_pattern})" -- ''${cur}) ) + return 0 + else + local data=($(_archive_parse ''${prev})) + local name="''${data[0]}" + COMPREPLY=( $(compgen -W "''${name}" -- ''${cur}) ) + return 0 + fi + } + + # Autocomplete with archives in current dir. + function _comp_archive_grep() { + _autocomplete_grep ''${_archive_pattern} + } + + # Autocomplete with fast archives in current dir. + function _comp_archive_grep_fast() { + _autocomplete_grep ''${_archive_pattern_fast} + } + + # Get date for a new archive. + function _archive_date() { + date +%Y%m%d%H%M + } + + # Get names of all archives. + function _archive_names() { + local IFS=$'\n' + local archives=($(_ls_archive)) + local names=() + + for archive in ''${archives[@]}; do + local data=($(_archive_parse ''${archive})) + names+=(''${data[0]}) + done + + # Remove copies. + names=($(printf '%s\n' "''${names[@]}" | sort -u)) + + printf '%s\n' "''${names[@]}" + } + + # Autocomplete with names of all archives. + function _comp_archive_names() { + _autocomplete_first $(_archive_names) + } + + # Check if file is an archive. + function _is_archive() { + local target="''${*}" + local out=$(echo "''${target##*/}" | grep -E ''${_archive_pattern}) + + [[ "''${out}" != "" ]] + } + + # Check if file is a compressed archive. + function _is_compressed_archive() { + local out=$(echo "''${*}" | grep -E ''${_archive_pattern_compressed}) + + [[ "''${out}" != "" ]] + } + + # List all archives. + function _ls_archive() { + ls | grep -E ''${_archive_pattern} + } + + # List fast archives. + function _ls_archive_fast() { + ls | grep -E ''${_archive_pattern_fast} + } + + # List fast archives. + function _ls_archive_compressed() { + ls | grep -E ''${_archive_pattern_compressed} + } + + # Filter input for archives only. + function _filter_archive() { + grep -E ''${_archive_pattern} + } + + function _archive_memlimit() { + local mem_free=$(_mem_free) + local mem_limit=$((mem_free*3/4)) + + echo "''${mem_limit}MiB" + } + + function _archive_check() { + # Extract hash from name. + local data=($(_archive_parse ''${target})) + local saved=''${data[2]} + + # Calculate actual hash. + local actual=$(pv ''${target} | sha1sum | cut -d\ -f1) + + # Compare hashes. + [[ "''${actual}" = "''${saved}" ]] || _error "Archive check failed." + } + + # complete -o filenames -F _comp_archive_grep archive_check unarchive archive_rm archive_touch + # complete -o filenames -F _comp_archive_grep_fast archive_xz + complete -o filenames -F _comp_archive_name archive_name + complete -o filenames -F _comp_archive_names archive_prune + ''; } diff --git a/home/program/bash/module/Ask.nix b/home/program/bash/module/Ask.nix index 59cf648..62681a8 100644 --- a/home/program/bash/module/Ask.nix +++ b/home/program/bash/module/Ask.nix @@ -1,28 +1,27 @@ -{ ... }: -{ - text = '' - # Ask general AI. - # Usage: ask - function ask() { - curl http://localhost:11434/api/generate -d "{ - \"model\":\"''${OLLAMA_MODEL}\", - \"raw\":true, - \"prompt\":\"''${*}\" - }" 2> /dev/null | parallel -j1 -- "printf '%s\n' {} | jq -r .response | sed -e 's/^$/\+\+\+/' | tr -d '\n' | sed -e 's/\+\+\+/\n/'" - echo - } +{ ... }: { + text = '' + # Ask general AI. + # Usage: ask + function ask() { + curl http://localhost:11434/api/generate -d "{ + \"model\":\"''${OLLAMA_MODEL}\", + \"raw\":true, + \"prompt\":\"''${*}\" + }" 2> /dev/null | parallel -j1 -- "printf '%s\n' {} | jq -r .response | sed -e 's/^$/\+\+\+/' | tr -d '\n' | sed -e 's/\+\+\+/\n/'" + echo + } - # Specify ask model. - function ask_model() { - export OLLAMA_MODEL="''${1}" - } + # Specify ask model. + function ask_model() { + export OLLAMA_MODEL="''${1}" + } - function _complete_ask_model() { - local IFS=$'\n' - local models=($(ollama list | sed -e "1d" | cut -f1)) - _autocomplete_first ''${models[@]} - } + function _complete_ask_model() { + local IFS=$'\n' + local models=($(ollama list | sed -e "1d" | cut -f1)) + _autocomplete_first ''${models[@]} + } - complete -F _complete_ask_model ask_model - ''; + complete -F _complete_ask_model ask_model + ''; } diff --git a/home/program/bash/module/Autocomplete.nix b/home/program/bash/module/Autocomplete.nix index ed62b82..ecf1b12 100644 --- a/home/program/bash/module/Autocomplete.nix +++ b/home/program/bash/module/Autocomplete.nix @@ -1,88 +1,87 @@ -{ ... }: -{ - text = '' - # Bash autocomplete. - # There are also options like -o nospace. see man for more info. - # Usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo - function _autocomplete() { - local IFS=$'\n' - local commands="''${*}" +{ ... }: { + text = '' + # Bash autocomplete. + # There are also options like -o nospace. see man for more info. + # Usage: _foo() { _autocomplete "{foo,bar}" } ; complete -F _foo foo + function _autocomplete() { + local IFS=$'\n' + local commands="''${*}" - COMPREPLY=() + COMPREPLY=() - local cur="''${COMP_WORDS[COMP_CWORD]}" - local prev="''${COMP_WORDS[COMP_CWORD-1]}" - local command="''${COMP_WORDS[0]}" + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" - COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) - return 0 - } + COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) + return 0 + } - # Autocomplete only first argument. - function _autocomplete_first() { - local IFS=$'\n' - local commands="''${*}" + # Autocomplete only first argument. + function _autocomplete_first() { + local IFS=$'\n' + local commands="''${*}" - COMPREPLY=() + COMPREPLY=() - local cur="''${COMP_WORDS[COMP_CWORD]}" - local prev="''${COMP_WORDS[COMP_CWORD-1]}" - local command="''${COMP_WORDS[0]}" + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" - if [[ "''${prev}" = "''${command}" ]]; then - COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) - return 0 - fi - } + if [[ "''${prev}" = "''${command}" ]]; then + COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) + return 0 + fi + } - # Autocomplete only first argument and the rest with files. - function _autocomplete_first_ls() { - local IFS=$'\n' - local commands="''${*}" + # Autocomplete only first argument and the rest with files. + function _autocomplete_first_ls() { + local IFS=$'\n' + local commands="''${*}" - COMPREPLY=() + COMPREPLY=() - local cur="''${COMP_WORDS[COMP_CWORD]}" - local prev="''${COMP_WORDS[COMP_CWORD-1]}" - local command="''${COMP_WORDS[0]}" + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" - if [[ "''${prev}" = "''${command}" ]]; then - COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) - return 0 - else - COMPREPLY=( $(compgen -W "$(ls)" -- ''${cur}) ) - return 0 - fi - } + if [[ "''${prev}" = "''${command}" ]]; then + COMPREPLY=( $(compgen -W "''${commands}" -- ''${cur}) ) + return 0 + else + COMPREPLY=( $(compgen -W "$(ls)" -- ''${cur}) ) + return 0 + fi + } - # Autocomplete by grepping file names. - function _autocomplete_grep() { - local IFS=$'\n' - COMPREPLY=() + # Autocomplete by grepping file names. + function _autocomplete_grep() { + local IFS=$'\n' + COMPREPLY=() - local pattern="''${1}" - local cur="''${COMP_WORDS[COMP_CWORD]}" - local prev="''${COMP_WORDS[COMP_CWORD-1]}" - local command="''${COMP_WORDS[0]}" + local pattern="''${1}" + local cur="''${COMP_WORDS[COMP_CWORD]}" + local prev="''${COMP_WORDS[COMP_CWORD-1]}" + local command="''${COMP_WORDS[0]}" - COMPREPLY=( $(compgen -W "$(ls | grep -E ''${pattern})" -- ''${cur}) ) - return 0 - } + COMPREPLY=( $(compgen -W "$(ls | grep -E ''${pattern})" -- ''${cur}) ) + return 0 + } - # Autocomplete nested program. - function _autocomplete_nested() { - # local IFS=$'\n' - local cur prev words cword split i - _init_completion -s || return + # Autocomplete nested program. + function _autocomplete_nested() { + # local IFS=$'\n' + local cur prev words cword split i + _init_completion -s || return - for ((i = 1; i <= cword; i++)); do - if [[ ''${words[i]} != -* ]]; then - local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin - local root_command=''${words[i]} - _command_offset ''${i} - return - fi - done - } - ''; + for ((i = 1; i <= cword; i++)); do + if [[ ''${words[i]} != -* ]]; then + local PATH=$PATH:/sbin:/usr/sbin:/usr/local/sbin + local root_command=''${words[i]} + _command_offset ''${i} + return + fi + done + } + ''; } diff --git a/home/program/bash/module/Battery.nix b/home/program/bash/module/Battery.nix index 3ca1c89..4013582 100644 --- a/home/program/bash/module/Battery.nix +++ b/home/program/bash/module/Battery.nix @@ -1,17 +1,16 @@ -{ ... }: -{ - text = '' - # Print current battery charge level in percents. - function battery_level() { - head -c -1 /sys/class/power_supply/BAT*/capacity - echo '%' - } +{ ... }: { + text = '' + # Print current battery charge level in percents. + function battery_level() { + head -c -1 /sys/class/power_supply/BAT*/capacity + echo '%' + } - # Get battery's info. - function battery_info() { - local IFS=$'\n' - local battery=("$(upower --enumerate | grep battery_BAT)") - upower -i "''${battery[0]}" - } - ''; + # Get battery's info. + function battery_info() { + local IFS=$'\n' + local battery=("$(upower --enumerate | grep battery_BAT)") + upower -i "''${battery[0]}" + } + ''; } diff --git a/home/program/bash/module/Brightness.nix b/home/program/bash/module/Brightness.nix index eb45300..e681f27 100644 --- a/home/program/bash/module/Brightness.nix +++ b/home/program/bash/module/Brightness.nix @@ -1,23 +1,22 @@ -{ ... }: -{ - text = '' - # Set display brightness to a minimum. - function brmin() { - light -S 0.01 - } +{ ... }: { + text = '' + # Set display brightness to a minimum. + function brmin() { + light -S 0.01 + } - # Set display brightness to a maximum. - function brmax() { - light -S 100 - } + # Set display brightness to a maximum. + function brmax() { + light -S 100 + } - # Set display brightness in percent, 50% default. - # Usage: brset [LEVEL] - function brset() { - local level=''${1} - [[ "''${level}" = "" ]] && level=50 + # Set display brightness in percent, 50% default. + # Usage: brset [LEVEL] + function brset() { + local level=''${1} + [[ "''${level}" = "" ]] && level=50 - light -S ''${level} - } - ''; + light -S ''${level} + } + ''; } diff --git a/home/program/bash/module/Cd.nix b/home/program/bash/module/Cd.nix index e4ef4a5..e390d8b 100644 --- a/home/program/bash/module/Cd.nix +++ b/home/program/bash/module/Cd.nix @@ -1,74 +1,73 @@ -{ ... }: -{ - text = '' - # CD (back to) directory. - # Goes to the exact-match dir first. If no exact match found, it finds first directory that contains the input (case-insensitive). - # Usage: cdd - function cdd() { - local target="''${1}" +{ ... }: { + text = '' + # CD (back to) directory. + # Goes to the exact-match dir first. If no exact match found, it finds first directory that contains the input (case-insensitive). + # Usage: cdd + function cdd() { + local target="''${1}" - if [[ "''${target}" = "" ]]; then - help cdd - return 2 - fi + if [[ "''${target}" = "" ]]; then + help cdd + return 2 + fi - local array=($(_cdd_directories)) - local result + local array=($(_cdd_directories)) + local result - # Check for exact match ELSE look for containing. - if _contains ''${target} ''${array[@]}; then - local current="''${PWD%/*}" - result="''${current%\/$target\/*}/''${target}" - else - # Make search case-insensitive. - shopt -s nocasematch + # Check for exact match ELSE look for containing. + if _contains ''${target} ''${array[@]}; then + local current="''${PWD%/*}" + result="''${current%\/$target\/*}/''${target}" + else + # Make search case-insensitive. + shopt -s nocasematch - # Find dir name that contains input. - local found=1 - for (( idx=''${#array[@]}-1 ; idx>=0 ; idx-- )); do - dir="''${array[idx]}" - [[ "''${dir}" =~ "''${target}" ]] && found=0 - [[ ''${found} = 0 ]] && result="/''${dir}''${result}" - done + # Find dir name that contains input. + local found=1 + for (( idx=''${#array[@]}-1 ; idx>=0 ; idx-- )); do + dir="''${array[idx]}" + [[ "''${dir}" =~ "''${target}" ]] && found=0 + [[ ''${found} = 0 ]] && result="/''${dir}''${result}" + done - # Clean-up??? - shopt -u nocasematch - fi + # Clean-up??? + shopt -u nocasematch + fi - # Go there! - if [[ "''${result}" != "" ]]; then - echo "''${result}" - cd "''${result}" - else - return 1 - fi - } + # Go there! + if [[ "''${result}" != "" ]]; then + echo "''${result}" + cd "''${result}" + else + return 1 + fi + } - # CLI cd. Opens CLI file manager. - function ccd() { - local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" - yazi "$@" --cwd-file="$tmp" - if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then - cd -- "$cwd" - fi - rm -f -- "$tmp" - } + # CLI cd. Opens CLI file manager. + function ccd() { + local tmp="$(mktemp -t "yazi-cwd.XXXXXX")" + yazi "$@" --cwd-file="$tmp" + if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then + cd -- "$cwd" + fi + rm -f -- "$tmp" + } - # Get list of all parent dirs. - function _cdd_directories() { - local array - IFS='/' read -r -a array <<< "''${PWD}" - array=("''${array[@]:1}") - unset array[-1] - printf "%s\n" "''${array[@]}" - } + # Get list of all parent dirs. + function _cdd_directories() { + local array + IFS='/' read -r -a array <<< "''${PWD}" + array=("''${array[@]:1}") + unset array[-1] + printf "%s\n" "''${array[@]}" + } - function _comp_cdd() { - local IFS=$'\n' - local dirs=($(_cdd_directories)) - _autocomplete_first ''${dirs[@]} - } + function _comp_cdd() { + local IFS=$'\n' + local dirs=($(_cdd_directories)) + _autocomplete_first ''${dirs[@]} + } - complete -o nosort -o filenames -F _comp_cdd cdd - ''; + complete -o nosort -o filenames -F _comp_cdd cdd + ''; } diff --git a/home/program/bash/module/Color.nix b/home/program/bash/module/Color.nix index a2afdc2..48b4c2c 100644 --- a/home/program/bash/module/Color.nix +++ b/home/program/bash/module/Color.nix @@ -1,29 +1,28 @@ -{ ... }: -{ - text = '' - # Collection of available CLI colors. - # They may differ depending on the terminal used. - # Colors with 'b' prefix are bold colors. +{ ... }: { + text = '' + # Collection of available CLI colors. + # They may differ depending on the terminal used. + # Colors with 'b' prefix are bold colors. - export color_default="\033[0m" - export color_blue="\033[0;34m" - export color_bblue="\033[1;34m" - export color_cyan="\033[0;36m" - export color_bcyan="\033[1;36m" - export color_green="\033[0;32m" - export color_bgreen="\033[1;32m" - export color_purple="\033[0;35m" - export color_bpurple="\033[1;35m" - export color_red="\033[0;31m" - export color_bred="\033[1;31m" - export color_white="\033[0;37m" - export color_bwhite="\033[1;37m" - export color_yellow="\033[0;33m" - export color_byellow="\033[1;33m" + export color_default="\033[0m" + export color_blue="\033[0;34m" + export color_bblue="\033[1;34m" + export color_cyan="\033[0;36m" + export color_bcyan="\033[1;36m" + export color_green="\033[0;32m" + export color_bgreen="\033[1;32m" + export color_purple="\033[0;35m" + export color_bpurple="\033[1;35m" + export color_red="\033[0;31m" + export color_bred="\033[1;31m" + export color_white="\033[0;37m" + export color_bwhite="\033[1;37m" + export color_yellow="\033[0;33m" + export color_byellow="\033[1;33m" - # Print all available colors with their names colored in corresponding color. - function color_test() { - echo -e "''${color_default}color_default\n''${color_blue}color_blue\n''${color_bblue}color_bblue\n''${color_cyan}color_cyan\n''${color_bcyan}color_bcyan\n''${color_green}color_green\n''${color_bgreen}color_bgreen\n''${color_purple}color_purple\n''${color_bpurple}color_bpurple\n''${color_red}color_red\n''${color_bred}color_bred\n''${color_white}color_white\n''${color_bwhite}color_bwhite\n''${color_yellow}color_yellow\n''${color_byellow}color_byellow" - } - ''; + # Print all available colors with their names colored in corresponding color. + function color_test() { + echo -e "''${color_default}color_default\n''${color_blue}color_blue\n''${color_bblue}color_bblue\n''${color_cyan}color_cyan\n''${color_bcyan}color_bcyan\n''${color_green}color_green\n''${color_bgreen}color_bgreen\n''${color_purple}color_purple\n''${color_bpurple}color_bpurple\n''${color_red}color_red\n''${color_bred}color_bred\n''${color_white}color_white\n''${color_bwhite}color_bwhite\n''${color_yellow}color_yellow\n''${color_byellow}color_byellow" + } + ''; } diff --git a/home/program/bash/module/Copypaste.nix b/home/program/bash/module/Copypaste.nix index 051ef38..62400e6 100644 --- a/home/program/bash/module/Copypaste.nix +++ b/home/program/bash/module/Copypaste.nix @@ -1,14 +1,13 @@ -{ ... }: -{ - text = '' - # Copy stdin to system clipboard. *Example:* `echo hi \| copy`. - function copy() { - wl-copy - } +{ ... }: { + text = '' + # Copy stdin to system clipboard. *Example:* `echo hi \| copy`. + function copy() { + wl-copy + } - # Paste system clipboard to stdout. *Example:* `paste > file.txt`. - function paste() { - wl-paste - } - ''; + # Paste system clipboard to stdout. *Example:* `paste > file.txt`. + function paste() { + wl-paste + } + ''; } diff --git a/home/program/bash/module/Cp.nix b/home/program/bash/module/Cp.nix index 6b648f4..f047895 100644 --- a/home/program/bash/module/Cp.nix +++ b/home/program/bash/module/Cp.nix @@ -1,55 +1,54 @@ -{ ... }: -{ - text = '' - # Replaces default cp with rsync. - # Usage: rcp - function rcp() { - rsync -ahP --chmod=u+w "''${@}" - } +{ ... }: { + text = '' + # Replaces default cp with rsync. + # Usage: rcp + function rcp() { + rsync -ahP --chmod=u+w "''${@}" + } - # Replaces default cp with rsync. - # Only compare file size. - # Usage: rcp_fast - function rcp_fast() { - rsync -ahP --chmod=u+w --size-only "''${@}" - } + # Replaces default cp with rsync. + # Only compare file size. + # Usage: rcp_fast + function rcp_fast() { + rsync -ahP --chmod=u+w --size-only "''${@}" + } - # Replaces default cp with rsync. - # Compare file hashes. - # Usage: rcp_hash - function rcp_hash() { - rsync -ahP --chmod=u+w --checksum "''${@}" - } + # Replaces default cp with rsync. + # Compare file hashes. + # Usage: rcp_hash + function rcp_hash() { + rsync -ahP --chmod=u+w --checksum "''${@}" + } - # Copy and also merge all changes (delete dst files that do not exist in src). - # Usage: rcp_merge - function rcp_merge() { - rsync -ahP --chmod=u+w --delete "''${@}" - } + # Copy and also merge all changes (delete dst files that do not exist in src). + # Usage: rcp_merge + function rcp_merge() { + rsync -ahP --chmod=u+w --delete "''${@}" + } - # Copy and also merge all changes FAST (delete dst files that do not exist in src, only compare size). - # Usage: rcp_merge_fast - function rcp_merge_fast() { - rsync -ahP --chmod=u+w --delete --size-only "''${@}" - } + # Copy and also merge all changes FAST (delete dst files that do not exist in src, only compare size). + # Usage: rcp_merge_fast + function rcp_merge_fast() { + rsync -ahP --chmod=u+w --delete --size-only "''${@}" + } - # Copy and also merge all changes BY CHECKSUM (delete dst files that do not exist in src, compare hashes). - # Usage: rcp_merge_hash - function rcp_merge_hash() { - rsync -ahP --chmod=u+w --delete --checksum "''${@}" - } + # Copy and also merge all changes BY CHECKSUM (delete dst files that do not exist in src, compare hashes). + # Usage: rcp_merge_hash + function rcp_merge_hash() { + rsync -ahP --chmod=u+w --delete --checksum "''${@}" + } - # Print output of cp_merge without writing anything. - # Usage: rcp_test - function rcp_test() { - rsync -ahP --chmod=u+w --delete -n "''${@}" - } + # Print output of cp_merge without writing anything. + # Usage: rcp_test + function rcp_test() { + rsync -ahP --chmod=u+w --delete -n "''${@}" + } - # Copy by creating hardlinks. - # Works for directories, too. - # Usage: cp_link - function cp_link() { - /usr/bin/env cp -lr "''${@}" - } - ''; + # Copy by creating hardlinks. + # Works for directories, too. + # Usage: cp_link + function cp_link() { + /usr/bin/env cp -lr "''${@}" + } + ''; } diff --git a/home/program/bash/module/Curl.nix b/home/program/bash/module/Curl.nix index 4b5406a..9780297 100644 --- a/home/program/bash/module/Curl.nix +++ b/home/program/bash/module/Curl.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - # Download a file from the web. - # Usaee: dl [FILES...] - function dl() { - wcurl --curl-options='--http2 --continue-at -' -- ''${@} - } - ''; +{ ... }: { + text = '' + # Download a file from the web. + # Usaee: dl [FILES...] + function dl() { + wcurl --curl-options='--http2 --continue-at -' -- ''${@} + } + ''; } diff --git a/home/program/bash/module/Date.nix b/home/program/bash/module/Date.nix index 8fdd681..9c208ac 100644 --- a/home/program/bash/module/Date.nix +++ b/home/program/bash/module/Date.nix @@ -1,14 +1,13 @@ -{ ... }: -{ - text = '' - # Print today date in yyyyMMdd format. - function today() { - date +%Y%m%d - } +{ ... }: { + text = '' + # Print today date in yyyyMMdd format. + function today() { + date +%Y%m%d + } - # Current day of week number. - function dow() { - date +%u - } - ''; + # Current day of week number. + function dow() { + date +%u + } + ''; } diff --git a/home/program/bash/module/Disk.nix b/home/program/bash/module/Disk.nix index 2a7443b..ca395fd 100644 --- a/home/program/bash/module/Disk.nix +++ b/home/program/bash/module/Disk.nix @@ -1,73 +1,72 @@ -{ ... }: -{ - text = '' - # Show only physical drives info. - function pdf() { - df --si | sed -e '1p' -e '/^\/dev\//!d' - } +{ ... }: { + text = '' + # Show only physical drives info. + function pdf() { + df --si | sed -e '1p' -e '/^\/dev\//!d' + } - # Show total size in SI. - # Current dir by default. - # Usage: tdu [DIRS] - function tdu() { - du -sh --si "''${@}" - } + # Show total size in SI. + # Current dir by default. + # Usage: tdu [DIRS] + function tdu() { + du -sh --si "''${@}" + } - # Unlock encrypted disk file. - # Usage: funlock - function funlock() { - local file="''${1}" + # Unlock encrypted disk file. + # Usage: funlock + function funlock() { + local file="''${1}" - if [[ "''${file}" = "" ]]; then - help funlock - return 2 - fi + if [[ "''${file}" = "" ]]; then + help funlock + return 2 + fi - local name=$(parse_alnum "''${file##*/}") + local name=$(parse_alnum "''${file##*/}") - local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}") - loop="''${loop##* }"; loop="''${loop%.}" + local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}") + loop="''${loop##* }"; loop="''${loop%.}" - local decrypted=$(udisksctl unlock --block-device "''${loop}") - decrypted="''${decrypted##* }"; decrypted="''${decrypted%.}" + local decrypted=$(udisksctl unlock --block-device "''${loop}") + decrypted="''${decrypted##* }"; decrypted="''${decrypted%.}" - local mount=$(udisksctl mount --no-user-interaction --block-device "''${decrypted}") - mount="''${mount#* at }" + local mount=$(udisksctl mount --no-user-interaction --block-device "''${decrypted}") + mount="''${mount#* at }" - ya pub dds-cd --str "''${mount}" 2> /dev/null - cd "''${mount}" - } + ya pub dds-cd --str "''${mount}" 2> /dev/null + cd "''${mount}" + } - # Mount file. - # Usage: fmount - function fmount() { - local file="''${1}" - if [[ "''${file}" = "" ]]; then - help fmount - return 2 - fi + # Mount file. + # Usage: fmount + function fmount() { + local file="''${1}" + if [[ "''${file}" = "" ]]; then + help fmount + return 2 + fi - local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}") - loop="''${loop##* }"; loop="''${loop%.}" + local loop=$(udisksctl loop-setup --no-user-interaction --file "''${file}") + loop="''${loop##* }"; loop="''${loop%.}" - local mount=$(udisksctl mount --no-user-interaction --block-device "''${loop}") - mount="''${mount#* at }" + local mount=$(udisksctl mount --no-user-interaction --block-device "''${loop}") + mount="''${mount#* at }" - ya pub dds-cd --str "''${mount}" 2> /dev/null - cd "''${mount}" - } + ya pub dds-cd --str "''${mount}" 2> /dev/null + cd "''${mount}" + } - # Unmount file. - # Usage: fumount - function fumount() { - local loop="''${1}" - if [[ "''${loop}" = "" ]]; then - help fumount - return 2 - fi + # Unmount file. + # Usage: fumount + function fumount() { + local loop="''${1}" + if [[ "''${loop}" = "" ]]; then + help fumount + return 2 + fi - udisksctl unmount --no-user-interaction --block-device "''${loop}" - udisksctl loop-delete --no-user-interaction --block-device "''${loop}" - } - ''; + udisksctl unmount --no-user-interaction --block-device "''${loop}" + udisksctl loop-delete --no-user-interaction --block-device "''${loop}" + } + ''; } diff --git a/home/program/bash/module/Docker.nix b/home/program/bash/module/Docker.nix index 0c3660e..2febc60 100644 --- a/home/program/bash/module/Docker.nix +++ b/home/program/bash/module/Docker.nix @@ -1,100 +1,99 @@ -{ ... }: -{ - text = '' - # Show container's volumes. - # Usage: docker_volumes - function docker_volumes() { - docker inspect -f '{{ .Mounts }}' "''${@}" - } +{ ... }: { + text = '' + # Show container's volumes. + # Usage: docker_volumes + function docker_volumes() { + docker inspect -f '{{ .Mounts }}' "''${@}" + } - # Check if any container exited. - function docker_health() { - docker ps -a | grep Exited - } + # Check if any container exited. + function docker_health() { + docker ps -a | grep Exited + } - # Find out container's IP address. - # Usage: docker_ip - function docker_ip() { - docker inspect -f '\'''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' "''${1}" | sed "s/^.//" | sed "s/.$//" - } + # Find out container's IP address. + # Usage: docker_ip + function docker_ip() { + docker inspect -f '\'''{{range .NetworkSettings.Networks}}{{.IPAddress}}{{end}}'\' "''${1}" | sed "s/^.//" | sed "s/.$//" + } - # Update all docker images. - function docker_update() { - docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull - } + # Update all docker images. + function docker_update() { + docker images --format "{{.Repository}}:{{.Tag}}" | xargs -L1 docker pull + } - # Docker compose shortcut. - function dc() { - docker compose "''${@}" - } + # Docker compose shortcut. + function dc() { + docker compose "''${@}" + } - # Docker compose up. - # Usage: dcu [SERVICES] - function dcu() { - docker compose up -d "''${@}" - } + # Docker compose up. + # Usage: dcu [SERVICES] + function dcu() { + docker compose up -d "''${@}" + } - # Docker compose down. - # Usage: dcd [SERVICES] - function dcd() { - docker compose down "''${@}" - } + # Docker compose down. + # Usage: dcd [SERVICES] + function dcd() { + docker compose down "''${@}" + } - # Docker compose pull. - # Usage: dcp [SERVICES] - function dcp() { - docker compose pull "''${@}" - } + # Docker compose pull. + # Usage: dcp [SERVICES] + function dcp() { + docker compose pull "''${@}" + } - # Docker compose logs. - # Usage: dcl [SERVICES] - function dcl() { - docker compose logs -f "''${@}" - } + # Docker compose logs. + # Usage: dcl [SERVICES] + function dcl() { + docker compose logs -f "''${@}" + } - # Docker compose restart. - # Usage: dcr [SERVICES] - function dcr() { - docker compose restart "''${@}" - } + # Docker compose restart. + # Usage: dcr [SERVICES] + function dcr() { + docker compose restart "''${@}" + } - # Docker compose stop. - # Usage: dcs [SERVICES] - function dcs() { - docker compose stop "''${@}" - } + # Docker compose stop. + # Usage: dcs [SERVICES] + function dcs() { + docker compose stop "''${@}" + } - # Docker compose down & up specified services. - # Usage: dcdu [SERVICES] - function dcdu() { - dcd "''${@}" - dcu "''${@}" - } + # Docker compose down & up specified services. + # Usage: dcdu [SERVICES] + function dcdu() { + dcd "''${@}" + dcu "''${@}" + } - # Docker compose pull & up specified services. - # Usage: dcpu [SERVICES] - function dcpu() { - dcp "''${@}" - dcu "''${@}" - } + # Docker compose pull & up specified services. + # Usage: dcpu [SERVICES] + function dcpu() { + dcp "''${@}" + dcu "''${@}" + } - # Docker compose up & attach to logs for specified services. - # Usage: dcul [SERVICES] - function dcul() { - dcu "''${@}" && dcl "''${@}" - } + # Docker compose up & attach to logs for specified services. + # Usage: dcul [SERVICES] + function dcul() { + dcu "''${@}" && dcl "''${@}" + } - # Autocomplete with available services. - function _dc_services() { - _autocomplete "$(docker compose config --services 2> /dev/null)" - } + # Autocomplete with available services. + function _dc_services() { + _autocomplete "$(docker compose config --services 2> /dev/null)" + } - # Autocomplete with available container names. - function _dc_containers() { - _autocomplete "$(docker ps --format "\""{{.Names}}"\"")" - } + # Autocomplete with available container names. + function _dc_containers() { + _autocomplete "$(docker ps --format "\""{{.Names}}"\"")" + } - complete -F _dc_services dcu dcd dcp dcl dcul dcdu dcr dcs dcpu - complete -F _dc_containers docker_volumes docker_ip - ''; + complete -F _dc_services dcu dcd dcp dcl dcul dcdu dcr dcs dcpu + complete -F _dc_containers docker_volumes docker_ip + ''; } diff --git a/home/program/bash/module/Dvd.nix b/home/program/bash/module/Dvd.nix index 126e449..3d44cda 100644 --- a/home/program/bash/module/Dvd.nix +++ b/home/program/bash/module/Dvd.nix @@ -1,44 +1,43 @@ -{ ... }: -{ - text = '' - # Burn specified iso file to DVD. - # Usage: dvd_burn_iso - function dvd_burn_iso() { - local iso="''${1}" - if [[ "''${iso}" = "" ]]; then - help dvd_burn_iso - return 2 - fi +{ ... }: { + text = '' + # Burn specified iso file to DVD. + # Usage: dvd_burn_iso + function dvd_burn_iso() { + local iso="''${1}" + if [[ "''${iso}" = "" ]]; then + help dvd_burn_iso + return 2 + fi - growisofs -dvd-compat -speed=8 -use-the-force-luke=tty -Z /dev/sr0="''${iso}" - } + growisofs -dvd-compat -speed=8 -use-the-force-luke=tty -Z /dev/sr0="''${iso}" + } - # Burn specified iso file to CD. - # Usage: cd_burn_iso - function cd_burn_iso() { - local iso="''${1}" - if [[ "''${iso}" = "" ]]; then - help cd_burn_iso - return 2 - fi + # Burn specified iso file to CD. + # Usage: cd_burn_iso + function cd_burn_iso() { + local iso="''${1}" + if [[ "''${iso}" = "" ]]; then + help cd_burn_iso + return 2 + fi - wodim speed=8 -tao dev=/dev/sr0 "''${iso}" - } + wodim speed=8 -tao dev=/dev/sr0 "''${iso}" + } - # Burn specified audio files to CD. - # Usage: cd_burn_audio - function cd_burn_audio() { - if [[ "''${*}" = "" ]]; then - help cd_burn_audio - return 2 - fi + # Burn specified audio files to CD. + # Usage: cd_burn_audio + function cd_burn_audio() { + if [[ "''${*}" = "" ]]; then + help cd_burn_audio + return 2 + fi - cdrecord -v dev=/dev/sr0 speed=8 -audio -pad "''${*}" - } + cdrecord -v dev=/dev/sr0 speed=8 -audio -pad "''${*}" + } - # Spawn Nix shell with required tools. - function dvd_shell() { - SHELL_NAME="dvd" tmpshell dvdplusrwtools cdrkit - } - ''; + # Spawn Nix shell with required tools. + function dvd_shell() { + SHELL_NAME="dvd" tmpshell dvdplusrwtools cdrkit + } + ''; } diff --git a/home/program/bash/module/Ffmpeg.nix b/home/program/bash/module/Ffmpeg.nix index 5b54909..1f1ab7a 100644 --- a/home/program/bash/module/Ffmpeg.nix +++ b/home/program/bash/module/Ffmpeg.nix @@ -1,113 +1,112 @@ -{ ... }: -{ - text = '' - # Mux audio into containers. File names in sound and current dirrectories must match. - # Usage: ffmpeg_mux_audio - function ffmpeg_mux_audio() { - if [[ "''${1}" = "" ]]; then - help ffmpeg_mux_audio - return 2 - fi +{ ... }: { + text = '' + # Mux audio into containers. File names in sound and current dirrectories must match. + # Usage: ffmpeg_mux_audio + function ffmpeg_mux_audio() { + if [[ "''${1}" = "" ]]; then + help ffmpeg_mux_audio + return 2 + fi - for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done - } + for file in *; do ffmpeg -i "$file" -i "$1"/"$file" -c copy -map 0:v:0 -map 1:a:0 -shortest "$2"/"$file"; done + } - # Mux cover into music file. - # Usage: ffmpeg_mux_cover - function ffmpeg_mux_cover() { - if [[ "''${1}" = "" ]]; then - help ffmpeg_mux_cover - return 2 - fi + # Mux cover into music file. + # Usage: ffmpeg_mux_cover + function ffmpeg_mux_cover() { + if [[ "''${1}" = "" ]]; then + help ffmpeg_mux_cover + return 2 + fi - local format="''${1}" - local cover="''${2}" + local format="''${1}" + local cover="''${2}" - mkdir out + mkdir out - case "''${format}" in - # "mka"|"mkv") - # for file in *.''${format}; do - # ffmpeg -i "''${file}" -attach "''${cover}" -map 0 -c copy -metadata:s:t mimetype="image/''${cover##*.}" -metadata:s:t:0 filename="cover.''${cover##*.}" "./out/''${file}" || return 1 - # done - # ;; - *) - for file in *.''${format}; do - # ffmpeg -i "''${file}" -i "''${cover}" -map 0 -map 0:-v? -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"''${file}" || return 1 - ffmpeg -i "''${file}" -i "''${cover}" -map 0 -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"''${file}" || return 1 - done - ;; - esac + case "''${format}" in + # "mka"|"mkv") + # for file in *.''${format}; do + # ffmpeg -i "''${file}" -attach "''${cover}" -map 0 -c copy -metadata:s:t mimetype="image/''${cover##*.}" -metadata:s:t:0 filename="cover.''${cover##*.}" "./out/''${file}" || return 1 + # done + # ;; + *) + for file in *.''${format}; do + # ffmpeg -i "''${file}" -i "''${cover}" -map 0 -map 0:-v? -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"''${file}" || return 1 + ffmpeg -i "''${file}" -i "''${cover}" -map 0 -map 1 -codec copy -metadata:s:v title="Album cover" -metadata:s:v comment="Cover (front)" -disposition:v attached_pic ./out/"''${file}" || return 1 + done + ;; + esac - mv out/* . - rm -d out/ && rm "''${2}" - } + mv out/* . + rm -d out/ && rm "''${2}" + } - # Generate music metadata from directory structure. - # Top dir is the Artist name like this: `The_Beatles`. - # Next are albums like this: `2010_My_love`. - # Inside are songs like this: `01_sample.flac`. - # Usage: ffmpeg_music_meta - function ffmpeg_music_meta() { - if [[ "''${1}" = "" ]]; then - help ffmpeg_music_meta - return 2 - fi + # Generate music metadata from directory structure. + # Top dir is the Artist name like this: `The_Beatles`. + # Next are albums like this: `2010_My_love`. + # Inside are songs like this: `01_sample.flac`. + # Usage: ffmpeg_music_meta + function ffmpeg_music_meta() { + if [[ "''${1}" = "" ]]; then + help ffmpeg_music_meta + return 2 + fi - local format="''${1}" + local format="''${1}" - ls *.''${format} &> /dev/null || return 1 + ls *.''${format} &> /dev/null || return 1 - local artist="''${PWD%/*}"; artist="''${artist##*/}"; artist="''${artist//_/ }" - local album="''${PWD##*/}"; album="''${album#*_}"; album="''${album//_/ }" - local year="''${PWD##*/}"; year="''${year%%_*}" - # local total=$(ls *.''${format} | wc -l) + local artist="''${PWD%/*}"; artist="''${artist##*/}"; artist="''${artist//_/ }" + local album="''${PWD##*/}"; album="''${album#*_}"; album="''${album//_/ }" + local year="''${PWD##*/}"; year="''${year%%_*}" + # local total=$(ls *.''${format} | wc -l) - mkdir out + mkdir out - for file in *.''${format}; do - local track="''${file%%_*}"; track=$((10#''${track})); [[ "''${track}" = "" ]] && track=0 - local title="''${file#*_}"; title="''${title%.*}"; title="''${title//_/ }" + for file in *.''${format}; do + local track="''${file%%_*}"; track=$((10#''${track})); [[ "''${track}" = "" ]] && track=0 + local title="''${file#*_}"; title="''${title%.*}"; title="''${title//_/ }" - # echo "''${artist}; ''${album}; ''${year}; ''${track}; ''${title}" - # TODO: make it format-specific. - ffmpeg -i "''${file}" -map 0 -c copy -metadata "artists=" -metadata "artist=''${artist}" -metadata "album_artist=''${artist}" -metadata "album=''${album}" -metadata "date=''${year}" -metadata "year=''${year}" -metadata "date_released=''${year}" -metadata "track=''${track}" -metadata "part_number=''${track}" -metadata "title=''${title}" ./out/"''${file}" || return 1 - done + # echo "''${artist}; ''${album}; ''${year}; ''${track}; ''${title}" + # TODO: make it format-specific. + ffmpeg -i "''${file}" -map 0 -c copy -metadata "artists=" -metadata "artist=''${artist}" -metadata "album_artist=''${artist}" -metadata "album=''${album}" -metadata "date=''${year}" -metadata "year=''${year}" -metadata "date_released=''${year}" -metadata "track=''${track}" -metadata "part_number=''${track}" -metadata "title=''${title}" ./out/"''${file}" || return 1 + done - mv out/* . - rm -d out/ - } + mv out/* . + rm -d out/ + } - # Rotate the video clock-wise. - # Usage: ffmpeg_rotate - function ffmpeg_rotate() { - if [[ "''${2}" = "" ]]; then - help ffmpeg_rotate - fi + # Rotate the video clock-wise. + # Usage: ffmpeg_rotate + function ffmpeg_rotate() { + if [[ "''${2}" = "" ]]; then + help ffmpeg_rotate + fi - local angle="''${1}" - local target="''${2}" + local angle="''${1}" + local target="''${2}" - ffmpeg -display_rotation ''${angle} -i ''${target} -c copy _''${target} && mv _''${target} ''${target} || rm _''${target} - } + ffmpeg -display_rotation ''${angle} -i ''${target} -c copy _''${target} && mv _''${target} ''${target} || rm _''${target} + } - # Get video FPS. - function _ffprobe_fps() { - local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "''${1}") - [[ "''${fps}" = "" ]] && fps=30 || fps=$((fps)) - echo "''${fps}" - } + # Get video FPS. + function _ffprobe_fps() { + local fps=$(ffprobe -v 0 -of csv=p=0 -select_streams v:0 -show_entries stream=r_frame_rate "''${1}") + [[ "''${fps}" = "" ]] && fps=30 || fps=$((fps)) + echo "''${fps}" + } - # Get recommended keyframe interval for a file. - function _ffprobe_keyint() { - local fps=$(_ffprobe_fps "''${1}") - echo $((fps*5)) - } + # Get recommended keyframe interval for a file. + function _ffprobe_keyint() { + local fps=$(_ffprobe_fps "''${1}") + echo $((fps*5)) + } - # Get audio bitrage. 128 by default. - function _ffprobe_ba() { - local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "''${1}") - [[ "''${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 - } - ''; + # Get audio bitrage. 128 by default. + function _ffprobe_ba() { + local ba=$(ffprobe -v error -select_streams a:0 -show_entries stream=bit_rate -of default=noprint_wrappers=1:nokey=1 "''${1}") + [[ "''${ba}" != "N/A" ]] && echo $((ba/1024)) || echo 128 + } + ''; } diff --git a/home/program/bash/module/File.nix b/home/program/bash/module/File.nix index 82023d4..a0adc8c 100644 --- a/home/program/bash/module/File.nix +++ b/home/program/bash/module/File.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - # Open file/dir in GUI. - # Usage: o - function o() { - xdg-open "''${@}" - } - ''; +{ ... }: { + text = '' + # Open file/dir in GUI. + # Usage: o + function o() { + xdg-open "''${@}" + } + ''; } diff --git a/home/program/bash/module/Find.nix b/home/program/bash/module/Find.nix index 9224ae1..ef94b59 100644 --- a/home/program/bash/module/Find.nix +++ b/home/program/bash/module/Find.nix @@ -1,10 +1,9 @@ -{ ... }: -{ - text = '' - # Find all file extensions. - function find_ext() { - local types=($(find -type f | sed -e "s/.*\///" -e "s/^\.//" -e "/\./!d" -e "s/.*\.//")) - echo "''${types[@]}" | tr ' ' '\n' | sort -u - } - ''; +{ ... }: { + text = '' + # Find all file extensions. + function find_ext() { + local types=($(find -type f | sed -e "s/.*\///" -e "s/^\.//" -e "/\./!d" -e "s/.*\.//")) + echo "''${types[@]}" | tr ' ' '\n' | sort -u + } + ''; } diff --git a/home/program/bash/module/Fix.nix b/home/program/bash/module/Fix.nix index b2ded6b..84e81f0 100644 --- a/home/program/bash/module/Fix.nix +++ b/home/program/bash/module/Fix.nix @@ -1,25 +1,24 @@ -{ ... }: -{ - text = '' - # Fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. - # SPEED is one of 10/100/1000 etc. - # Usage: fix_ethernet_speed - function fix_ethernet_speed() { - local device="''${1}" - local speed="''${2}" +{ ... }: { + text = '' + # Fix when ethernet mistakenly detects 100 Mb instead of 1000 Mb. + # SPEED is one of 10/100/1000 etc. + # Usage: fix_ethernet_speed + function fix_ethernet_speed() { + local device="''${1}" + local speed="''${2}" - if [[ "''${device}" = "" || "''${speed}" = "" ]]; then - help fix_ethernet_speed - return 2 - fi + if [[ "''${device}" = "" || "''${speed}" = "" ]]; then + help fix_ethernet_speed + return 2 + fi - ethtool -s "''${device}" speed "''${speed}" - } + ethtool -s "''${device}" speed "''${speed}" + } - # Delete lost Gradle lock files. - function fix_gradle_lock() { - cd "''${HOME}/.gradle" && find -type f | grep \\.lock$ | xargs -- rm - cd - - } - ''; + # Delete lost Gradle lock files. + function fix_gradle_lock() { + cd "''${HOME}/.gradle" && find -type f | grep \\.lock$ | xargs -- rm + cd - + } + ''; } diff --git a/home/program/bash/module/Git.nix b/home/program/bash/module/Git.nix index ec78b9c..3f8d77d 100644 --- a/home/program/bash/module/Git.nix +++ b/home/program/bash/module/Git.nix @@ -1,319 +1,318 @@ -{ ... }: -{ - text = '' - # Git push. - function gps() { - git push "''${@}" - } +{ ... }: { + text = '' + # Git push. + function gps() { + git push "''${@}" + } - # Git push all (branches). Useful for pushing all stuff to a new remote. - function gpsa() { - local remotes=($(git remote)) - for remote in ''${remotes[@]}; do - echo -n "''${remote}: " - git push "''${remote}" --tags "refs/remotes/origin/*:refs/heads/*" - done - } + # Git push all (branches). Useful for pushing all stuff to a new remote. + function gpsa() { + local remotes=($(git remote)) + for remote in ''${remotes[@]}; do + echo -n "''${remote}: " + git push "''${remote}" --tags "refs/remotes/origin/*:refs/heads/*" + done + } - # Git force push. - function gpsf() { - git push --force "''${@}" - } + # Git force push. + function gpsf() { + git push --force "''${@}" + } - # Git pull. - function gpl() { - git pull "''${@}" - } + # Git pull. + function gpl() { + git pull "''${@}" + } - # Git log. - function gl() { - git log --show-signature "''${@}" - } + # Git log. + function gl() { + git log --show-signature "''${@}" + } - # Git status. - function gs() { - git status "''${@}" - } + # Git status. + function gs() { + git status "''${@}" + } - # Git stash. - function gst() { - git stash "''${@}" - } + # Git stash. + function gst() { + git stash "''${@}" + } - # Cd to git's root dir. - function gcd() { - local path=$(git rev-parse --show-toplevel) - [[ "''${path}" = "" ]] && return 1 - cd "''${path}" - } + # Cd to git's root dir. + function gcd() { + local path=$(git rev-parse --show-toplevel) + [[ "''${path}" = "" ]] && return 1 + cd "''${path}" + } - # Git diff. - function gd() { - git diff "''${@}" - } + # Git diff. + function gd() { + git diff "''${@}" + } - # Git diff added. - function gda() { - git diff --cached "''${@}" - } + # Git diff added. + function gda() { + git diff --cached "''${@}" + } - # Git commit. - function gc() { - git commit -m "''${@}" - } + # Git commit. + function gc() { + git commit -m "''${@}" + } - # Git clone (lazy!). - function gcl() { - git clone --filter tree:0 "''${@}" - } + # Git clone (lazy!). + function gcl() { + git clone --filter tree:0 "''${@}" + } - # Git signed commit. - function gcs() { - git commit -S -m "''${@}" - } + # Git signed commit. + function gcs() { + git commit -S -m "''${@}" + } - # Git checkout. - function gch() { - git checkout "''${@}" - } + # Git checkout. + function gch() { + git checkout "''${@}" + } - # Git checkout branch. - # Usage: gchb - function gchb() { - git checkout -b "''${@}" - } + # Git checkout branch. + # Usage: gchb + function gchb() { + git checkout -b "''${@}" + } - # Git branch. - function gb() { - git branch --all "''${@}" - } + # Git branch. + function gb() { + git branch --all "''${@}" + } - # Git branch delete. - # Usage: gbd - function gbd() { - git branch -D "''${@}" - } + # Git branch delete. + # Usage: gbd + function gbd() { + git branch -D "''${@}" + } - # Git branch delete all except current. - function gbda() { - git branch | grep -v ^* | xargs git branch -D - } + # Git branch delete all except current. + function gbda() { + git branch | grep -v ^* | xargs git branch -D + } - # Git fetch all. - function gf() { - git fetch --all -v -p - } + # Git fetch all. + function gf() { + git fetch --all -v -p + } - # Git tag. - function gt() { - git tag "''${@}" - } + # Git tag. + function gt() { + git tag "''${@}" + } - # Git ignore files. - function gi() { - git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached - } + # Git ignore files. + function gi() { + git ls-files -ci --exclude-standard -z | xargs -0 git rm --cached + } - # Git patch create. - # Usage: gpc > - function gpc() { - git diff --staged --patch --binary - } + # Git patch create. + # Usage: gpc > + function gpc() { + git diff --staged --patch --binary + } - # Git patch (apply). - # Usage: gp - function gp() { - git apply --index "''${@}" - } + # Git patch (apply). + # Usage: gp + function gp() { + git apply --index "''${@}" + } - # Unstage changes. - # Usage: grs - function grs() { - git restore --staged "''${@}" - } + # Unstage changes. + # Usage: grs + function grs() { + git restore --staged "''${@}" + } - # Run git garbage collection. - function ggc() { - git gc --aggressive --no-cruft --prune=now - } + # Run git garbage collection. + function ggc() { + git gc --aggressive --no-cruft --prune=now + } - # Check git file integrity. - function gfsck() { - git fsck - } + # Check git file integrity. + function gfsck() { + git fsck + } - # Preview diff while adding. Adds current dir by default. - # Usage: ga [FILES] - function ga() { - local target=''${@} + # Preview diff while adding. Adds current dir by default. + # Usage: ga [FILES] + function ga() { + local target=''${@} - if [[ "''${target}" = "" ]]; then - target="." - fi + if [[ "''${target}" = "" ]]; then + target="." + fi - git diff ''${target} - git add ''${target} - } + git diff ''${target} + git add ''${target} + } - # Rebase by X commits or from root. When COUNT is 0 - rebase from root. Default is 2. - # Usage: gr [COMMIT COUNT] - function gr() { - local base="''${1}" + # Rebase by X commits or from root. When COUNT is 0 - rebase from root. Default is 2. + # Usage: gr [COMMIT COUNT] + function gr() { + local base="''${1}" - # Rebase last 2 commits by default. - if [[ "''${base}" = "" ]]; then - base="2" - fi + # Rebase last 2 commits by default. + if [[ "''${base}" = "" ]]; then + base="2" + fi - # If 0, rebase from root. else from specified base. - if [[ "''${base}" = "0" ]]; then - git rebase -i --root - else - git rebase -i HEAD~''${base} - fi - } + # If 0, rebase from root. else from specified base. + if [[ "''${base}" = "0" ]]; then + git rebase -i --root + else + git rebase -i HEAD~''${base} + fi + } - # Specify git user as Dmitry Voronin with provided email. - # Usage: gu [EMAIL] - function gu() { - local name="Dmitry Voronin" - local email="''${1}" + # Specify git user as Dmitry Voronin with provided email. + # Usage: gu [EMAIL] + function gu() { + local name="Dmitry Voronin" + local email="''${1}" - if [[ "''${name}" = "" || "''${email}" = "" ]]; then - echo "usage: gu [EMAIL]" - return 2 - fi + if [[ "''${name}" = "" || "''${email}" = "" ]]; then + echo "usage: gu [EMAIL]" + return 2 + fi - git config user.name "''${name}" - git config user.email "''${email}" - } + git config user.name "''${name}" + git config user.email "''${email}" + } - # Get my git repo. - # Usage: gg - function gg() { - local repo="''${1}" + # Get my git repo. + # Usage: gg + function gg() { + local repo="''${1}" - if [[ "''${repo}" = "" ]]; then - help gg - return 2 - fi + if [[ "''${repo}" = "" ]]; then + help gg + return 2 + fi - git clone ssh://git@git.voronind.com:22144/voronind/"''${repo}" - } + git clone ssh://git@git.voronind.com:22144/voronind/"''${repo}" + } - # See diff for a specific commit. Last commit by default. - # Usage: gdc [COMMITHASH] - function gdc() { - local hash="''${1}" - [[ "''${hash}" = "" ]] && hash="HEAD" - git diff "''${hash}^!" - } + # See diff for a specific commit. Last commit by default. + # Usage: gdc [COMMITHASH] + function gdc() { + local hash="''${1}" + [[ "''${hash}" = "" ]] && hash="HEAD" + git diff "''${hash}^!" + } - # Get version number based on commit count. - function gv() { - git rev-list HEAD --count - } + # Get version number based on commit count. + function gv() { + git rev-list HEAD --count + } - # Open the remote web url in default browser. - # Usage: gw [REMOTE] - function gw() { - local remote="''${1}" - [[ "''${remote}" = "" ]] && remote="$(git remote | head -n1)" + # Open the remote web url in default browser. + # Usage: gw [REMOTE] + function gw() { + local remote="''${1}" + [[ "''${remote}" = "" ]] && remote="$(git remote | head -n1)" - local url="$(git remote get-url ''${remote})" - open "''${url}" - } + local url="$(git remote get-url ''${remote})" + open "''${url}" + } - # Search for string in whole git history. - # Usage: gsearch - function gsearch() { - local target="''${*}" + # Search for string in whole git history. + # Usage: gsearch + function gsearch() { + local target="''${*}" - if [[ "''${target}" = "" ]]; then - help gsearch - return 2 - fi + if [[ "''${target}" = "" ]]; then + help gsearch + return 2 + fi - git log -p -G "''${target}" - } + git log -p -G "''${target}" + } - # Sign the old commits. 0 to resign from root. - # Usage: gsign [COMMIT_COUNT] - function gsign() { - local base="''${1}" + # Sign the old commits. 0 to resign from root. + # Usage: gsign [COMMIT_COUNT] + function gsign() { + local base="''${1}" - # Resign last commit by default. - if [[ "''${base}" = "" ]]; then - base="1" - fi + # Resign last commit by default. + if [[ "''${base}" = "" ]]; then + base="1" + fi - # If 0, rebase from root. else from specified base. - if [[ "''${base}" = "0" ]]; then - git rebase --exec 'git commit --amend --no-edit -n -S' -i --root - else - git rebase --exec 'git commit --amend --no-edit -n -S' -i HEAD~''${base} - fi - } + # If 0, rebase from root. else from specified base. + if [[ "''${base}" = "0" ]]; then + git rebase --exec 'git commit --amend --no-edit -n -S' -i --root + else + git rebase --exec 'git commit --amend --no-edit -n -S' -i HEAD~''${base} + fi + } - # Show current branch. - function _git_current_branch() { - git branch --show-current 2> /dev/null - } + # Show current branch. + function _git_current_branch() { + git branch --show-current 2> /dev/null + } - # Show origin's url. - function _git_origin_url() { - git remote get-url origin - } + # Show origin's url. + function _git_origin_url() { + git remote get-url origin + } - # Get this dotfiles url. - function _git_dotfiles_url() { - echo 'https://git.voronind.com/voronind/linux.git' - } + # Get this dotfiles url. + function _git_dotfiles_url() { + echo 'https://git.voronind.com/voronind/linux.git' + } - # Check if current git repo is this dotfiles. - function _git_is_dotfiles() { - # [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]] - local dir="''${PWD}" + # Check if current git repo is this dotfiles. + function _git_is_dotfiles() { + # [[ "$(_git_origin_url)" = "$(_git_dotfiles_url)" ]] + local dir="''${PWD}" - while [[ "''${dir}" != "" ]]; do - if [[ -d "''${dir}/.git" ]]; then - if [[ "''${dir}" = "''${HOME}" ]] || [[ "''${dir}" = "$(realpath ''${HOME})" ]]; then - return 0 - else - return 1 - fi - fi + while [[ "''${dir}" != "" ]]; do + if [[ -d "''${dir}/.git" ]]; then + if [[ "''${dir}" = "''${HOME}" ]] || [[ "''${dir}" = "$(realpath ''${HOME})" ]]; then + return 0 + else + return 1 + fi + fi - dir="''${dir%/*}" - done - } + dir="''${dir%/*}" + done + } - # Autocomplete. - _completion_loader git &> /dev/null - __git_complete gps _git_push &> /dev/null - __git_complete gpsf _git_push &> /dev/null - __git_complete gpl _git_pull &> /dev/null - __git_complete gl _git_log &> /dev/null - __git_complete gs _git_status &> /dev/null - __git_complete gst _git_stash &> /dev/null - __git_complete gd _git_diff &> /dev/null - __git_complete gdc _git_diff &> /dev/null - __git_complete gc _git_commit &> /dev/null - __git_complete gch _git_checkout &> /dev/null - __git_complete gchb _git_checkout &> /dev/null - __git_complete gb _git_branch &> /dev/null - __git_complete gbd _git_branch &> /dev/null - __git_complete gf _git_fetch &> /dev/null - __git_complete gt _git_tag &> /dev/null - __git_complete gp _git_apply &> /dev/null - __git_complete ga _git_add &> /dev/null - __git_complete gw _git_pull &> /dev/null + # Autocomplete. + _completion_loader git &> /dev/null + __git_complete gps _git_push &> /dev/null + __git_complete gpsf _git_push &> /dev/null + __git_complete gpl _git_pull &> /dev/null + __git_complete gl _git_log &> /dev/null + __git_complete gs _git_status &> /dev/null + __git_complete gst _git_stash &> /dev/null + __git_complete gd _git_diff &> /dev/null + __git_complete gdc _git_diff &> /dev/null + __git_complete gc _git_commit &> /dev/null + __git_complete gch _git_checkout &> /dev/null + __git_complete gchb _git_checkout &> /dev/null + __git_complete gb _git_branch &> /dev/null + __git_complete gbd _git_branch &> /dev/null + __git_complete gf _git_fetch &> /dev/null + __git_complete gt _git_tag &> /dev/null + __git_complete gp _git_apply &> /dev/null + __git_complete ga _git_add &> /dev/null + __git_complete gw _git_pull &> /dev/null - # Autocomplete with my git emails. - function _gu() { - _autocomplete_first hi@voronind.com dd.voronin@fsight.ru - } + # Autocomplete with my git emails. + function _gu() { + _autocomplete_first hi@voronind.com dd.voronin@fsight.ru + } - complete -F _gu gu - ''; + complete -F _gu gu + ''; } diff --git a/home/program/bash/module/Gpg.nix b/home/program/bash/module/Gpg.nix index 36366ed..4c5ea4b 100644 --- a/home/program/bash/module/Gpg.nix +++ b/home/program/bash/module/Gpg.nix @@ -1,96 +1,95 @@ -{ ... }: -{ - text = '' - # Check smartcard pin. - function scunlock() { - pkill keyboxd &> /dev/null - # pkill gpg-agent &> /dev/null - echo verify | gpg --card-edit --no-tty --command-fd=0 - } +{ ... }: { + text = '' + # Check smartcard pin. + function scunlock() { + pkill keyboxd &> /dev/null + # pkill gpg-agent &> /dev/null + echo verify | gpg --card-edit --no-tty --command-fd=0 + } - # Encrypt files to myself. - # Usage: encrypt - function encrypt() { - local IFS=$'\n' - local targets=(''${@}) + # Encrypt files to myself. + # Usage: encrypt + function encrypt() { + local IFS=$'\n' + local targets=(''${@}) - if [[ "''${targets}" = "" ]]; then - help encrypt - return 2 - fi + if [[ "''${targets}" = "" ]]; then + help encrypt + return 2 + fi - process() { - gpg --encrypt --armor --recipient hi@voronind.com --output "''${target}.gpg" "''${target}" - } + process() { + gpg --encrypt --armor --recipient hi@voronind.com --output "''${target}.gpg" "''${target}" + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Decrypt files to myself. - # Usage: decrypt [FILES] - function decrypt() { - local IFS=$'\n' - local targets=(''${@}) + # Decrypt files to myself. + # Usage: decrypt [FILES] + function decrypt() { + local IFS=$'\n' + local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=(*.gpg) + [[ "''${targets}" = "" ]] && targets=(*.gpg) - process() { - gpg --decrypt --output "''${target%.gpg}" "''${target}" - } + process() { + gpg --decrypt --output "''${target%.gpg}" "''${target}" + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Sign a file. - # Usage: sign - function sign() { - local IFS=$'\n' - local targets=(''${@}) + # Sign a file. + # Usage: sign + function sign() { + local IFS=$'\n' + local targets=(''${@}) - if [[ "''${targets}" = "" ]]; then - help sign - return 2 - fi + if [[ "''${targets}" = "" ]]; then + help sign + return 2 + fi - process() { - gpg --detach-sig --armor --output "''${target}.sig" "''${target}" - } + process() { + gpg --detach-sig --armor --output "''${target}.sig" "''${target}" + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Verify a signature. All .sig files by default. - # Usage: verify [FILES] - function verify() { - local IFS=$'\n' - local targets=(''${@}) + # Verify a signature. All .sig files by default. + # Usage: verify [FILES] + function verify() { + local IFS=$'\n' + local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=(*.sig) + [[ "''${targets}" = "" ]] && targets=(*.sig) - process() { - gpg --verify "''${target}" - } + process() { + gpg --verify "''${target}" + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Find user keys using keyservers. - # Usage: gpg_find - function gpg_find() { - local email="''${1}" + # Find user keys using keyservers. + # Usage: gpg_find + function gpg_find() { + local email="''${1}" - if [[ "''${email}" = "" ]]; then - help gpg_find - return 2 - fi + if [[ "''${email}" = "" ]]; then + help gpg_find + return 2 + fi - gpg --locate-keys "''${email}" \ - || gpg --locate-keys --auto-key-locate hkps://keys.openpgp.org "''${email}" - } + gpg --locate-keys "''${email}" \ + || gpg --locate-keys --auto-key-locate hkps://keys.openpgp.org "''${email}" + } - # Update keys. - function gpg_refresh() { - gpg --refresh-keys - } - ''; + # Update keys. + function gpg_refresh() { + gpg --refresh-keys + } + ''; } diff --git a/home/program/bash/module/Group.nix b/home/program/bash/module/Group.nix index a19ae26..a99809d 100644 --- a/home/program/bash/module/Group.nix +++ b/home/program/bash/module/Group.nix @@ -1,74 +1,73 @@ -{ ... }: -{ - text = '' - # Group files by extension. - # Usage: group_ext [FILES] - function group_ext() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) +{ ... }: { + text = '' + # Group files by extension. + # Usage: group_ext [FILES] + function group_ext() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - process() { - local ext=''${target##*.} - [[ -d "''${target}" ]] && { _iterate_skip "Is a directory."; return 0; } - [[ "''${ext}" = "''${target}" ]] && { _iterate_skip "No extension."; return 0; } + process() { + local ext=''${target##*.} + [[ -d "''${target}" ]] && { _iterate_skip "Is a directory."; return 0; } + [[ "''${ext}" = "''${target}" ]] && { _iterate_skip "No extension."; return 0; } - mkdir ''${ext} 2> /dev/null + mkdir ''${ext} 2> /dev/null - mv -- ''${target} ./''${ext}/''${target} - } + mv -- ''${target} ./''${ext}/''${target} + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Group files and dirs by year. - # Usage: group_year [FILES] - function group_year() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(ls)) + # Group files and dirs by year. + # Usage: group_year [FILES] + function group_year() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls)) - process() { - local year=$(stat --format=%y ''${target}) - year=''${year%%-*} + process() { + local year=$(stat --format=%y ''${target}) + year=''${year%%-*} - mkdir ''${year} 2> /dev/null + mkdir ''${year} 2> /dev/null - mv -- ''${target} ./''${year}/''${target} - } + mv -- ''${target} ./''${year}/''${target} + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Copy files from current year to the named dir. - # Usage: group_year_copy [FILES] - function group_year_copy() { - local IFS=$'\n' - local selected_year="''${1}" - local targets=(''${@:2}) + # Copy files from current year to the named dir. + # Usage: group_year_copy [FILES] + function group_year_copy() { + local IFS=$'\n' + local selected_year="''${1}" + local targets=(''${@:2}) - if [[ "''${selected_year}" = "" ]]; then - help group_year_copy - return 2 - fi + if [[ "''${selected_year}" = "" ]]; then + help group_year_copy + return 2 + fi - # All files by default. - [[ "''${targets}" = "" ]] && targets=($(ls)) + # All files by default. + [[ "''${targets}" = "" ]] && targets=($(ls)) - mkdir ''${selected_year} 2> /dev/null + mkdir ''${selected_year} 2> /dev/null - process() { - local year=$(stat --format=%y ''${target}) - year=''${year%%-*} + process() { + local year=$(stat --format=%y ''${target}) + year=''${year%%-*} - if [[ "''${year}" = "''${selected_year}" ]]; then - rcp -- ''${target} ./''${selected_year}/ - else - _iterate_skip "Skip: ''${year}" - fi - } + if [[ "''${year}" = "''${selected_year}" ]]; then + rcp -- ''${target} ./''${selected_year}/ + else + _iterate_skip "Skip: ''${year}" + fi + } - _iterate_targets process ''${targets[@]} - } - ''; + _iterate_targets process ''${targets[@]} + } + ''; } diff --git a/home/program/bash/module/Help.nix b/home/program/bash/module/Help.nix index 27e9eaf..1949c92 100644 --- a/home/program/bash/module/Help.nix +++ b/home/program/bash/module/Help.nix @@ -1,30 +1,29 @@ -{ ... }: -{ - text = '' - # Get help about dotfiles bash function. - # Usage: help - function help() { - local fun="''${1}" +{ ... }: { + text = '' + # Get help about dotfiles bash function. + # Usage: help + function help() { + local fun="''${1}" - if [[ "''${fun}" = "" ]] || [[ "$(find_function | grep ''${fun})" = "" ]]; then - help help - return 2 - fi + if [[ "''${fun}" = "" ]] || [[ "$(find_function | grep ''${fun})" = "" ]]; then + help help + return 2 + fi - cat ~/.bashrc | sed -n -e "/^function ''${fun}()/q;p" | tac | sed -n -e "/^[^#]/q;p" | tac | sed -e "s/^# \+//" -e "\$i \ " | sed "1{/^$/d}" | sed "1{/^ *$/d}" - } + cat ~/.bashrc | sed -n -e "/^function ''${fun}()/q;p" | tac | sed -n -e "/^[^#]/q;p" | tac | sed -e "s/^# \+//" -e "\$i \ " | sed "1{/^$/d}" | sed "1{/^ *$/d}" + } - # Short for help. - # Usage: h - function h() { - help "''${@}" - } + # Short for help. + # Usage: h + function h() { + help "''${@}" + } - # Autocomplete with available functions. - function _help_functions() { - _autocomplete_first $(find_function) - } + # Autocomplete with available functions. + function _help_functions() { + _autocomplete_first $(find_function) + } - complete -F _help_functions help h - ''; + complete -F _help_functions help h + ''; } diff --git a/home/program/bash/module/Ls.nix b/home/program/bash/module/Ls.nix index ca001d7..e4cbd06 100644 --- a/home/program/bash/module/Ls.nix +++ b/home/program/bash/module/Ls.nix @@ -1,71 +1,70 @@ -{ ... }: -{ - text = '' - # Unset possible system-defined aliases. - unalias l ll lll llll la lla &> /dev/null - unset l ll lll llll la lla &> /dev/null +{ ... }: { + text = '' + # Unset possible system-defined aliases. + unalias l ll lll llll la lla &> /dev/null + unset l ll lll llll la lla &> /dev/null - # List files in dirs. - # Current dir by default. - # Usage: l [DIRS] - function l() { - # ls -lhv --si --group-directories-first --color=auto -- "$@" - ccd "$@" - } + # List files in dirs. + # Current dir by default. + # Usage: l [DIRS] + function l() { + # ls -lhv --si --group-directories-first --color=auto -- "$@" + ccd "$@" + } - # List last modified files first. - # Current dir by default. - # Usage: ll [DIRS] - function ll() { - ls -lhv --si --group-directories-first --color=auto -- "$@" - # ls -lhvtr --si --color=auto -- "$@" - } + # List last modified files first. + # Current dir by default. + # Usage: ll [DIRS] + function ll() { + ls -lhv --si --group-directories-first --color=auto -- "$@" + # ls -lhvtr --si --color=auto -- "$@" + } - # List files in tree structure. - # Current dir by default. - # Depth can be omitted by passing `-` (dash). - # Usage: lll [DEPTH] [DIRS] - function lll() { - local IFS=$'\n' - local depth="''${1}" - local target=("''${@:2}") + # List files in tree structure. + # Current dir by default. + # Depth can be omitted by passing `-` (dash). + # Usage: lll [DEPTH] [DIRS] + function lll() { + local IFS=$'\n' + local depth="''${1}" + local target=("''${@:2}") - [[ "''${target}" = "" ]] && target="." - [[ "''${depth}" = "" ]] && depth=666 - [[ "''${depth}" = "-" ]] && depth=666 + [[ "''${target}" = "" ]] && target="." + [[ "''${depth}" = "" ]] && depth=666 + [[ "''${depth}" = "-" ]] && depth=666 - tree -a -L "''${depth}" -- "''${target[@]}" - } + tree -a -L "''${depth}" -- "''${target[@]}" + } - # List files recursively. - # Current dir by default. - # Usage: llll [DIRS] - function llll() { - ls -RlAhv --si --group-directories-first --color=auto -- "$@" - } + # List files recursively. + # Current dir by default. + # Usage: llll [DIRS] + function llll() { + ls -RlAhv --si --group-directories-first --color=auto -- "$@" + } - # List all files in dirs, incl. hidden files. - # Current dir by default. - # Usage: la [DIRS] - function la() { - ls -lAh --si --group-directories-first --color=auto -- "$@" - } + # List all files in dirs, incl. hidden files. + # Current dir by default. + # Usage: la [DIRS] + function la() { + ls -lAh --si --group-directories-first --color=auto -- "$@" + } - # List all files in dirs, incl. hidden files, sorted by mtime. - # Current dir by default. - # Usage: lla [DIRS] - function lla() { - ls -lAhtr --si --color=auto -- "$@" - } + # List all files in dirs, incl. hidden files, sorted by mtime. + # Current dir by default. + # Usage: lla [DIRS] + function lla() { + ls -lAhtr --si --color=auto -- "$@" + } - # List only files. - function _ls_file() { - ls --classify | grep -v \/$ - } + # List only files. + function _ls_file() { + ls --classify | grep -v \/$ + } - # List only dirs. - function _ls_dir() { - ls --classify | grep \/$ | sed -e "s/\/$//" - } - ''; + # List only dirs. + function _ls_dir() { + ls --classify | grep \/$ | sed -e "s/\/$//" + } + ''; } diff --git a/home/program/bash/module/Name.nix b/home/program/bash/module/Name.nix index ce33025..130581d 100644 --- a/home/program/bash/module/Name.nix +++ b/home/program/bash/module/Name.nix @@ -1,400 +1,399 @@ -{ ... }: -{ - text = '' - # Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives! - # Usage: name [FILES] - function name() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(ls)) - - process() { - # Skip archive. - if $(_is_archive "''${target}"); then - _iterate_skip "File is an archive, skip." - return 0 - fi - - if [[ -d "''${target}" ]]; then - local new_name=$(parse_snake ''${target}) - [[ -e "''${new_name}" ]] && return 0 - - mv -- ''${target} ''${new_name} && echo ''${new_name} - else - local ext=".''${target##*.}" - local name=''${target%.*} - [[ "''${ext}" = ".''${target}" ]] && ext="" - - local new_name="$(parse_pascal ''${name})''${ext}" - [[ -e "''${new_name}" ]] && return 0 - - mv -- ''${target} ''${new_name} && echo ''${new_name} - fi - } - - _iterate_targets process ''${targets[@]} - } - - # Rename files with provided parser, i.e. `parse_simple`. - # All files by default. - # Usage: name_parse [FILES] - function name_parse() { - local IFS=$'\n' - local parser=''${1} - local targets=(''${@:2}) - [[ "''${targets}" = "" ]] && targets=([^.]*) - - if [[ "''${parser}" = "" ]]; then - help name_parse - return 2 - fi - - process() { - # Skip archive. - if $(_is_archive "''${target}"); then - _iterate_skip "File is an archive, skip." - return 0 - fi - - # parse new name. - local ext="" - local name="''${target}" - - # ext only for files. - if [[ -f "''${target}" ]]; then - ext=".''${target##*.}" - name="''${target%.*}" - fi - - # Files w/o extension support. - [[ "''${ext#.}" = "''${name}" ]] && ext="" - - # Get new name. - local new_name=$(''${parser} "''${name}")''${ext,,} - - # check if same name. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # check if target name already exists. - if [[ -f "''${new_name}" ]]; then - _error "''${new_name}: Already exists!" - return 1 - fi - - # rename target. - mv -- "''${target}" "''${new_name}" && echo "''${new_name}" - } - - _iterate_targets process ''${targets[@]} - } - - # Rename all files to their hashes while keeping extensions. - # All files by default. - # Usage: name_hash [FILES] - function name_hash() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - - process() { - # extract extension. - local extension="''${target##*.}" - if [[ "''${extension}" = "''${target}" ]]; then - extension="" - else - extension=".''${extension}" - fi - - # hash the new name. - local hash=$(pv "''${target}" | sha1sum | cut -d\ -f1) - new_name="''${hash,,}''${extension,,}" - - # check if same name. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # rename target. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Check hashes for previously renamed files. - # All files by default. - # Usage: name_hash_check [FILES] - function name_hash_check() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=([^.]*) - - process() { - # extract hashes. - local stored="''${target%%.*}" - local actual=$(pv "''${target}" | sha1sum | cut -d\ -f1) - - # compare hashes. - if [[ "''${stored}" != "''${actual}" ]]; then - _error "Failed." - return 1 - fi - } - - _iterate_targets process ''${targets[@]} - } - - # Rename files for Jellyfin shows, i.e. `Episode S01E01.mkv` - # All files by default. - # Usage: name_show [FILES] - function name_show() { - local IFS=$'\n' - local season="$(realpath .)"; season="''${season##*\ }" - local episode=0 - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - - # Error when no season number specified. - if [[ "''${season}" = "" ]]; then - _error "Could not determine season number." - return 2 - fi - - process() { - ((episode++)) - - # extract new name. - local new_name="Episode S''${season}E$(printf %02d ''${episode}).''${target##*.}" - - # Skip on no change. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # rename target. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Rename files for Kavita manga format. - # All files by default. - # Usage: name_manga [FILES] - function name_manga() { - local IFS=$'\n' - local manga=''${PWD##*/} - local season=''${1} - local episode=0 - local targets=(''${@:2}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - - # Error when no season number specified. - if [[ "''${season}" = "" ]]; then - help name_manga - return 2 - fi - - process() { - ((episode++)) - - # Extract new name. - local new_name="''${manga} Vol.''${season} Ch.''${episode}.''${target##*.}" - - # Skip on no change. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Rename target. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Rename files for ffmpeg_music_meta format. - # All files by default. - # Usage: name_music [FILES] - function name_music() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(ls)) - - process() { - # Extract new name. - local ext=''${target##*.} - - if [[ -d "''${target}" ]]; then - local new_name="$(parse_startcase $(parse_simple ''${target%.*}))" - else - local new_name="$(parse_startcase $(parse_simple ''${target%.*})).''${ext}" - fi - - # Skip on no change. - [[ "''${target%/}" = "''${new_name}" ]] && return 0 - - # Rename target. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Rename files with new extension. - # All files by default. - # Usage: name_ext [FILES] - function name_ext() { - local IFS=$'\n' - local extension=''${1} - local targets=(''${@:2}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - - # Error when no new extension specified. - if [[ "''${extension}" = "" ]]; then - help name_ext - return 2 - fi - - process() { - # Extract new name. - local new_name="''${target%.*}"."''${extension}" - - # Skip on no change. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Rename target. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Change file name prefix. - # All matching files by default. - # Usage: name_prefix [FILES] - function name_prefix() { - local IFS=$'\n' - local old=''${1} - local new=''${2} - local targets=(''${@:3}) - [[ "''${targets}" = "" ]] && targets=(''${old}*) - - process() { - # Create new name. - local new_name="''${new}''${target#$old}" - - # Skip on no change. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Rename. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Change file name postfix. - # All matching files by default. - # Usage: name_postfix [FILES] - function name_postfix() { - local IFS=$'\n' - local old=''${1} - local new=''${2} - local targets=(''${@:3}) - [[ "''${targets}" = "" ]] && targets=(*''${old}) - - process() { - # Create new name. - local new_name="''${target%$old}''${new}" - - # Skip on no change. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Rename. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Replace part of the name. - # All matching files by default. - # Usage: name_replace [FILES] - function name_replace() { - local IFS=$'\n' - local old=''${1} - local new=''${2} - local targets=(''${@:3}) - [[ "''${targets}" = "" ]] && targets=(*''${old}*) - - process() { - # Create new name. - local new_name="''${target//$old/$new}" - - # Skip on no change. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Rename. - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - # Fix numbering for numbered files. I.e if there are 10 items and some of them start without zero, then append zero to it. 1..10 -> 01..10. - # Usage: name_fix_numbering [FILES] - function name_fix_numbering() { - local IFS=$'\n' - local highest=0 - local power=0 - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(ls | grep "^[0-9]")) - - # Count leading zeroes. - for target in "''${targets[@]}"; do - # Check that starts with a digit. - [[ "''${target}" =~ ^[0-9] ]] || continue - - local digits=($(parse_ints "''${target}")) - local digit="''${digits[0]}" - digit=$((10#''${digit})) - - [[ "''${digit}" -gt "''${highest}" ]] && highest="''${digit}" - done - - local i=''${highest} - while [[ i -gt 0 ]]; do - ((power++)) - i=$((''${i}/10)) - done - - process() { - # Check that starts with a digit. - if [[ ! "''${target}" =~ ^[0-9] ]]; then - _error "Does not start with a digit!" - return 1 - fi - - # Prepare new name. - local digits=($(parse_ints "''${target}")) - local digit="''${digits[0]}" - digit=$((10#''${digit})) - local new_name=$(printf "%0''${power}d" "''${digit}")"''${target#''${digits[0]}}" - - # Skip if the same name. - [[ "''${target}" = "''${new_name}" ]] && return 0 - - # Check that file does not exist. - if [[ -e "''${new_name}" ]]; then - _error "''${new_name}: File exists!" - return 1 - fi - - mv -- ''${target} ''${new_name} && echo ''${new_name} - } - - _iterate_targets process ''${targets[@]} - } - - function _comp_name_parse() { - _autocomplete_first_ls $(find_function | grep ^parse) - } - - complete -o filenames -F _comp_name_parse name_parse - ''; +{ ... }: { + text = '' + # Rename dirs to `snake_case` and files to `PascalCase`. Careful with structured file names like archives! + # Usage: name [FILES] + function name() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls)) + + process() { + # Skip archive. + if $(_is_archive "''${target}"); then + _iterate_skip "File is an archive, skip." + return 0 + fi + + if [[ -d "''${target}" ]]; then + local new_name=$(parse_snake ''${target}) + [[ -e "''${new_name}" ]] && return 0 + + mv -- ''${target} ''${new_name} && echo ''${new_name} + else + local ext=".''${target##*.}" + local name=''${target%.*} + [[ "''${ext}" = ".''${target}" ]] && ext="" + + local new_name="$(parse_pascal ''${name})''${ext}" + [[ -e "''${new_name}" ]] && return 0 + + mv -- ''${target} ''${new_name} && echo ''${new_name} + fi + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files with provided parser, i.e. `parse_simple`. + # All files by default. + # Usage: name_parse [FILES] + function name_parse() { + local IFS=$'\n' + local parser=''${1} + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=([^.]*) + + if [[ "''${parser}" = "" ]]; then + help name_parse + return 2 + fi + + process() { + # Skip archive. + if $(_is_archive "''${target}"); then + _iterate_skip "File is an archive, skip." + return 0 + fi + + # parse new name. + local ext="" + local name="''${target}" + + # ext only for files. + if [[ -f "''${target}" ]]; then + ext=".''${target##*.}" + name="''${target%.*}" + fi + + # Files w/o extension support. + [[ "''${ext#.}" = "''${name}" ]] && ext="" + + # Get new name. + local new_name=$(''${parser} "''${name}")''${ext,,} + + # check if same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # check if target name already exists. + if [[ -f "''${new_name}" ]]; then + _error "''${new_name}: Already exists!" + return 1 + fi + + # rename target. + mv -- "''${target}" "''${new_name}" && echo "''${new_name}" + } + + _iterate_targets process ''${targets[@]} + } + + # Rename all files to their hashes while keeping extensions. + # All files by default. + # Usage: name_hash [FILES] + function name_hash() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + process() { + # extract extension. + local extension="''${target##*.}" + if [[ "''${extension}" = "''${target}" ]]; then + extension="" + else + extension=".''${extension}" + fi + + # hash the new name. + local hash=$(pv "''${target}" | sha1sum | cut -d\ -f1) + new_name="''${hash,,}''${extension,,}" + + # check if same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Check hashes for previously renamed files. + # All files by default. + # Usage: name_hash_check [FILES] + function name_hash_check() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=([^.]*) + + process() { + # extract hashes. + local stored="''${target%%.*}" + local actual=$(pv "''${target}" | sha1sum | cut -d\ -f1) + + # compare hashes. + if [[ "''${stored}" != "''${actual}" ]]; then + _error "Failed." + return 1 + fi + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files for Jellyfin shows, i.e. `Episode S01E01.mkv` + # All files by default. + # Usage: name_show [FILES] + function name_show() { + local IFS=$'\n' + local season="$(realpath .)"; season="''${season##*\ }" + local episode=0 + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Error when no season number specified. + if [[ "''${season}" = "" ]]; then + _error "Could not determine season number." + return 2 + fi + + process() { + ((episode++)) + + # extract new name. + local new_name="Episode S''${season}E$(printf %02d ''${episode}).''${target##*.}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files for Kavita manga format. + # All files by default. + # Usage: name_manga [FILES] + function name_manga() { + local IFS=$'\n' + local manga=''${PWD##*/} + local season=''${1} + local episode=0 + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Error when no season number specified. + if [[ "''${season}" = "" ]]; then + help name_manga + return 2 + fi + + process() { + ((episode++)) + + # Extract new name. + local new_name="''${manga} Vol.''${season} Ch.''${episode}.''${target##*.}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files for ffmpeg_music_meta format. + # All files by default. + # Usage: name_music [FILES] + function name_music() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls)) + + process() { + # Extract new name. + local ext=''${target##*.} + + if [[ -d "''${target}" ]]; then + local new_name="$(parse_startcase $(parse_simple ''${target%.*}))" + else + local new_name="$(parse_startcase $(parse_simple ''${target%.*})).''${ext}" + fi + + # Skip on no change. + [[ "''${target%/}" = "''${new_name}" ]] && return 0 + + # Rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Rename files with new extension. + # All files by default. + # Usage: name_ext [FILES] + function name_ext() { + local IFS=$'\n' + local extension=''${1} + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + + # Error when no new extension specified. + if [[ "''${extension}" = "" ]]; then + help name_ext + return 2 + fi + + process() { + # Extract new name. + local new_name="''${target%.*}"."''${extension}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename target. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Change file name prefix. + # All matching files by default. + # Usage: name_prefix [FILES] + function name_prefix() { + local IFS=$'\n' + local old=''${1} + local new=''${2} + local targets=(''${@:3}) + [[ "''${targets}" = "" ]] && targets=(''${old}*) + + process() { + # Create new name. + local new_name="''${new}''${target#$old}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Change file name postfix. + # All matching files by default. + # Usage: name_postfix [FILES] + function name_postfix() { + local IFS=$'\n' + local old=''${1} + local new=''${2} + local targets=(''${@:3}) + [[ "''${targets}" = "" ]] && targets=(*''${old}) + + process() { + # Create new name. + local new_name="''${target%$old}''${new}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Replace part of the name. + # All matching files by default. + # Usage: name_replace [FILES] + function name_replace() { + local IFS=$'\n' + local old=''${1} + local new=''${2} + local targets=(''${@:3}) + [[ "''${targets}" = "" ]] && targets=(*''${old}*) + + process() { + # Create new name. + local new_name="''${target//$old/$new}" + + # Skip on no change. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Rename. + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + # Fix numbering for numbered files. I.e if there are 10 items and some of them start without zero, then append zero to it. 1..10 -> 01..10. + # Usage: name_fix_numbering [FILES] + function name_fix_numbering() { + local IFS=$'\n' + local highest=0 + local power=0 + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(ls | grep "^[0-9]")) + + # Count leading zeroes. + for target in "''${targets[@]}"; do + # Check that starts with a digit. + [[ "''${target}" =~ ^[0-9] ]] || continue + + local digits=($(parse_ints "''${target}")) + local digit="''${digits[0]}" + digit=$((10#''${digit})) + + [[ "''${digit}" -gt "''${highest}" ]] && highest="''${digit}" + done + + local i=''${highest} + while [[ i -gt 0 ]]; do + ((power++)) + i=$((''${i}/10)) + done + + process() { + # Check that starts with a digit. + if [[ ! "''${target}" =~ ^[0-9] ]]; then + _error "Does not start with a digit!" + return 1 + fi + + # Prepare new name. + local digits=($(parse_ints "''${target}")) + local digit="''${digits[0]}" + digit=$((10#''${digit})) + local new_name=$(printf "%0''${power}d" "''${digit}")"''${target#''${digits[0]}}" + + # Skip if the same name. + [[ "''${target}" = "''${new_name}" ]] && return 0 + + # Check that file does not exist. + if [[ -e "''${new_name}" ]]; then + _error "''${new_name}: File exists!" + return 1 + fi + + mv -- ''${target} ''${new_name} && echo ''${new_name} + } + + _iterate_targets process ''${targets[@]} + } + + function _comp_name_parse() { + _autocomplete_first_ls $(find_function | grep ^parse) + } + + complete -o filenames -F _comp_name_parse name_parse + ''; } diff --git a/home/program/bash/module/Nix.nix b/home/program/bash/module/Nix.nix index 80d255d..c1cb32d 100644 --- a/home/program/bash/module/Nix.nix +++ b/home/program/bash/module/Nix.nix @@ -1,82 +1,81 @@ -{ ... }: -{ - text = '' - # Spawn shell with specified nix environment. - # Uses flake.nix in current dir by default. - # Usage: shell [NAME] - function shell() { - local target="''${1}" - [[ "''${target}" = "" ]] && target="default" +{ ... }: { + text = '' + # Spawn shell with specified nix environment. + # Uses flake.nix in current dir by default. + # Usage: shell [NAME] + function shell() { + local target="''${1}" + [[ "''${target}" = "" ]] && target="default" - SHELL_NAME="''${target}" nix develop ".#''${target}" - } + SHELL_NAME="''${target}" nix develop ".#''${target}" + } - # Spawn temporary nix-shell with specified packages. - # Usage: tmpshell - function tmpshell() { - local IFS=$'\n' - local input=("''${@}") - local pkgs=() - local tag="''${1}" + # Spawn temporary nix-shell with specified packages. + # Usage: tmpshell + function tmpshell() { + local IFS=$'\n' + local input=("''${@}") + local pkgs=() + local tag="''${1}" - if [[ "''${input}" = "" ]]; then - help tmpshell - return 2 - fi + if [[ "''${input}" = "" ]]; then + help tmpshell + return 2 + fi - for pkg in ''${input[@]}; do - pkgs+=("nixpkgs#''${pkg}") - done + for pkg in ''${input[@]}; do + pkgs+=("nixpkgs#''${pkg}") + done - SHELL_NAME="''${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ''${pkgs[@]} - } + SHELL_NAME="''${tag}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure ''${pkgs[@]} + } - # Run stuff directrly from Nixpks. - # Usage: nixpkgs_run [COMMAND] - function nixpkgs_run() { - local rev="''${1}" - local pkg="''${2}" - local cmd="''${@:3}" + # Run stuff directrly from Nixpks. + # Usage: nixpkgs_run [COMMAND] + function nixpkgs_run() { + local rev="''${1}" + local pkg="''${2}" + local cmd="''${@:3}" - if [[ "''${pkg}" = "" ]]; then - help nixpkgs_run - return 2 - fi + if [[ "''${pkg}" = "" ]]; then + help nixpkgs_run + return 2 + fi - [[ "''${cmd}" = "" ]] && cmd="''${pkg}" + [[ "''${cmd}" = "" ]] && cmd="''${pkg}" - SHELL_NAME="''${pkg}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure github:NixOS/nixpkgs/''${rev}#''${pkg} -c ''${cmd} - } + SHELL_NAME="''${pkg}" NIXPKGS_ALLOW_UNFREE=1 nix shell --impure github:NixOS/nixpkgs/''${rev}#''${pkg} -c ''${cmd} + } - # Prefetch to nix store. - # Usage: prefetch - function prefetch() { - local url="''${1}" + # Prefetch to nix store. + # Usage: prefetch + function prefetch() { + local url="''${1}" - if [[ "''${url}" = "" ]]; then - help prefetch - return 2 - fi + if [[ "''${url}" = "" ]]; then + help prefetch + return 2 + fi - nix hash to-sri --type sha256 $(nix-prefetch-url "''${url}") - } + nix hash to-sri --type sha256 $(nix-prefetch-url "''${url}") + } - # Run nix locally with no builders. - # Usage: nix_local - function nix_local() { - nix --option max-jobs $(_core_count) --builders "" --substituters https://cache.nixos.org ''${@} - } + # Run nix locally with no builders. + # Usage: nix_local + function nix_local() { + nix --option max-jobs $(_core_count) --builders "" --substituters https://cache.nixos.org ''${@} + } - # Run test app from other people PRs. - # Usage: nix_test github:user/nixpkgs/# - function nix_test() { - if [[ "''${@}" = "" ]]; then - help nix_test - return 2 - fi + # Run test app from other people PRs. + # Usage: nix_test github:user/nixpkgs/# + function nix_test() { + if [[ "''${@}" = "" ]]; then + help nix_test + return 2 + fi - local name=''${*##*#} - SHELL_NAME="''${name}" NIXPKGS_ALLOW_UNFREE=1 nix --option max-jobs $(_core_count) --builders "" --substituters https://cache.nixos.org shell --impure ''${@} - } - ''; + local name=''${*##*#} + SHELL_NAME="''${name}" NIXPKGS_ALLOW_UNFREE=1 nix --option max-jobs $(_core_count) --builders "" --substituters https://cache.nixos.org shell --impure ''${@} + } + ''; } diff --git a/home/program/bash/module/Notify.nix b/home/program/bash/module/Notify.nix index 87065ba..261322e 100644 --- a/home/program/bash/module/Notify.nix +++ b/home/program/bash/module/Notify.nix @@ -1,16 +1,15 @@ -{ secret, ... }: -{ - text = '' - # Send Telegram notification. - # Usage: notify - function notify() { - curl -X POST -H 'Content-Type: Application/json' -d "${secret.tg.dt "false"}" ${secret.tg.bt} &> /dev/null - } +{ secret, ... }: { + text = '' + # Send Telegram notification. + # Usage: notify + function notify() { + curl -X POST -H 'Content-Type: Application/json' -d "${secret.tg.dt "false"}" ${secret.tg.bt} &> /dev/null + } - # Send silent Telegram notification. - # Usage: notify_silent - function notify_silent() { - curl -X POST -H 'Content-Type: Application/json' -d "${secret.tg.dt "true"}" ${secret.tg.bt} &> /dev/null - } - ''; + # Send silent Telegram notification. + # Usage: notify_silent + function notify_silent() { + curl -X POST -H 'Content-Type: Application/json' -d "${secret.tg.dt "true"}" ${secret.tg.bt} &> /dev/null + } + ''; } diff --git a/home/program/bash/module/Own.nix b/home/program/bash/module/Own.nix index 7630b9b..067d9c2 100644 --- a/home/program/bash/module/Own.nix +++ b/home/program/bash/module/Own.nix @@ -1,41 +1,40 @@ -{ ... }: -{ - text = '' - # Change file ownership to specified user id and restrict access to him. - # Root user by default. This directory recursively by default. - # Usage: own [USER] [FILES] - function own() { - local IFS=$'\n' - local files=("''${@:2}") - local user="''${1}" - local group="''${1}" +{ ... }: { + text = '' + # Change file ownership to specified user id and restrict access to him. + # Root user by default. This directory recursively by default. + # Usage: own [USER] [FILES] + function own() { + local IFS=$'\n' + local files=("''${@:2}") + local user="''${1}" + local group="''${1}" - # default to current dir. - if [ "''${files[*]}" = "" ]; then - files=(".") - fi + # default to current dir. + if [ "''${files[*]}" = "" ]; then + files=(".") + fi - # default to current user. - if [ "''${user}" = "" ]; then - user="''${UID}" - fi + # default to current user. + if [ "''${user}" = "" ]; then + user="''${UID}" + fi - # If not root, default to users group. - [[ "''${user}" = 0 ]] && group="0" || group="100" + # If not root, default to users group. + [[ "''${user}" = 0 ]] && group="0" || group="100" - for file in "''${files[@]}"; do - # set ownership. - chown "''${user}":"''${group}" -R "''${file}" &> /dev/null + for file in "''${files[@]}"; do + # set ownership. + chown "''${user}":"''${group}" -R "''${file}" &> /dev/null - # remove access from group and others. - chmod -077 -R "''${file}" - done - } + # remove access from group and others. + chmod -077 -R "''${file}" + done + } - function _complete_own() { - _autocomplete_first_ls $(_get_users) - } + function _complete_own() { + _autocomplete_first_ls $(_get_users) + } - complete -F _complete_own own - ''; + complete -F _complete_own own + ''; } diff --git a/home/program/bash/module/Pack.nix b/home/program/bash/module/Pack.nix index eaff272..37eb1cb 100644 --- a/home/program/bash/module/Pack.nix +++ b/home/program/bash/module/Pack.nix @@ -1,209 +1,208 @@ -{ ... }: -{ - text = '' - export _unpack_supported=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" +{ ... }: { + text = '' + export _unpack_supported=".tar$|.tgz$|.txz$|.tar.gz$|.tar.xz$|.zip$|.iso$|.rar$" - # Pack files into desired format. - # All files and directories by default. - # Usage: pack [FILES] - function pack() { - local IFS=$'\n' - local output="''${1}" - local targets=("''${@:2}") - local format="''${output##*.}" - local name="''${output%.*}" + # Pack files into desired format. + # All files and directories by default. + # Usage: pack [FILES] + function pack() { + local IFS=$'\n' + local output="''${1}" + local targets=("''${@:2}") + local format="''${output##*.}" + local name="''${output%.*}" - # report no output. - if [[ "''${output}" = "" ]]; then - help pack - return 2 - fi + # report no output. + if [[ "''${output}" = "" ]]; then + help pack + return 2 + fi - # report no format. - if [[ "''${format}" = "" ]]; then - _error "Could not determine output format." - help pack - return 2 - fi + # report no format. + if [[ "''${format}" = "" ]]; then + _error "Could not determine output format." + help pack + return 2 + fi - # All targets by default. - [[ "''${targets}" = "" ]] && targets=(*) + # All targets by default. + [[ "''${targets}" = "" ]] && targets=(*) - case "''${format}" in - "tgz") - _pack_tgz "''${output}" "''${targets[@]}" - ;; - "txz") - _pack_txz "''${output}" "''${targets[@]}" - ;; - "tar") - _pack_tar "''${output}" "''${targets[@]}" - ;; - "zip") - _pack_zip "''${output}" "''${targets[@]}" - ;; - "gz") - _pack_gz "''${output}" "''${targets[@]}" - ;; - "xz") - _pack_xz "''${output}" "''${targets[@]}" - ;; - "iso") - _pack_iso "''${output}" "''${targets[@]}" - ;; - *) - _error "''${target}: Format not supported." - return 2 - ;; - esac - } + case "''${format}" in + "tgz") + _pack_tgz "''${output}" "''${targets[@]}" + ;; + "txz") + _pack_txz "''${output}" "''${targets[@]}" + ;; + "tar") + _pack_tar "''${output}" "''${targets[@]}" + ;; + "zip") + _pack_zip "''${output}" "''${targets[@]}" + ;; + "gz") + _pack_gz "''${output}" "''${targets[@]}" + ;; + "xz") + _pack_xz "''${output}" "''${targets[@]}" + ;; + "iso") + _pack_iso "''${output}" "''${targets[@]}" + ;; + *) + _error "''${target}: Format not supported." + return 2 + ;; + esac + } - # Attempt to unpack. - # All supported formats by default. - # Usage: unpack [FILES] - function unpack() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_files | grep -E ''${_unpack_supported})) + # Attempt to unpack. + # All supported formats by default. + # Usage: unpack [FILES] + function unpack() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_files | grep -E ''${_unpack_supported})) - process() { - # Use full path to file. - target=''$(realpath "''${target}") + process() { + # Use full path to file. + target=''$(realpath "''${target}") - # Check for archive. - if $(_is_archive "''${target}"); then - unarchive "''${target}" - return 0 - fi + # Check for archive. + if $(_is_archive "''${target}"); then + unarchive "''${target}" + return 0 + fi - # Unpack file type. - local type="''${target##*.}" + # Unpack file type. + local type="''${target##*.}" - [[ "''${target}" =~ .tar.gz$ ]] && type="tar.gz" - [[ "''${target}" =~ .tar.xz$ ]] && type="tar.xz" + [[ "''${target}" =~ .tar.gz$ ]] && type="tar.gz" + [[ "''${target}" =~ .tar.xz$ ]] && type="tar.xz" - # Make a dir for files. - local dir="''${target%.$type}"; dir="''${dir##*/}" - mkdir "''${dir}" > /dev/null - pushd "''${dir}" > /dev/null + # Make a dir for files. + local dir="''${target%.$type}"; dir="''${dir##*/}" + mkdir "''${dir}" > /dev/null + pushd "''${dir}" > /dev/null - # Unpack content. - case "''${type,,}" in - "zip") - _unpack_zip "''${target}" - ;; - "7z") - _unpack_7z "''${target}" - ;; - "tgz"|"tar.gz") - _unpack_tgz "''${target}" - ;; - "txz"|"tar.xz") - _unpack_txz "''${target}" - ;; - "tar") - _unpack_tar "''${target}" - ;; - "iso") - _unpack_iso "''${target}" - ;; - "rar") - _unpack_rar "''${target}" - ;; - "xz") - _unpack_xz "''${target}" - ;; - "gz") - _unpack_gz "''${target}" - ;; - *) - _error "''${target}: Format not supported." - return 2 - ;; - esac + # Unpack content. + case "''${type,,}" in + "zip") + _unpack_zip "''${target}" + ;; + "7z") + _unpack_7z "''${target}" + ;; + "tgz"|"tar.gz") + _unpack_tgz "''${target}" + ;; + "txz"|"tar.xz") + _unpack_txz "''${target}" + ;; + "tar") + _unpack_tar "''${target}" + ;; + "iso") + _unpack_iso "''${target}" + ;; + "rar") + _unpack_rar "''${target}" + ;; + "xz") + _unpack_xz "''${target}" + ;; + "gz") + _unpack_gz "''${target}" + ;; + *) + _error "''${target}: Format not supported." + return 2 + ;; + esac - # Cd back. - popd > /dev/null - } + # Cd back. + popd > /dev/null + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - function _pack_zip() { - zip -9 -r "''${@}" - } + function _pack_zip() { + zip -9 -r "''${@}" + } - function _pack_tgz() { - tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "''${1}" - } + function _pack_tgz() { + tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') | gzip -1 > "''${1}" + } - function _pack_txz() { - tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "''${1}" - } + function _pack_txz() { + tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') | xz -9e > "''${1}" + } - function _pack_tar() { - tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') > "''${1}" - } + function _pack_tar() { + tar -c "''${@:2}" | pv -s $(/usr/bin/env du -csb "''${@:2}" | sed -n -e '$p' | awk '{print $1}') > "''${1}" + } - function _pack_gz() { - pv "''${2}" | gzip -1 > "''${1}" - } + function _pack_gz() { + pv "''${2}" | gzip -1 > "''${1}" + } - function _pack_xz() { - pv "''${2}" | xz -9e > "''${1}" - } + function _pack_xz() { + pv "''${2}" | xz -9e > "''${1}" + } - function _pack_iso() { - local input=("''${@:2}") - local output="''${1}" - local args=() + function _pack_iso() { + local input=("''${@:2}") + local output="''${1}" + local args=() - for arg in ''${input[@]}; do - [[ -d "''${arg}" ]] || { - _error "''${arg} is not a directory." - return 1 - }; + for arg in ''${input[@]}; do + [[ -d "''${arg}" ]] || { + _error "''${arg} is not a directory." + return 1 + }; - args+=("''${arg}=''${arg}") - done + args+=("''${arg}=''${arg}") + done - genisoimage -J -r -pad -o "''${output}" -graft-points "''${args[@]}" - } + genisoimage -J -r -pad -o "''${output}" -graft-points "''${args[@]}" + } - function _unpack_zip() { - unzip "''${1}" - } + function _unpack_zip() { + unzip "''${1}" + } - function _unpack_7z() { - 7za x "''${1}" - } + function _unpack_7z() { + 7za x "''${1}" + } - function _unpack_tgz() { - pv "''${1}" | gzip -d | tar -xf - - } + function _unpack_tgz() { + pv "''${1}" | gzip -d | tar -xf - + } - function _unpack_txz() { - pv "''${1}" | xz -d | tar -xf - - } + function _unpack_txz() { + pv "''${1}" | xz -d | tar -xf - + } - function _unpack_tar() { - pv "''${1}" | tar -xf - - } + function _unpack_tar() { + pv "''${1}" | tar -xf - + } - function _unpack_iso() { - 7za x "''${1}" - } + function _unpack_iso() { + 7za x "''${1}" + } - function _unpack_rar() { - unrar x "''${1}" - } + function _unpack_rar() { + unrar x "''${1}" + } - function _unpack_gz() { - pv "''${1}" | gzip -d > "''${1%.gz}" - } + function _unpack_gz() { + pv "''${1}" | gzip -d > "''${1%.gz}" + } - function _unpack_xz() { - pv "''${1}" | xz -d > "''${1%.xz}" - } - ''; + function _unpack_xz() { + pv "''${1}" | xz -d > "''${1%.xz}" + } + ''; } diff --git a/home/program/bash/module/Parse.nix b/home/program/bash/module/Parse.nix index d5ae89a..dac76e0 100644 --- a/home/program/bash/module/Parse.nix +++ b/home/program/bash/module/Parse.nix @@ -1,173 +1,172 @@ -{ ... }: -{ - text = '' - export _PARSE_ALLOWED_CHARS="_-" - export _PARSE_SPLIT_CHARS="\.\ _-" +{ ... }: { + text = '' + export _PARSE_ALLOWED_CHARS="_-" + export _PARSE_SPLIT_CHARS="\.\ _-" - # Parse data and output simplified format. - # Usage: parse_simple - function parse_simple() { - echo "''${*}" | sed \ - -e "s/[''${_PARSE_SPLIT_CHARS}]/_/g" \ - -e "s/[^[:alnum:]''${_PARSE_ALLOWED_CHARS}]//g" \ - -e "s/_\+/_/g" -e "s/-\+/-/g" \ - -e "s/_-/_/g" -e "s/-_/_/g" \ - -e "s/_\+/_/g" \ - -e "s/^_//" -e "s/_$//" - } + # Parse data and output simplified format. + # Usage: parse_simple + function parse_simple() { + echo "''${*}" | sed \ + -e "s/[''${_PARSE_SPLIT_CHARS}]/_/g" \ + -e "s/[^[:alnum:]''${_PARSE_ALLOWED_CHARS}]//g" \ + -e "s/_\+/_/g" -e "s/-\+/-/g" \ + -e "s/_-/_/g" -e "s/-_/_/g" \ + -e "s/_\+/_/g" \ + -e "s/^_//" -e "s/_$//" + } - # Parse to PascalCase. - # Usage: parse_pascal - function parse_pascal() { - local parts=($(_get_parts $(parse_simple "''${*}"))) - local result + # Parse to PascalCase. + # Usage: parse_pascal + function parse_pascal() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result - for part in "''${parts[@]}"; do - local word="''${part,,}" - word="''${word^}" - result="''${result}''${word}" - done + for part in "''${parts[@]}"; do + local word="''${part,,}" + word="''${word^}" + result="''${result}''${word}" + done - echo "''${result}" - } + echo "''${result}" + } - # Parse to snake_case. - # Usage: parse_snake - function parse_snake() { - local parts=($(_get_parts $(parse_simple "''${*}"))) - local result + # Parse to snake_case. + # Usage: parse_snake + function parse_snake() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result - for part in "''${parts[@]}"; do - local word="''${part,,}" - result="''${result}_''${word}" - done + for part in "''${parts[@]}"; do + local word="''${part,,}" + result="''${result}_''${word}" + done - echo "''${result#_}" - } + echo "''${result#_}" + } - # Parse to kebab-case. - # Usage: parse_kebab - function parse_kebab() { - local parts=($(_get_parts $(parse_simple "''${*}"))) - local result + # Parse to kebab-case. + # Usage: parse_kebab + function parse_kebab() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result - for part in "''${parts[@]}"; do - local word="''${part,,}" - result="''${result}-''${word}" - done + for part in "''${parts[@]}"; do + local word="''${part,,}" + result="''${result}-''${word}" + done - echo "''${result#-}" - } + echo "''${result#-}" + } - # Parse to camelCase. - # Usage: parse_camel - function parse_camel() { - local parts=($(_get_parts $(parse_simple "''${*}"))) - local result + # Parse to camelCase. + # Usage: parse_camel + function parse_camel() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result - for part in "''${parts[@]}"; do - local word="''${part,,}" - word="''${word^}" - result="''${result}''${word}" - done + for part in "''${parts[@]}"; do + local word="''${part,,}" + word="''${word^}" + result="''${result}''${word}" + done - echo "''${result,}" - } + echo "''${result,}" + } - # Parse to SNAKE_CASE_UPPERCASE. **NOT STABLE! Repeating results in different output.** - # Usage: parse_snake_uppercase - function parse_snake_uppercase() { - local parts=($(_get_parts $(parse_simple "''${*}"))) - local result + # Parse to SNAKE_CASE_UPPERCASE. **NOT STABLE! Repeating results in different output.** + # Usage: parse_snake_uppercase + function parse_snake_uppercase() { + local parts=($(_get_parts $(parse_simple "''${*}"))) + local result - for part in "''${parts[@]}"; do - local word="''${part^^}" - result="''${result}_''${word}" - done + for part in "''${parts[@]}"; do + local word="''${part^^}" + result="''${result}_''${word}" + done - echo "''${result#_}" - } + echo "''${result#_}" + } - # Parse data keeping only alphanumeric characters. - # Usage: parse_alnum - function parse_alnum() { - echo "''${*}" | sed -e "s/[^[:alnum:]]//g" - } + # Parse data keeping only alphanumeric characters. + # Usage: parse_alnum + function parse_alnum() { + echo "''${*}" | sed -e "s/[^[:alnum:]]//g" + } - # Parse integers from mixed string. - # Usage: parse_ints - function parse_ints() { - echo "''${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g' - } + # Parse integers from mixed string. + # Usage: parse_ints + function parse_ints() { + echo "''${*}" | tr '\n' ' ' | sed -e 's/[^0-9]/ /g' -e 's/^ *//g' -e 's/ *$//g' | tr -s ' ' | sed 's/ /\n/g' + } - # Parse string to lowercase. - # Usage: parse_lowercase - function parse_lowercase() { - echo "''${*,,}" - } + # Parse string to lowercase. + # Usage: parse_lowercase + function parse_lowercase() { + echo "''${*,,}" + } - # Parse string to uppercase. - # Usage: parse_uppercase - function parse_uppercase() { - echo "''${*^^}" - } + # Parse string to uppercase. + # Usage: parse_uppercase + function parse_uppercase() { + echo "''${*^^}" + } - # Parse string to title case. - # Usage: parse_titlecase - function parse_titlecase() { - local IFS=$'\n' - local parts=($(_parse_split ''${@})) - local minors=("is" "at" "of" "to" "in" "for" "the" "a" "an" "and" "but" "or" "on" "was" "were" "been" "be" "do" "did" "does") + # Parse string to title case. + # Usage: parse_titlecase + function parse_titlecase() { + local IFS=$'\n' + local parts=($(_parse_split ''${@})) + local minors=("is" "at" "of" "to" "in" "for" "the" "a" "an" "and" "but" "or" "on" "was" "were" "been" "be" "do" "did" "does") - echo -n "$(parse_sentencecase ''${parts[0]})" - for part in ''${parts[@]:1}; do - if _contains $(echo ''${part,,} | sed -e "s/[''${_PARSE_SPLIT_CHARS}]//g") ''${minors[@]}; then - echo -n "''${part,,}" - else - echo -n "$(parse_sentencecase ''${part})" - fi - done + echo -n "$(parse_sentencecase ''${parts[0]})" + for part in ''${parts[@]:1}; do + if _contains $(echo ''${part,,} | sed -e "s/[''${_PARSE_SPLIT_CHARS}]//g") ''${minors[@]}; then + echo -n "''${part,,}" + else + echo -n "$(parse_sentencecase ''${part})" + fi + done - echo - } + echo + } - # Parse string to sentence case. - # Usage: parse_sentencecase - function parse_sentencecase() { - local lower="''${*,,}" - echo "''${lower^}" - } + # Parse string to sentence case. + # Usage: parse_sentencecase + function parse_sentencecase() { + local lower="''${*,,}" + echo "''${lower^}" + } - # Parse string to start case. - # Usage: parse_startcase - function parse_startcase() { - local IFS=$'\n' - local lower="''${*,,}" - local parts=($(_parse_split ''${lower})) + # Parse string to start case. + # Usage: parse_startcase + function parse_startcase() { + local IFS=$'\n' + local lower="''${*,,}" + local parts=($(_parse_split ''${lower})) - for part in ''${parts[@]}; do - echo -n "''${part^}" - done + for part in ''${parts[@]}; do + echo -n "''${part^}" + done - echo - } + echo + } - # Parse string to pretty Json. - # Usage: parse_json - function parse_json() { - echo "''${*}" | jq - } + # Parse string to pretty Json. + # Usage: parse_json + function parse_json() { + echo "''${*}" | jq + } - # Split string by separators. - # Usage: _parse_split - function _parse_split() { - echo "''${*}" | sed -e "s/[A-Z]\+/\n&/g" -e "s/[0-9]\+/\n&\n/g" -e "s/[''${_PARSE_SPLIT_CHARS}]/&\n/g" | sed -e "/^$/d" - } + # Split string by separators. + # Usage: _parse_split + function _parse_split() { + echo "''${*}" | sed -e "s/[A-Z]\+/\n&/g" -e "s/[0-9]\+/\n&\n/g" -e "s/[''${_PARSE_SPLIT_CHARS}]/&\n/g" | sed -e "/^$/d" + } - # Get name parts. - # Usage: _get_parts - function _get_parts() { - _parse_split "''${*}" | sed -e "s/[''${_PARSE_SPLIT_CHARS}]//g" | sed -e "/^$/d" - } - ''; + # Get name parts. + # Usage: _get_parts + function _get_parts() { + _parse_split "''${*}" | sed -e "s/[''${_PARSE_SPLIT_CHARS}]//g" | sed -e "/^$/d" + } + ''; } diff --git a/home/program/bash/module/Permission.nix b/home/program/bash/module/Permission.nix index f861cc1..3b785c1 100644 --- a/home/program/bash/module/Permission.nix +++ b/home/program/bash/module/Permission.nix @@ -1,14 +1,13 @@ -{ ... }: -{ - text = '' - # Recursively change permissions to allow read sharing with group and others. - function perm_share() { - find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \; - } +{ ... }: { + text = '' + # Recursively change permissions to allow read sharing with group and others. + function perm_share() { + find . -type d -exec chmod 755 {} \;; find . -type f -exec chmod 644 {} \; + } - # Recursively change permissions to restrict access for group and others. - function perm() { - find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \; - } - ''; + # Recursively change permissions to restrict access for group and others. + function perm() { + find . -type d -exec chmod 700 {} \;; find . -type f -exec chmod 600 {} \; + } + ''; } diff --git a/home/program/bash/module/Ps.nix b/home/program/bash/module/Ps.nix index 0a9afe1..bc4fa8b 100644 --- a/home/program/bash/module/Ps.nix +++ b/home/program/bash/module/Ps.nix @@ -1,16 +1,15 @@ -{ ... }: -{ - text = '' - # Find process and filter. - # Usage: fps [PROCESS] - function fps() { - local process="''${1}" +{ ... }: { + text = '' + # Find process and filter. + # Usage: fps [PROCESS] + function fps() { + local process="''${1}" - if [[ "''${process}" = "" ]]; then - ps aux - else - ps aux | sed -n -e "1p" -e "/''${process}/Ip" | sed -e "/sed -n -e 1p -e/d" - fi - } - ''; + if [[ "''${process}" = "" ]]; then + ps aux + else + ps aux | sed -n -e "1p" -e "/''${process}/Ip" | sed -e "/sed -n -e 1p -e/d" + fi + } + ''; } diff --git a/home/program/bash/module/Ps1.nix b/home/program/bash/module/Ps1.nix index 39e7e2f..f72c4bc 100644 --- a/home/program/bash/module/Ps1.nix +++ b/home/program/bash/module/Ps1.nix @@ -1,159 +1,160 @@ -{ config, ... }: -let - accent = "${config.style.color.accent-r};${config.style.color.accent-g};${config.style.color.accent-b}"; - negative = "${config.style.color.negative-r};${config.style.color.negative-g};${config.style.color.negative-b}"; - neutral = "${config.style.color.neutral-r};${config.style.color.neutral-g};${config.style.color.neutral-b}"; - positive = "${config.style.color.positive-r};${config.style.color.positive-g};${config.style.color.positive-b}"; -in { - text = '' - export PROMPT_COMMAND=(__prompt_command "''${PROMPT_COMMAND[@]}") + config, + ... +}: let + accent = "${config.module.style.color.accent-r};${config.module.style.color.accent-g};${config.module.style.color.accent-b}"; + negative = "${config.module.style.color.negative-r};${config.module.style.color.negative-g};${config.module.style.color.negative-b}"; + neutral = "${config.module.style.color.neutral-r};${config.module.style.color.neutral-g};${config.module.style.color.neutral-b}"; + positive = "${config.module.style.color.positive-r};${config.module.style.color.positive-g};${config.module.style.color.positive-b}"; +in { + text = '' + export PROMPT_COMMAND=(__prompt_command "''${PROMPT_COMMAND[@]}") - function __prompt_color() { - local color="''${1}" - if [[ "''${color}" = "" ]]; then - printf "\[\x1b[0m\]" - else - printf "\[\x1b[38;2;''${color}m\]" - fi - } + function __prompt_color() { + local color="''${1}" + if [[ "''${color}" = "" ]]; then + printf "\[\x1b[0m\]" + else + printf "\[\x1b[38;2;''${color}m\]" + fi + } - # Custom terminal prompt format. - function __prompt_command() { - local last_status="''${?}" - local is_error=false - local is_root=false + # Custom terminal prompt format. + function __prompt_command() { + local last_status="''${?}" + local is_error=false + local is_root=false - if [[ ''${last_status} != 0 && ''${last_status} != 130 ]]; then - is_error=true - fi - if [[ "''${UID}" -eq 0 ]]; then - is_root=true - fi + if [[ ''${last_status} != 0 && ''${last_status} != 130 ]]; then + is_error=true + fi + if [[ "''${UID}" -eq 0 ]]; then + is_root=true + fi - # Add newline. - PS1="\n" + # Add newline. + PS1="\n" - # Set error red. - if ''${is_error}; then - PS1+="$(__prompt_color '${negative}')" - PS1+="[" - else - PS1+="$(__prompt_color)" - PS1+="[" - fi + # Set error red. + if ''${is_error}; then + PS1+="$(__prompt_color '${negative}')" + PS1+="[" + else + PS1+="$(__prompt_color)" + PS1+="[" + fi - # Add time. - # PS1+="$(__prompt_color '${accent}')" - # PS1+="$(date +%H:%M) " + # Add time. + # PS1+="$(__prompt_color '${accent}')" + # PS1+="$(date +%H:%M) " - # Set root red. - if ''${is_root}; then - PS1+="$(__prompt_color '${negative}')" - else - PS1+="$(__prompt_color '${neutral}')" - fi + # Set root red. + if ''${is_root}; then + PS1+="$(__prompt_color '${negative}')" + else + PS1+="$(__prompt_color '${neutral}')" + fi - # Add user, host and working dir. - PS1+="\u@\h " - PS1+="$(__prompt_color '${positive}')" - PS1+="\w" - # PS1+="\''${PWD}" + # Add user, host and working dir. + PS1+="\u@\h " + PS1+="$(__prompt_color '${positive}')" + PS1+="\w" + # PS1+="\''${PWD}" - # Add git branch if available. - local git_branch="$(_git_current_branch)" - if [[ "''${git_branch}" != "" ]]; then - PS1+=" $(__prompt_color '${accent}')@''${git_branch}" - fi + # Add git branch if available. + local git_branch="$(_git_current_branch)" + if [[ "''${git_branch}" != "" ]]; then + PS1+=" $(__prompt_color '${accent}')@''${git_branch}" + fi - # Set error red. - if ''${is_error}; then - PS1+="$(__prompt_color '${negative}')" - PS1+="] " - else - PS1+="$(__prompt_color)" - PS1+="] " - fi + # Set error red. + if ''${is_error}; then + PS1+="$(__prompt_color '${negative}')" + PS1+="] " + else + PS1+="$(__prompt_color)" + PS1+="] " + fi - # If error, show code. - if ''${is_error}; then - PS1+="$(__prompt_color '${negative}')(" - PS1+="''${last_status}" - local error_type="$(_ps1error ''${last_status})" - [[ "''${error_type}" != "" ]] && PS1+=" ''${error_type}" - PS1+=")$(__prompt_color) " - fi + # If error, show code. + if ''${is_error}; then + PS1+="$(__prompt_color '${negative}')(" + PS1+="''${last_status}" + local error_type="$(_ps1error ''${last_status})" + [[ "''${error_type}" != "" ]] && PS1+=" ''${error_type}" + PS1+=")$(__prompt_color) " + fi - # Command on new line. - PS1+="\n" + # Command on new line. + PS1+="\n" - # Show nix shell name or shell depth. - if [ -n "''${SHELL_NAME}" ]; then - PS1+="''${SHELL_NAME} " - fi + # Show nix shell name or shell depth. + if [ -n "''${SHELL_NAME}" ]; then + PS1+="''${SHELL_NAME} " + fi - # Show remote connections. - if [ -n "''${SSH_TTY}" ]; then - PS1+=">" - fi + # Show remote connections. + if [ -n "''${SSH_TTY}" ]; then + PS1+=">" + fi - PS1+="$(__prompt_color)" + PS1+="$(__prompt_color)" - # Set user tag. - if ''${is_root}; then - PS1+="# " - else - PS1+="$ " - fi + # Set user tag. + if ''${is_root}; then + PS1+="# " + else + PS1+="$ " + fi - # Reset color. - PS1+="\[\033[0m\]" - } + # Reset color. + PS1+="\[\033[0m\]" + } - # Convert error code into short description. - # Usage: _ps1error - function _ps1error() { - local type - case ''${1} in - 1) type="GENERAL" ;; - 2) type="MISUSE" ;; - 126) type="CANTEXEC" ;; - 127) type="CMDNF" ;; - 129) type="SIGHUP" ;; - 130) type="SIGINT" ;; - 131) type="SIGQUIT" ;; - 132) type="SIGILL" ;; - 133) type="SIGTRAP" ;; - 134) type="SIGABRT" ;; - 135) type="SIGBUS" ;; - 136) type="SIGFPE" ;; - 137) type="SIGKILL" ;; - 138) type="SIGUSR1" ;; - 139) type="SIGSEGV" ;; - 140) type="SIGUSR2" ;; - 141) type="SIGPIPE" ;; - 142) type="SIGALRM" ;; - 143) type="SIGTERM" ;; - 144) type="" ;; - 145) type="SIGCHLD" ;; - 146) type="SIGCONT" ;; - 147) type="SIGSTOP" ;; - 148) type="SIGTSTP" ;; - 149) type="SIGTTIN" ;; - 150) type="SIGTTOU" ;; - 151) type="SIGURG" ;; - 152) type="SIGXCPU" ;; - 153) type="SIGXFSZ" ;; - 154) type="SIGVTALRM" ;; - 155) type="SIGPROF" ;; - 156) type="SIGWINCH" ;; - 157) type="SIGIO" ;; - 158) type="SIGPWR" ;; - 159) type="SIGSYS" ;; - *) type="" ;; - esac + # Convert error code into short description. + # Usage: _ps1error + function _ps1error() { + local type + case ''${1} in + 1) type="GENERAL" ;; + 2) type="MISUSE" ;; + 126) type="CANTEXEC" ;; + 127) type="CMDNF" ;; + 129) type="SIGHUP" ;; + 130) type="SIGINT" ;; + 131) type="SIGQUIT" ;; + 132) type="SIGILL" ;; + 133) type="SIGTRAP" ;; + 134) type="SIGABRT" ;; + 135) type="SIGBUS" ;; + 136) type="SIGFPE" ;; + 137) type="SIGKILL" ;; + 138) type="SIGUSR1" ;; + 139) type="SIGSEGV" ;; + 140) type="SIGUSR2" ;; + 141) type="SIGPIPE" ;; + 142) type="SIGALRM" ;; + 143) type="SIGTERM" ;; + 144) type="" ;; + 145) type="SIGCHLD" ;; + 146) type="SIGCONT" ;; + 147) type="SIGSTOP" ;; + 148) type="SIGTSTP" ;; + 149) type="SIGTTIN" ;; + 150) type="SIGTTOU" ;; + 151) type="SIGURG" ;; + 152) type="SIGXCPU" ;; + 153) type="SIGXFSZ" ;; + 154) type="SIGVTALRM" ;; + 155) type="SIGPROF" ;; + 156) type="SIGWINCH" ;; + 157) type="SIGIO" ;; + 158) type="SIGPWR" ;; + 159) type="SIGSYS" ;; + *) type="" ;; + esac - echo -n "''${type}" - } - ''; + echo -n "''${type}" + } + ''; } diff --git a/home/program/bash/module/Random.nix b/home/program/bash/module/Random.nix index e28b80c..8346d43 100644 --- a/home/program/bash/module/Random.nix +++ b/home/program/bash/module/Random.nix @@ -1,15 +1,14 @@ -{ ... }: -{ - text = '' - # Picks a random file or directory. - function random_file() { - local IFS=$'\n' - local dirs=($(ls)) - local total=''${#dirs[@]} - ((total--)) - local index=$(shuf -i 0-''${total} -n 1) +{ ... }: { + text = '' + # Picks a random file or directory. + function random_file() { + local IFS=$'\n' + local dirs=($(ls)) + local total=''${#dirs[@]} + ((total--)) + local index=$(shuf -i 0-''${total} -n 1) - echo ''${dirs[$index]} - } - ''; + echo ''${dirs[$index]} + } + ''; } diff --git a/home/program/bash/module/Recursive.nix b/home/program/bash/module/Recursive.nix index 81aa69e..a53087c 100644 --- a/home/program/bash/module/Recursive.nix +++ b/home/program/bash/module/Recursive.nix @@ -1,85 +1,84 @@ -{ ... }: -{ - text = '' - # Run something recursively over all directories. - # Usage: recursive - function recursive() { - if [[ "''${*}" = "" ]]; then - help recursive - return 2 - fi +{ ... }: { + text = '' + # Run something recursively over all directories. + # Usage: recursive + function recursive() { + if [[ "''${*}" = "" ]]; then + help recursive + return 2 + fi - local IFS=$'\n' - local current="''${PWD}" - local dirs=$(find -type d) - local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ''${dirs}". - local count=0 - local failed=0 + local IFS=$'\n' + local current="''${PWD}" + local dirs=$(find -type d) + local total=$(find -type d | wc -l) # TODO: don't call find twice. won't work with "echo ''${dirs}". + local count=0 + local failed=0 - for dir in ''${dirs}; do - # increment counter. - ((count++)) + for dir in ''${dirs}; do + # increment counter. + ((count++)) - # cd into the next dir. - cd "''${current}" || failed=''${?} - cd "''${dir}" || failed=''${?} + # cd into the next dir. + cd "''${current}" || failed=''${?} + cd "''${dir}" || failed=''${?} - # echo status. - echo -e "''${color_bblue}[''${count}/''${total}] ''${dir}''${color_default}" + # echo status. + echo -e "''${color_bblue}[''${count}/''${total}] ''${dir}''${color_default}" - # run command. - ''${*} || failed=''${?} + # run command. + ''${*} || failed=''${?} - # Add newline if not the last one. - [[ "''${count}" = "''${total}" ]] || echo - done + # Add newline if not the last one. + [[ "''${count}" = "''${total}" ]] || echo + done - # return back on complete. - cd "''${current}" || failed=''${?} + # return back on complete. + cd "''${current}" || failed=''${?} - return ''${failed} - } + return ''${failed} + } - # Run something recursively over directories of 1 depth (excluding current dir). - # Usage: recursive1 - function recursive1() { - if [[ "''${*}" = "" ]]; then - help recursive1 - return 2 - fi + # Run something recursively over directories of 1 depth (excluding current dir). + # Usage: recursive1 + function recursive1() { + if [[ "''${*}" = "" ]]; then + help recursive1 + return 2 + fi - local IFS=$'\n' - local current="''${PWD}" - local dirs=$(find -mindepth 1 -maxdepth 1 -type d) - local total=$(find -mindepth 1 -maxdepth 1 -type d | wc -l) # TODO: don't call find twice. won't work with "echo ''${dirs}". - local count=0 - local failed=0 + local IFS=$'\n' + local current="''${PWD}" + local dirs=$(find -mindepth 1 -maxdepth 1 -type d) + local total=$(find -mindepth 1 -maxdepth 1 -type d | wc -l) # TODO: don't call find twice. won't work with "echo ''${dirs}". + local count=0 + local failed=0 - for dir in ''${dirs}; do - # increment counter. - ((count++)) + for dir in ''${dirs}; do + # increment counter. + ((count++)) - # cd into the next dir. - cd "''${current}" - cd "''${dir}" + # cd into the next dir. + cd "''${current}" + cd "''${dir}" - # echo status. - echo -e "''${color_bblue}[''${count}/''${total}] ''${dir}''${color_default}" + # echo status. + echo -e "''${color_bblue}[''${count}/''${total}] ''${dir}''${color_default}" - # run command. - ''${*} || failed=''${?} + # run command. + ''${*} || failed=''${?} - # Add newline if not the last one. - [[ "''${count}" = "''${total}" ]] || echo - done + # Add newline if not the last one. + [[ "''${count}" = "''${total}" ]] || echo + done - # return back on complete. - cd "''${current}" + # return back on complete. + cd "''${current}" - return ''${failed} - } + return ''${failed} + } - # autocomplete. - complete -F _autocomplete_nested recursive recursive1 - ''; + # autocomplete. + complete -F _autocomplete_nested recursive recursive1 + ''; } diff --git a/home/program/bash/module/Reload.nix b/home/program/bash/module/Reload.nix index 04555f5..9d435cc 100644 --- a/home/program/bash/module/Reload.nix +++ b/home/program/bash/module/Reload.nix @@ -1,9 +1,8 @@ -{ ... }: -{ - text = '' - function reload() { - source ~/.bashrc - } - trap reload USR1 - ''; +{ ... }: { + text = '' + function reload() { + source ~/.bashrc + } + trap reload USR1 + ''; } diff --git a/home/program/bash/module/Shopt.nix b/home/program/bash/module/Shopt.nix index 85d49c0..4760280 100644 --- a/home/program/bash/module/Shopt.nix +++ b/home/program/bash/module/Shopt.nix @@ -1,28 +1,27 @@ -{ ... }: -{ - text = '' - shopt -s dotglob - shopt -s globstar - shopt -s autocd - shopt -s extglob +{ ... }: { + text = '' + shopt -s dotglob + shopt -s globstar + shopt -s autocd + shopt -s extglob - # Enable vim mode. - bind 'set editing-mode vi' - bind 'set show-mode-in-prompt on' - bind 'set keyseq-timeout 0' + # Enable vim mode. + bind 'set editing-mode vi' + bind 'set show-mode-in-prompt on' + bind 'set keyseq-timeout 0' - # Set the mode string and cursor to indicate the vim mode - # For the number after `\e[`: - # 0: blinking block - # 1: blinking block (default) - # 2: steady block - # 3: blinking underline - # 4: steady underline - # 5: blinking bar (xterm) - # 6: steady bar (xterm) - bind 'set vi-ins-mode-string \1\e[6 q\2' - bind 'set vi-cmd-mode-string \1\e[2 q\2' + # Set the mode string and cursor to indicate the vim mode + # For the number after `\e[`: + # 0: blinking block + # 1: blinking block (default) + # 2: steady block + # 3: blinking underline + # 4: steady underline + # 5: blinking bar (xterm) + # 6: steady bar (xterm) + bind 'set vi-ins-mode-string \1\e[6 q\2' + bind 'set vi-cmd-mode-string \1\e[2 q\2' - exec {BASH_XTRACEFD}>/dev/null - ''; + exec {BASH_XTRACEFD}>/dev/null + ''; } diff --git a/home/program/bash/module/Su.nix b/home/program/bash/module/Su.nix index ee15da9..26670a8 100644 --- a/home/program/bash/module/Su.nix +++ b/home/program/bash/module/Su.nix @@ -1,35 +1,34 @@ -{ ... }: -{ - text = '' - # Su shortcut for lazy me. - # Root by default. - # Usage: s [USER] - function s() { - su - ''${1} - } - alias su="SHELL_NAME=su su" +{ ... }: { + text = '' + # Su shortcut for lazy me. + # Root by default. + # Usage: s [USER] + function s() { + su - ''${1} + } + alias su="SHELL_NAME=su su" - # Run something as root. Runs command as a current user if su is not available. - # Usage: sudo - function sudo() { - if command -v su &> /dev/null; then - su -c "$(echo ''${*} | tr '\n' ' ')" - else - ''${*} - fi - } + # Run something as root. Runs command as a current user if su is not available. + # Usage: sudo + function sudo() { + if command -v su &> /dev/null; then + su -c "$(echo ''${*} | tr '\n' ' ')" + else + ''${*} + fi + } - # Run something as current user. If fails, try to run with sudo. - # Usage: trysudo - function trysudo() { - ''${*} || sudo ''${*} - } + # Run something as current user. If fails, try to run with sudo. + # Usage: trysudo + function trysudo() { + ''${*} || sudo ''${*} + } - function _complete_s() { - _autocomplete_first $(_get_users) - } + function _complete_s() { + _autocomplete_first $(_get_users) + } - complete -F _complete_s s - complete -F _autocomplete_nested sudo trysudo - ''; + complete -F _complete_s s + complete -F _autocomplete_nested sudo trysudo + ''; } diff --git a/home/program/bash/module/Tmux.nix b/home/program/bash/module/Tmux.nix index de2d6b6..39aa94f 100644 --- a/home/program/bash/module/Tmux.nix +++ b/home/program/bash/module/Tmux.nix @@ -1,99 +1,98 @@ -{ ... }: -{ - text = '' - # Create/attach to named session. - # By default uses current dir name. - # Usage: ta [NAME] - function ta() { - local name="''${1}" +{ ... }: { + text = '' + # Create/attach to named session. + # By default uses current dir name. + # Usage: ta [NAME] + function ta() { + local name="''${1}" - # Set default name. - # [[ "''${name}" = "" ]] && name="main" - [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + # Set default name. + # [[ "''${name}" = "" ]] && name="main" + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") - # Create session. - tmux new-session -s "''${name}" -d &> /dev/null + # Create session. + tmux new-session -s "''${name}" -d &> /dev/null - # Attach to session. - if _is_tmux; then - tmux switch-client -t "''${name}" - else - tmux attach-session -t "''${name}" - fi - } + # Attach to session. + if _is_tmux; then + tmux switch-client -t "''${name}" + else + tmux attach-session -t "''${name}" + fi + } - # Detach from running session. - function td() { - tmux detach-client - } + # Detach from running session. + function td() { + tmux detach-client + } - # Detach all other tmux clients. - function tda() { - tmux detach-client -s $(tmux display-message -p '#S') - } + # Detach all other tmux clients. + function tda() { + tmux detach-client -s $(tmux display-message -p '#S') + } - # List running sessions. - function tl() { - tmux list-sessions - } + # List running sessions. + function tl() { + tmux list-sessions + } - # Assign name to session. Uses current dir name by default. - # Usage: tns [NAME] - function tns() { - local name="''${1}" + # Assign name to session. Uses current dir name by default. + # Usage: tns [NAME] + function tns() { + local name="''${1}" - [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") - tmux rename-session "''${name}" - } + tmux rename-session "''${name}" + } - # Assign name to window. Uses current dir name by default. - # Usage: tnw [NAME] - function tnw() { - local name="''${1}" + # Assign name to window. Uses current dir name by default. + # Usage: tnw [NAME] + function tnw() { + local name="''${1}" - [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") - tmux rename-window "''${name}" - } + tmux rename-window "''${name}" + } - # Kill specified session. - # By default uses current dir name. - # Usage: tk [NAME] - function tk() { - local name="''${1}" + # Kill specified session. + # By default uses current dir name. + # Usage: tk [NAME] + function tk() { + local name="''${1}" - [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") - tmux kill-session -t "''${name}" - } + tmux kill-session -t "''${name}" + } - # Kill all sessions. - function tka() { - local sessions=$(tmux list-sessions | sed -e 's/:.*//') + # Kill all sessions. + function tka() { + local sessions=$(tmux list-sessions | sed -e 's/:.*//') - for session in $sessions; do - tmux kill-session -t "$session" - done - } + for session in $sessions; do + tmux kill-session -t "$session" + done + } - # Autocomplete with running sessions once. - function _complete_tmux_session() { - _autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" - } + # Autocomplete with running sessions once. + function _complete_tmux_session() { + _autocomplete_first "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" + } - # Autocomplete with running sessions. - function _complete_tmux_sessions() { - _autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" - } + # Autocomplete with running sessions. + function _complete_tmux_sessions() { + _autocomplete "$(tmux list-sessions 2> /dev/null | sed -e 's/:.*//')" + } - # Autocomplete with current dir name and dirs inside this one. - function _complete_tmux_name() { - _autocomplete_first "''${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//') - } + # Autocomplete with current dir name and dirs inside this one. + function _complete_tmux_name() { + _autocomplete_first "''${PWD##*/}"$'\n'$(ls --classify | grep /$ | sed -e 's/\/$//') + } - complete -F _complete_tmux_session ta - complete -F _complete_tmux_sessions tk - complete -o nosort -F _complete_tmux_name tns tnw - ''; + complete -F _complete_tmux_session ta + complete -F _complete_tmux_sessions tk + complete -o nosort -F _complete_tmux_name tns tnw + ''; } diff --git a/home/program/bash/module/Transcode.nix b/home/program/bash/module/Transcode.nix index 58923ef..feb13fb 100644 --- a/home/program/bash/module/Transcode.nix +++ b/home/program/bash/module/Transcode.nix @@ -1,102 +1,101 @@ -{ ... }: -{ - text = '' - # Convert between different formats. - # By default tries to convert all files. - # Usage: transcode [FILES] - function transcode() { - local IFS=$'\n' - local format=''${1} - local targets=(''${@:2}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) +{ ... }: { + text = '' + # Convert between different formats. + # By default tries to convert all files. + # Usage: transcode [FILES] + function transcode() { + local IFS=$'\n' + local format=''${1} + local targets=(''${@:2}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - # Report no format. - if [[ "''${format}" = "" ]] || [[ "''${format}" =~ "." ]]; then - _error "No format specified." - help transcode - return 2 - fi + # Report no format. + if [[ "''${format}" = "" ]] || [[ "''${format}" =~ "." ]]; then + _error "No format specified." + help transcode + return 2 + fi - process() { - # Define context names and status. - local from="''${target##*.}" - local to="''${format}" - local output="''${target##*/}" - output="''${output%.*}.''${to}" + process() { + # Define context names and status. + local from="''${target##*.}" + local to="''${format}" + local output="''${target##*/}" + output="''${output%.*}.''${to}" - # Skip if file exists. - [[ -f "''${output}" ]] && { _iterate_skip "Already exists."; return 0; } + # Skip if file exists. + [[ -f "''${output}" ]] && { _iterate_skip "Already exists."; return 0; } - # Support multiple inputs. - [[ "''${to}" = "mp3" ]] && from="" - [[ "''${to}" = "flac" ]] && from="" - [[ "''${to}" = "mka" ]] && from="" - [[ "''${to}" = "mkv" ]] && from="" + # Support multiple inputs. + [[ "''${to}" = "mp3" ]] && from="" + [[ "''${to}" = "flac" ]] && from="" + [[ "''${to}" = "mka" ]] && from="" + [[ "''${to}" = "mkv" ]] && from="" - # Send convert. - case "''${from}-''${to}" in - "gz-xz"|"tgz-txz") - _transcode_gz-xz "''${target}" "''${output}" - ;; - "xz-gz"|"txz-tgz") - _transcode_xz-gz "''${target}" "''${output}" - ;; - "-mp3") - _transcode_mp3 "''${target}" "''${output}" - ;; - "-flac") - _transcode_flac "''${target}" "''${output}" - ;; - "-mka") - _transcode_mka "''${target}" "''${output}" - ;; - "-mkv") - _transcode_mkv "''${target}" "''${output}" - ;; - *) - _error "Conversion ''${target##*.}-''${to} not supported." - return 1 - ;; - esac - } + # Send convert. + case "''${from}-''${to}" in + "gz-xz"|"tgz-txz") + _transcode_gz-xz "''${target}" "''${output}" + ;; + "xz-gz"|"txz-tgz") + _transcode_xz-gz "''${target}" "''${output}" + ;; + "-mp3") + _transcode_mp3 "''${target}" "''${output}" + ;; + "-flac") + _transcode_flac "''${target}" "''${output}" + ;; + "-mka") + _transcode_mka "''${target}" "''${output}" + ;; + "-mkv") + _transcode_mkv "''${target}" "''${output}" + ;; + *) + _error "Conversion ''${target##*.}-''${to} not supported." + return 1 + ;; + esac + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - function _transcode_gz-xz() { - [[ -f "''${2}" ]] && return 1 - pv "''${1}" | gzip -d | xz -9e > "''${2}" - } + function _transcode_gz-xz() { + [[ -f "''${2}" ]] && return 1 + pv "''${1}" | gzip -d | xz -9e > "''${2}" + } - function _transcode_xz-gz() { - [[ -f "''${2}" ]] && return 1 - pv "''${1}" | xz -d | gzip -1 > "''${2}" - } + function _transcode_xz-gz() { + [[ -f "''${2}" ]] && return 1 + pv "''${1}" | xz -d | gzip -1 > "''${2}" + } - function _transcode_mp3() { - ffmpeg -n -i "''${1}" -c:a libmp3lame -b:a 320k -f mp3 "''${2}" - } + function _transcode_mp3() { + ffmpeg -n -i "''${1}" -c:a libmp3lame -b:a 320k -f mp3 "''${2}" + } - function _transcode_flac() { - ffmpeg -n -i "''${1}" -c:a flac -f flac "''${2}" - } + function _transcode_flac() { + ffmpeg -n -i "''${1}" -c:a flac -f flac "''${2}" + } - function _transcode_mka() { - local braudio=$(_ffprobe_ba "''${1}") - [[ ''${braudio} -gt 128 ]] && braudio=128 + function _transcode_mka() { + local braudio=$(_ffprobe_ba "''${1}") + [[ ''${braudio} -gt 128 ]] && braudio=128 - ffmpeg -n -i "''${1}" -ac 2 -c:a libopus -b:a ''${braudio}k -vn "''${2}" - } + ffmpeg -n -i "''${1}" -ac 2 -c:a libopus -b:a ''${braudio}k -vn "''${2}" + } - function _transcode_mkv() { - local keyint=$(_ffprobe_keyint "''${1}") - local braudio=$(_ffprobe_ba "''${1}") - local fps=$(_ffprobe_fps "''${1}") - [[ ''${braudio} -gt 128 ]] && braudio=128 - [[ ''${fps} -gt 30 ]] && fps=30 + function _transcode_mkv() { + local keyint=$(_ffprobe_keyint "''${1}") + local braudio=$(_ffprobe_ba "''${1}") + local fps=$(_ffprobe_fps "''${1}") + [[ ''${braudio} -gt 128 ]] && braudio=128 + [[ ''${fps} -gt 30 ]] && fps=30 - # ffmpeg -n -i "''${1}" -c:a libopus -b:a ''${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -preset 8 -pix_fmt yuv420p10le -g ''${keyint} -vf "scale=-2:min'(1080,ih)'" "''${2}" - ffmpeg -n -i "''${1}" -map 0 -map -v -map V -map -t -dn -c:s srt -ac 2 -c:a libopus -b:a ''${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "tune=0" -pix_fmt yuv420p10le -g ''${keyint} -vf "scale=-2:min'(1080,ih)' , fps=''${fps}" "''${2}" - } - ''; + # ffmpeg -n -i "''${1}" -c:a libopus -b:a ''${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "fast-decode=1:tune=0" -preset 8 -pix_fmt yuv420p10le -g ''${keyint} -vf "scale=-2:min'(1080,ih)'" "''${2}" + ffmpeg -n -i "''${1}" -map 0 -map -v -map V -map -t -dn -c:s srt -ac 2 -c:a libopus -b:a ''${braudio}k -c:v libsvtav1 -crf 30 -svtav1-params "tune=0" -pix_fmt yuv420p10le -g ''${keyint} -vf "scale=-2:min'(1080,ih)' , fps=''${fps}" "''${2}" + } + ''; } diff --git a/home/program/bash/module/Try.nix b/home/program/bash/module/Try.nix index eaea4f1..22a790a 100644 --- a/home/program/bash/module/Try.nix +++ b/home/program/bash/module/Try.nix @@ -1,26 +1,25 @@ -{ ... }: -{ - text = '' - # Retry command every 2 sec until it completes successfully. - # Usage: try - function try() { - if [[ "''${*}" = "" ]]; then - help try - return 2 - fi +{ ... }: { + text = '' + # Retry command every 2 sec until it completes successfully. + # Usage: try + function try() { + if [[ "''${*}" = "" ]]; then + help try + return 2 + fi - local result=-1 + local result=-1 - while [ "$result" != 0 ]; do - ''${*} - result=$? - if [ "$result" != 0 ]; then - sleep 2 - fi - done - } + while [ "$result" != 0 ]; do + ''${*} + result=$? + if [ "$result" != 0 ]; then + sleep 2 + fi + done + } - # autocomplete. - complete -F _autocomplete_nested try - ''; + # autocomplete. + complete -F _autocomplete_nested try + ''; } diff --git a/home/program/bash/module/Util.nix b/home/program/bash/module/Util.nix index cad702b..dfdf3b7 100644 --- a/home/program/bash/module/Util.nix +++ b/home/program/bash/module/Util.nix @@ -1,159 +1,158 @@ -{ ... }: -{ - text = '' - # Get the number of avaialble cores (threads). - function _core_count() { - cat /proc/cpuinfo | grep ^processor | wc -l - } +{ ... }: { + text = '' + # Get the number of avaialble cores (threads). + function _core_count() { + cat /proc/cpuinfo | grep ^processor | wc -l + } - # Get the number of available memory (in mebibytes). - function _mem_free() { - free -m | sed -n -e '2p' | awk '{print $7}' - } + # Get the number of available memory (in mebibytes). + function _mem_free() { + free -m | sed -n -e '2p' | awk '{print $7}' + } - # Function-wrapper to iterate with specified function with provided files. - # By default Iterates on all non-hidden files and directories. - # List of variables available to FUNCTION: target - current file, count - current item index, total - sum of targets, failed - count of previously failed items, skipped - count of skipped files, status - status line (not recommended to use). - # Usage: _iterate_targets [FILES] - function _iterate_targets() { - local IFS=$'\n' - local foo="''${1}" - local targets=("''${@:2}") - local total=''${#targets[@]} - local count=0 - local failed=0 - local skipped=0 - local code=0 + # Function-wrapper to iterate with specified function with provided files. + # By default Iterates on all non-hidden files and directories. + # List of variables available to FUNCTION: target - current file, count - current item index, total - sum of targets, failed - count of previously failed items, skipped - count of skipped files, status - status line (not recommended to use). + # Usage: _iterate_targets [FILES] + function _iterate_targets() { + local IFS=$'\n' + local foo="''${1}" + local targets=("''${@:2}") + local total=''${#targets[@]} + local count=0 + local failed=0 + local skipped=0 + local code=0 - # set dafult value to target all supported archives. - if [[ "''${targets}" = "" ]]; then - _error "No targets provided." - return 1 - fi + # set dafult value to target all supported archives. + if [[ "''${targets}" = "" ]]; then + _error "No targets provided." + return 1 + fi - # iterate each target. - for target in "''${targets[@]}"; do - # increment counter. - ((count++)) + # iterate each target. + for target in "''${targets[@]}"; do + # increment counter. + ((count++)) - # status info. - local status="[''${count}/''${total}] ''${target}" - _info "''${status}" + # status info. + local status="[''${count}/''${total}] ''${target}" + _info "''${status}" - # Call function. - ''${foo} "''${target}" + # Call function. + ''${foo} "''${target}" - # Show error. - if [[ ''${?} != 0 ]]; then - ((failed++)) - _error "''${status}: Failed." - fi + # Show error. + if [[ ''${?} != 0 ]]; then + ((failed++)) + _error "''${status}: Failed." + fi - # Add newline if not the last one. - [[ "''${count}" = "''${total}" ]] || _info - done + # Add newline if not the last one. + [[ "''${count}" = "''${total}" ]] || _info + done - # Show skipped. - if [[ ''${skipped} != 0 ]]; then - _warn - _warn "''${color_byellow}Skipped: ''${skipped}.''${color_default}" - fi + # Show skipped. + if [[ ''${skipped} != 0 ]]; then + _warn + _warn "''${color_byellow}Skipped: ''${skipped}.''${color_default}" + fi - # Show error. - if [[ ''${failed} != 0 ]]; then - [[ "''${skipped}" = 0 ]] && _error - _error "''${color_bred}Failed: ''${failed}.''${color_default}" - false - fi - } + # Show error. + if [[ ''${failed} != 0 ]]; then + [[ "''${skipped}" = 0 ]] && _error + _error "''${color_bred}Failed: ''${failed}.''${color_default}" + false + fi + } - # Skip current iteration. - # Usage: _iterate_skip [MESSAGE] - function _iterate_skip() { - ((skipped++)) + # Skip current iteration. + # Usage: _iterate_skip [MESSAGE] + function _iterate_skip() { + ((skipped++)) - [[ "''${*}" != "" ]] && _warn "''${color_byellow}''${*}''${color_default}" - } + [[ "''${*}" != "" ]] && _warn "''${color_byellow}''${*}''${color_default}" + } - # Report an error. - # Always returns code 1. - # Usage: _error - function _error() { - >&2 echo -e "''${color_bred}''${*}''${color_default}" - return 1 - } + # Report an error. + # Always returns code 1. + # Usage: _error + function _error() { + >&2 echo -e "''${color_bred}''${*}''${color_default}" + return 1 + } - # Report a warning. - # Usage: _warn - function _warn() { - >&2 echo -e "''${color_byellow}''${*}''${color_default}" - } + # Report a warning. + # Usage: _warn + function _warn() { + >&2 echo -e "''${color_byellow}''${*}''${color_default}" + } - # Report a debug. - # Usage: _debug - function _debug() { - >&2 echo -e "''${color_bwhite}''${*}''${color_default}" - } + # Report a debug. + # Usage: _debug + function _debug() { + >&2 echo -e "''${color_bwhite}''${*}''${color_default}" + } - # Report an info. - # Usage: _info - function _info() { - >&2 echo -e "''${color_bwhite}''${*}''${color_default}" - } + # Report an info. + # Usage: _info + function _info() { + >&2 echo -e "''${color_bwhite}''${*}''${color_default}" + } - # Check if array contains an element (strict). - # Usage: _contains - function _contains() { - local IFS=$'\n' - local target="''${1}" - local array="''${@:2}" + # Check if array contains an element (strict). + # Usage: _contains + function _contains() { + local IFS=$'\n' + local target="''${1}" + local array="''${@:2}" - if [[ "''${target}" = "" ]] || [[ "''${array}" = "" ]]; then - help _contains - return 2 - fi + if [[ "''${target}" = "" ]] || [[ "''${array}" = "" ]]; then + help _contains + return 2 + fi - for item in ''${array[@]}; do - [[ "''${item}" = "''${target}" ]] && return 0 - done + for item in ''${array[@]}; do + [[ "''${item}" = "''${target}" ]] && return 0 + done - return 1 - } + return 1 + } - # Find an index of an element in array. - # Usage: _index_of - function _index_of() { - local element="''${1}" - local array="''${@:2}" - local index=0 + # Find an index of an element in array. + # Usage: _index_of + function _index_of() { + local element="''${1}" + local array="''${@:2}" + local index=0 - for item in ''${array[@]}; do - [[ "''${item}" = "''${element}" ]] && break - ((index++)) - done + for item in ''${array[@]}; do + [[ "''${item}" = "''${element}" ]] && break + ((index++)) + done - echo "''${index}" - } + echo "''${index}" + } - # Check if inside Tmux. - function _is_tmux() { - [[ "''${TERM_PROGRAM}" = "tmux" ]] - } + # Check if inside Tmux. + function _is_tmux() { + [[ "''${TERM_PROGRAM}" = "tmux" ]] + } - # Check if root. - function _is_root() { - [[ "''${UID}" = 0 ]] - } + # Check if root. + function _is_root() { + [[ "''${UID}" = 0 ]] + } - # Ring a bell. - function _bell() { - echo -e '\a' - } + # Ring a bell. + function _bell() { + echo -e '\a' + } - # Get users. - function _get_users() { - local users=("voronind" "dasha") - echo ''${users[@]} - } - ''; + # Get users. + function _get_users() { + local users=("voronind" "dasha") + echo ''${users[@]} + } + ''; } diff --git a/home/program/bash/module/Vdl.nix b/home/program/bash/module/Vdl.nix index 980ab76..7853fcf 100644 --- a/home/program/bash/module/Vdl.nix +++ b/home/program/bash/module/Vdl.nix @@ -1,44 +1,43 @@ -{ ... }: -{ - text = '' - # Download video from URL. When no `[LINK]` specified, it tries to update previously downloaded link. - # Usage: vdl [LINK] - function vdl() { - # Check that ffmpeg and ffprobe are available. - if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then - _error "ffmpeg and ffprobe are required." - return 1 - fi +{ ... }: { + text = '' + # Download video from URL. When no `[LINK]` specified, it tries to update previously downloaded link. + # Usage: vdl [LINK] + function vdl() { + # Check that ffmpeg and ffprobe are available. + if [[ "$(ffmpeg -version)" = "" ]] || [[ "$(ffprobe -version)" = "" ]]; then + _error "ffmpeg and ffprobe are required." + return 1 + fi - local target="''${@}" # What to download/update. + local target="''${@}" # What to download/update. - # If no [LINK] provided, try to read from `Src.txt`. - [[ "''${target}" = "" ]] && target="$(cat Src.txt)" + # If no [LINK] provided, try to read from `Src.txt`. + [[ "''${target}" = "" ]] && target="$(cat Src.txt)" - # If could not get [LINK] eventually, show an error and exit. - if [[ "''${target}" = "" ]]; then - _error "Could not determine [LINK] to download." - help vdl - return 2 - fi + # If could not get [LINK] eventually, show an error and exit. + if [[ "''${target}" = "" ]]; then + _error "Could not determine [LINK] to download." + help vdl + return 2 + fi - # Save [LINK] for later use. - [[ -f "Src.txt" ]] || echo "''${target}" > Src.txt + # Save [LINK] for later use. + [[ -f "Src.txt" ]] || echo "''${target}" > Src.txt - # Download [LINK] content. - yt-dlp -S 'res:1080,codec:av1,codec:vp9,codec:h264' --download-archive Index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ''${target} # || _vdl_retry - } + # Download [LINK] content. + yt-dlp -S 'res:1080,codec:av1,codec:vp9,codec:h264' --download-archive Index.txt --embed-thumbnail --embed-subs --write-auto-subs --embed-metadata --merge-output-format mkv -cio '%(playlist_index)000006d_%(id)s.%(ext)s' ''${target} # || _vdl_retry + } - # Temporary fix for vk downloads. - # Usage: vdl_vk - function vdl_vk() { - vdl --format mp4 "''${@}" - } + # Temporary fix for vk downloads. + # Usage: vdl_vk + function vdl_vk() { + vdl --format mp4 "''${@}" + } - # Download all videos from file with links. - # Usage: vdl_file - function vdl_file() { - vdl -a "''${@}" - } - ''; + # Download all videos from file with links. + # Usage: vdl_file + function vdl_file() { + vdl -a "''${@}" + } + ''; } diff --git a/home/program/bash/module/Vi.nix b/home/program/bash/module/Vi.nix index 960b7ea..d813bfe 100644 --- a/home/program/bash/module/Vi.nix +++ b/home/program/bash/module/Vi.nix @@ -1,9 +1,8 @@ -{ ... }: -{ - text = '' - # Neovim shortcut. - function v() { - nvim -- "''${@}" - } - ''; +{ ... }: { + text = '' + # Neovim shortcut. + function v() { + nvim -- "''${@}" + } + ''; } diff --git a/home/program/bash/module/Watch.nix b/home/program/bash/module/Watch.nix index 6a951a0..167f990 100644 --- a/home/program/bash/module/Watch.nix +++ b/home/program/bash/module/Watch.nix @@ -1,29 +1,28 @@ -{ ... }: -{ - text = '' - # Watch command output with 2 seconds interval. - # Usage: w - function w() { - if [[ "''${*}" = "" ]]; then - help w - return 2 - fi +{ ... }: { + text = '' + # Watch command output with 2 seconds interval. + # Usage: w + function w() { + if [[ "''${*}" = "" ]]; then + help w + return 2 + fi - watch -n 2 "''${@}" - } + watch -n 2 "''${@}" + } - # Watch command output with minimal interval. - # Usage: ww - function ww() { - if [[ "''${*}" = "" ]]; then - help ww - return 2 - fi + # Watch command output with minimal interval. + # Usage: ww + function ww() { + if [[ "''${*}" = "" ]]; then + help ww + return 2 + fi - watch -n 0 "''${@}" - } + watch -n 0 "''${@}" + } - # Autocomplete. - complete -F _autocomplete_nested w ww - ''; + # Autocomplete. + complete -F _autocomplete_nested w ww + ''; } diff --git a/home/program/bash/module/Zapret.nix b/home/program/bash/module/Zapret.nix index 5b3fd73..0ca5b10 100644 --- a/home/program/bash/module/Zapret.nix +++ b/home/program/bash/module/Zapret.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - text = '' - # FRKN. - # SOURCE: https://github.com/bol-van/zapret - function zapret() { - iptables -t mangle -I POSTROUTING -p tcp -m multiport --dports 80,443 -m connbytes --connbytes-dir=original --connbytes-mode=packets --connbytes 1:6 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 201 --queue-bypass - nfqws --pidfile=/run/nfqws.pid --qnum=201 ''${@} - } - ''; +{ ... }: { + text = '' + # FRKN. + # SOURCE: https://github.com/bol-van/zapret + function zapret() { + iptables -t mangle -I POSTROUTING -p tcp -m multiport --dports 80,443 -m connbytes --connbytes-dir=original --connbytes-mode=packets --connbytes 1:6 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num 201 --queue-bypass + nfqws --pidfile=/run/nfqws.pid --qnum=201 ''${@} + } + ''; } diff --git a/home/program/chromium/default.nix b/home/program/chromium/default.nix index 9252ba2..2939541 100644 --- a/home/program/chromium/default.nix +++ b/home/program/chromium/default.nix @@ -1,79 +1,68 @@ -{ pkgs, lib, ... }: -let - package = pkgs.ungoogled-chromium; - browserVersion = lib.versions.major package.version; - extensions = - let - fetchFromStore = - { - id, - sha256, - version, - }: - { - inherit id version; - crxPath = pkgs.fetchurl { - inherit sha256; - url = "https://clients2.google.com/service/update2/crx?response=redirect&acceptformat=crx2,crx3&prodversion=${browserVersion}&x=id%3D${id}%26installsource%3Dondemand%26uc"; - name = "${id}.crx"; - }; - }; - fetchFromUrl = - { - id, - url, - sha256, - version, - }: - { - inherit id version; - crxPath = pkgs.fetchurl { - inherit sha256 url; - name = "${id}.crx"; - }; - }; - in - [ - (fetchFromStore { - # uBlock Origin dev. - id = "cgbcahbpdhpcegmbfconppldiemgcoii"; - sha256 = "sha256-sTE96l7/B3n4rJHYC0p4hCVmXUMYj/6O6+596DFIK58="; - version = "1.60.1.16"; - }) - (fetchFromStore { - # Dark reader. - id = "eimadpbcbfnmbkopoojfekhnkhdbieeh"; - sha256 = "sha256-98sGCo2dG+XYMzBeLR+10Ic5DLjDXhSh1DzatLOCyQQ="; - version = "4.9.95"; - }) - (fetchFromStore { - # Foxy Proxy. - id = "gcknhkkoolaabfmlnjonogaaifnjlfnp"; - sha256 = "sha256-Zm7x/467CaGcEN+cYwf8XowpaZRJQIzIEY/F6NhJ3pA="; - version = "8.9"; - }) - (fetchFromStore { - # Vimium. - id = "dbepggeogbaibhgnhhndojpepiihcmeb"; - sha256 = "sha256-DaEM1NyMX8RMBvWoIVOhmfY/ae66HCNfRFnwAuLUHVU="; - version = "2.1.2"; - }) - # (fetchFromUrl rec { - # # Ext updater. - # id = "ocaahdebbfolfmndjeplogmgcagdmblk"; - # url = "https://github.com/NeverDecaf/chromium-web-store/releases/download/v${version}/Chromium.Web.Store.crx"; - # sha256 = "sha256-gKAcrvnxLh9gMraTFX4zRsUua4OI+lak51gpII29d8g="; - # version = "1.5.4.3"; - # }) - ]; -in { - enable = true; - inherit extensions package; - dictionaries = with pkgs.hunspellDictsChromium; [ en_US ]; - commandLineArgs = [ - # Disable animations. - "--wm-window-animations-disabled" - "--animation-duration-scale=0" - ]; + pkgs, + lib, + ... +}: let + package = pkgs.ungoogled-chromium; + browserVersion = lib.versions.major package.version; + extensions = let + fetchFromStore = { id, sha256, version, }: { + inherit id version; + crxPath = pkgs.fetchurl { + inherit sha256; + name = "${id}.crx"; + url = "https://clients2.google.com/service/update2/crx?response=redirect&acceptformat=crx2,crx3&prodversion=${browserVersion}&x=id%3D${id}%26installsource%3Dondemand%26uc"; + }; + }; + fetchFromUrl = { id, url, sha256, version, }: { + inherit id version; + crxPath = pkgs.fetchurl { + inherit sha256 url; + name = "${id}.crx"; + }; + }; + in [ + (fetchFromStore { + # uBlock Origin dev. + id = "cgbcahbpdhpcegmbfconppldiemgcoii"; + sha256 = "sha256-sTE96l7/B3n4rJHYC0p4hCVmXUMYj/6O6+596DFIK58="; + version = "1.60.1.16"; + }) + (fetchFromStore { + # Dark reader. + id = "eimadpbcbfnmbkopoojfekhnkhdbieeh"; + sha256 = "sha256-98sGCo2dG+XYMzBeLR+10Ic5DLjDXhSh1DzatLOCyQQ="; + version = "4.9.95"; + }) + (fetchFromStore { + # Foxy Proxy. + id = "gcknhkkoolaabfmlnjonogaaifnjlfnp"; + sha256 = "sha256-Zm7x/467CaGcEN+cYwf8XowpaZRJQIzIEY/F6NhJ3pA="; + version = "8.9"; + }) + (fetchFromStore { + # Vimium. + id = "dbepggeogbaibhgnhhndojpepiihcmeb"; + sha256 = "sha256-DaEM1NyMX8RMBvWoIVOhmfY/ae66HCNfRFnwAuLUHVU="; + version = "2.1.2"; + }) + # (fetchFromUrl rec { + # # Ext updater. + # id = "ocaahdebbfolfmndjeplogmgcagdmblk"; + # url = "https://github.com/NeverDecaf/chromium-web-store/releases/download/v${version}/Chromium.Web.Store.crx"; + # sha256 = "sha256-gKAcrvnxLh9gMraTFX4zRsUua4OI+lak51gpII29d8g="; + # version = "1.5.4.3"; + # }) + ]; +in { + inherit extensions package; + enable = true; + dictionaries = with pkgs.hunspellDictsChromium; [ + en_US + ]; + commandLineArgs = [ + # Disable animations. + "--wm-window-animations-disabled" + "--animation-duration-scale=0" + ]; } diff --git a/home/program/default.nix b/home/program/default.nix index 713aa25..bb185cf 100644 --- a/home/program/default.nix +++ b/home/program/default.nix @@ -1,34 +1,32 @@ { - secret, - lib, - config, - ... -}@args: -let - bash = import ./bash args; -in -{ - core = { - home-manager.enable = true; + config, + lib, + secret, + ... +} @args: let + bash = import ./bash args; +in { + core = { + home-manager.enable = true; - gpg = { - enable = true; - inherit (secret.crypto) publicKeys; - mutableKeys = true; - mutableTrust = true; - settings = { - keyserver = "hkps://keys.openpgp.org"; - }; - }; + gpg = { + inherit (secret.crypto) publicKeys; + enable = true; + mutableKeys = true; + mutableTrust = true; + settings = { + keyserver = "hkps://keys.openpgp.org"; + }; + }; - bash = { - enable = true; - initExtra = bash.bashrc; - }; - }; + bash = { + enable = true; + initExtra = bash.bashrc; + }; + }; - desktop = { - chromium = import ./chromium args; - firefox = import ./firefox args; - }; + desktop = { + chromium = import ./chromium args; + firefox = import ./firefox args; + }; } diff --git a/home/program/firefox/default.nix b/home/program/firefox/default.nix index 68ab9d3..d7daebc 100644 --- a/home/program/firefox/default.nix +++ b/home/program/firefox/default.nix @@ -1,416 +1,413 @@ { - pkgs, - config, - __findFile, - ... -}: -let - bookmarks = [ - (mkBookmark "Dashboard" "https://home.voronind.com") - (mkBookmark "Watch" "https://watch.voronind.com") - (mkBookmark "Telegram" "https://web.telegram.org/a") - (mkBookmark "WorkChat" "https://fsmm.fsight.ru/fmp") - (mkBookmark "Mail" "https://mail.voronind.com") - (mkBookmark "WorkMail" "https://mail.fsight.ru") - (mkBookmark "Git" "https://git.voronind.com") - (mkBookmark "WorkGit" "https://git.fmp.fsight.world") - (mkBookmark "WorkBoard" "https://support.fsight.ru") - (mkBookmark "Hass" "https://iot.voronind.com") - (mkBookmark "Cloud" "https://cloud.voronind.com") - ]; + __findFile, + config, + pkgs, + ... +}: let + bookmarks = [ + (mkBookmark "Dashboard" "https://home.voronind.com") + (mkBookmark "Watch" "https://watch.voronind.com") + (mkBookmark "Telegram" "https://web.telegram.org/a") + (mkBookmark "WorkChat" "https://fsmm.fsight.ru/fmp") + (mkBookmark "Mail" "https://mail.voronind.com") + (mkBookmark "WorkMail" "https://mail.fsight.ru") + (mkBookmark "Git" "https://git.voronind.com") + (mkBookmark "WorkGit" "https://git.fmp.fsight.world") + (mkBookmark "WorkBoard" "https://support.fsight.ru") + (mkBookmark "Hass" "https://iot.voronind.com") + (mkBookmark "Cloud" "https://cloud.voronind.com") + ]; - searchEngines = [ - (mkSearchEngine "4pda" "4pda" "https://4pda.to/forum/index.php?act=search&forums[]=all&source=all&query={searchTerms}") - (mkSearchEngine "aw" "Arch Wiki" "https://wiki.archlinux.org/index.php?search={searchTerms}") - (mkSearchEngine "gh" "GitHub" "https://github.com/search?q={searchTerms}") - (mkSearchEngine "ghc" "GitHub Code" "https://github.com/search?q={searchTerms}&type=code") - (mkSearchEngine "hm" "Home Manager" "https://home-manager-options.extranix.com/?query={searchTerms}") - (mkSearchEngine "no" "NixOS Options" "https://search.nixos.org/options?query={searchTerms}") - (mkSearchEngine "np" "NixOS Packages" "https://search.nixos.org/packages?query={searchTerms}") - (mkSearchEngine "re" "Reddit" "https://www.reddit.com/search/?q={searchTerms}") - (mkSearchEngine "rt" "RuTracker" "https://rutracker.org/forum/tracker.php?nm={searchTerms}") - (mkSearchEngine "s" "SearX" "https://search.voronind.com/search?q={searchTerms}") - (mkSearchEngine "so" "Stack Overflow" "https://stackoverflow.com/search?tab=votes&q={searchTerms}") - (mkSearchEngine "st" "Steam" "https://store.steampowered.com/search/?term={searchTerms}") - (mkSearchEngine "yt" "YouTube" "https://yt.voronind.com/search?q={searchTerms}") - ]; + searchEngines = [ + (mkSearchEngine "4pda" "4pda" "https://4pda.to/forum/index.php?act=search&forums[]=all&source=all&query={searchTerms}") + (mkSearchEngine "aw" "Arch Wiki" "https://wiki.archlinux.org/index.php?search={searchTerms}") + (mkSearchEngine "gh" "GitHub" "https://github.com/search?q={searchTerms}") + (mkSearchEngine "ghc" "GitHub Code" "https://github.com/search?q={searchTerms}&type=code") + (mkSearchEngine "hm" "Home Manager" "https://home-manager-options.extranix.com/?query={searchTerms}") + (mkSearchEngine "no" "NixOS Options" "https://search.nixos.org/options?query={searchTerms}") + (mkSearchEngine "np" "NixOS Packages" "https://search.nixos.org/packages?query={searchTerms}") + (mkSearchEngine "re" "Reddit" "https://www.reddit.com/search/?q={searchTerms}") + (mkSearchEngine "rt" "RuTracker" "https://rutracker.org/forum/tracker.php?nm={searchTerms}") + (mkSearchEngine "s" "SearX" "https://search.voronind.com/search?q={searchTerms}") + (mkSearchEngine "so" "Stack Overflow" "https://stackoverflow.com/search?tab=votes&q={searchTerms}") + (mkSearchEngine "st" "Steam" "https://store.steampowered.com/search/?term={searchTerms}") + (mkSearchEngine "yt" "YouTube" "https://yt.voronind.com/search?q={searchTerms}") + ]; - extensions = [ - # TODO: Use this after https://github.com/darkreader/darkreader/pull/12920 gets merged. - # (mkExtension "addon@darkreader.org" "https://addons.mozilla.org/firefox/downloads/latest/darkreader/latest.xpi") - (mkExtension "addon@darkreader.org" "file://${ - pkgs.callPackage { } - }/latest.xpi") - (mkExtension "cliget@zaidabdulla.com" "https://addons.mozilla.org/firefox/downloads/latest/cliget/latest.xpi") - (mkExtension "foxyproxy@eric.h.jung" "https://addons.mozilla.org/firefox/downloads/latest/foxyproxy-standard/latest.xpi") - (mkExtension "uBlock0@raymondhill.net" "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi") - (mkExtension "{446900e4-71c2-419f-a6a7-df9c091e268b}" "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi") - (mkExtension "{a6c4a591-f1b2-4f03-b3ff-767e5bedf4e7}" "https://addons.mozilla.org/firefox/downloads/latest/user-agent-string-switcher/latest.xpi") - (mkExtension "{d7742d87-e61d-4b78-b8a1-b469842139fa}" "https://addons.mozilla.org/firefox/downloads/latest/vimium-ff/latest.xpi") - (mkExtension "{e7625f06-e252-479d-ac7a-db68aeaff2cb}" "https://addons.mozilla.org/firefox/downloads/latest/togglefonts/latest.xpi") - # NOTE: This extension is helpful to find the required parameters for this config. - # Or find them yourself inside the `about:support`. - # (mkExtension "queryamoid@kaply.com" "https://github.com/mkaply/queryamoid/releases/download/v0.1/query_amo_addon_id-0.1-fx.xpi") - ]; + extensions = [ + # TODO: Use this after https://github.com/darkreader/darkreader/pull/12920 gets merged. + # (mkExtension "addon@darkreader.org" "https://addons.mozilla.org/firefox/downloads/latest/darkreader/latest.xpi") + (mkExtension "addon@darkreader.org" "file://${pkgs.callPackage { }}/latest.xpi") + (mkExtension "cliget@zaidabdulla.com" "https://addons.mozilla.org/firefox/downloads/latest/cliget/latest.xpi") + (mkExtension "foxyproxy@eric.h.jung" "https://addons.mozilla.org/firefox/downloads/latest/foxyproxy-standard/latest.xpi") + (mkExtension "uBlock0@raymondhill.net" "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi") + (mkExtension "{446900e4-71c2-419f-a6a7-df9c091e268b}" "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi") + (mkExtension "{a6c4a591-f1b2-4f03-b3ff-767e5bedf4e7}" "https://addons.mozilla.org/firefox/downloads/latest/user-agent-string-switcher/latest.xpi") + (mkExtension "{d7742d87-e61d-4b78-b8a1-b469842139fa}" "https://addons.mozilla.org/firefox/downloads/latest/vimium-ff/latest.xpi") + (mkExtension "{e7625f06-e252-479d-ac7a-db68aeaff2cb}" "https://addons.mozilla.org/firefox/downloads/latest/togglefonts/latest.xpi") + # NOTE: This extension is helpful to find the required parameters for this config. + # Or find them yourself inside the `about:support`. + # (mkExtension "queryamoid@kaply.com" "https://github.com/mkaply/queryamoid/releases/download/v0.1/query_amo_addon_id-0.1-fx.xpi") + ]; - prefs = [ - # WARN: Remove when Dark Reader policies gets merged. - (mkLockedPref "xpinstall.signatures.required" false) + prefs = [ + # WARN: Remove when Dark Reader policies gets merged. + (mkLockedPref "xpinstall.signatures.required" false) - # Bookmarks. - (mkLockedPref "browser.microsummary.enabled" true) - (mkLockedPref "browser.places.importBookmarksHTML" true) - (mkLockedPref "browser.toolbars.bookmarks.visibility" "never") + # Bookmarks. + (mkLockedPref "browser.microsummary.enabled" true) + (mkLockedPref "browser.places.importBookmarksHTML" true) + (mkLockedPref "browser.toolbars.bookmarks.visibility" "never") - # Fonts. - (mkUserPref "browser.display.use_document_fonts" 0) - (mkLockedPref "font.minimum-size.x-cyrillic" (toString config.style.font.size.application)) - (mkLockedPref "font.minimum-size.x-unicode" (toString config.style.font.size.application)) - (mkLockedPref "font.minimum-size.x-western" (toString config.style.font.size.application)) - (mkLockedPref "font.name.monospace.x-cyrillic" config.style.font.monospace.name) - (mkLockedPref "font.name.monospace.x-unicode" config.style.font.monospace.name) - (mkLockedPref "font.name.monospace.x-western" config.style.font.monospace.name) - (mkLockedPref "font.name.sans-serif.x-cyrillic" config.style.font.sansSerif.name) - (mkLockedPref "font.name.sans-serif.x-unicode" config.style.font.sansSerif.name) - (mkLockedPref "font.name.sans-serif.x-western" config.style.font.sansSerif.name) - (mkLockedPref "font.name.serif.x-cyrillic" config.style.font.serif.name) - (mkLockedPref "font.name.serif.x-unicode" config.style.font.serif.name) - (mkLockedPref "font.name.serif.x-western" config.style.font.serif.name) + # Fonts. + (mkUserPref "browser.display.use_document_fonts" 0) + (mkLockedPref "font.minimum-size.x-cyrillic" (toString config.module.style.font.size.application)) + (mkLockedPref "font.minimum-size.x-unicode" (toString config.module.style.font.size.application)) + (mkLockedPref "font.minimum-size.x-western" (toString config.module.style.font.size.application)) + (mkLockedPref "font.name.monospace.x-cyrillic" config.module.style.font.monospace.name) + (mkLockedPref "font.name.monospace.x-unicode" config.module.style.font.monospace.name) + (mkLockedPref "font.name.monospace.x-western" config.module.style.font.monospace.name) + (mkLockedPref "font.name.sans-serif.x-cyrillic" config.module.style.font.sansSerif.name) + (mkLockedPref "font.name.sans-serif.x-unicode" config.module.style.font.sansSerif.name) + (mkLockedPref "font.name.sans-serif.x-western" config.module.style.font.sansSerif.name) + (mkLockedPref "font.name.serif.x-cyrillic" config.module.style.font.serif.name) + (mkLockedPref "font.name.serif.x-unicode" config.module.style.font.serif.name) + (mkLockedPref "font.name.serif.x-western" config.module.style.font.serif.name) - # Animations. - (mkLockedPref "browser.fullscreen.animateUp" 0) - (mkLockedPref "browser.fullscreen.autohide" true) + # Animations. + (mkLockedPref "browser.fullscreen.animateUp" 0) + (mkLockedPref "browser.fullscreen.autohide" true) - # Homepage. - (mkLockedPref "browser.newtabpage.enabled" false) - (mkLockedPref "browser.startup.homepage" "https://home.voronind.com/") - (mkLockedPref "browser.startup.page" 3) + # Homepage. + (mkLockedPref "browser.newtabpage.enabled" false) + (mkLockedPref "browser.startup.homepage" "https://home.voronind.com/") + (mkLockedPref "browser.startup.page" 3) - # Passwords. - (mkLockedPref "signon.prefillForms" false) - (mkLockedPref "signon.rememberSignons" false) + # Passwords. + (mkLockedPref "signon.prefillForms" false) + (mkLockedPref "signon.rememberSignons" false) - # Formats. - (mkLockedPref "image.jxl.enabled" true) + # Formats. + (mkLockedPref "image.jxl.enabled" true) - # User agent. - # (mkLockedPref "general.useragent.override" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36") + # User agent. + # (mkLockedPref "general.useragent.override" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/94.0.4606.61 Safari/537.36") - # Disable HTTP3. - (mkLockedPref "network.http.http3.enable" false) + # Disable HTTP3. + (mkLockedPref "network.http.http3.enable" false) - # Disable built-in DoH. - (mkLockedPref "doh-rollout.disable-heuristics" true) - (mkLockedPref "network.trr.mode" 5) + # Disable built-in DoH. + (mkLockedPref "doh-rollout.disable-heuristics" true) + (mkLockedPref "network.trr.mode" 5) - # HTTPS only mode. - (mkLockedPref "dom.security.https_only_mode" true) - (mkLockedPref "dom.security.https_only_mode_ever_enabled" true) + # HTTPS only mode. + (mkLockedPref "dom.security.https_only_mode" true) + (mkLockedPref "dom.security.https_only_mode_ever_enabled" true) - # Style. - (mkLockedPref "toolkit.legacyUserProfileCustomizations.stylesheets" true) + # Style. + (mkLockedPref "toolkit.legacyUserProfileCustomizations.stylesheets" true) - # Disable auto gain for the mic. - # (mkLockedPref "media.getusermedia.audio.processing.aec" 0) - # (mkLockedPref "media.getusermedia.audio.processing.aec.enabled" false) - # (mkLockedPref "media.getusermedia.audio.processing.agc" 0) - # (mkLockedPref "media.getusermedia.audio.processing.agc.enabled" false) - # (mkLockedPref "media.getusermedia.audio.processing.agc2.forced" false - # (mkLockedPref "media.getusermedia.audio.processing.hpf.enabled" false) - # (mkLockedPref "media.getusermedia.audio.processing.noise" 0) - # (mkLockedPref "media.getusermedia.audio.processing.noise.enabled" false) - # (mkLockedPref "media.getusermedia.audio.processing.platform.enabled" false) - # (mkLockedPref "media.getusermedia.audio.processing.transient.enabled" false) - ]; + # Disable auto gain for the mic. + # (mkLockedPref "media.getusermedia.audio.processing.aec" 0) + # (mkLockedPref "media.getusermedia.audio.processing.aec.enabled" false) + # (mkLockedPref "media.getusermedia.audio.processing.agc" 0) + # (mkLockedPref "media.getusermedia.audio.processing.agc.enabled" false) + # (mkLockedPref "media.getusermedia.audio.processing.agc2.forced" false + # (mkLockedPref "media.getusermedia.audio.processing.hpf.enabled" false) + # (mkLockedPref "media.getusermedia.audio.processing.noise" 0) + # (mkLockedPref "media.getusermedia.audio.processing.noise.enabled" false) + # (mkLockedPref "media.getusermedia.audio.processing.platform.enabled" false) + # (mkLockedPref "media.getusermedia.audio.processing.transient.enabled" false) + ]; - userChrome = '' - * { - font-family: "${config.style.font.serif.name}" !important; - font-size: ${toString config.style.font.size.application}pt !important; - } - ''; + userChrome = '' + * { + font-family: "${config.module.style.font.serif.name}" !important; + font-size: ${toString config.module.style.font.size.application}pt !important; + } + ''; - userContent = '' - @-moz-document url(about:home), url(about:newtab), url(about:privatebrowsing), url(about:blank) { - .click-target-container *, .top-sites-list * { - color: #fff !important ; - text-shadow: 2px 2px 2px #222 !important ; - } - body::before { - content: "" ; - z-index: -1 ; - position: fixed ; - top: 0 ; - left: 0 ; - background: #f9a no-repeat url("${config.module.wallpaper.path}?raw=true") center ; - background-color: #222; - background-size: cover ; - /* filter: blur(4px) ; */ - width: 100vw ; - height: 100vh ; - } - /* .logo { background-image: url("{repo}/logo.png?raw=true") !important; } */ - /* .logo { background-image: none !important; } */ - } - ''; + userContent = '' + @-moz-document url(about:home), url(about:newtab), url(about:privatebrowsing), url(about:blank) { + .click-target-container *, .top-sites-list * { + color: #fff !important ; + text-shadow: 2px 2px 2px #222 !important ; + } + body::before { + content: "" ; + z-index: -1 ; + position: fixed ; + top: 0 ; + left: 0 ; + background: #f9a no-repeat url("${config.module.wallpaper.path}?raw=true") center ; + background-color: #222; + background-size: cover ; + /* filter: blur(4px) ; */ + width: 100vw ; + height: 100vh ; + } + /* .logo { background-image: url("{repo}/logo.png?raw=true") !important; } */ + /* .logo { background-image: none !important; } */ + } + ''; - mkExtension = id: install_url: { - ${id} = { - inherit install_url; - installation_mode = "force_installed"; - }; - }; + mkExtension = id: install_url: { + ${id} = { + inherit install_url; + installation_mode = "force_installed"; + }; + }; - mkBookmark = name: url: { inherit name url; }; + mkBookmark = name: url: { inherit name url; }; - mkSearchEngine = Alias: Description: URLTemplate: { - inherit Alias Description URLTemplate; - Method = "GET"; - Name = Description; - }; + mkSearchEngine = Alias: Description: URLTemplate: { + inherit Alias Description URLTemplate; + Method = "GET"; + Name = Description; + }; - mkPref = Name: Value: Status: { - ${Name} = { - inherit Value Status; - }; - }; - mkLockedPref = Name: Value: mkPref Name Value "locked"; - mkUserPref = Name: Value: mkPref Name Value "user"; + mkPref = Name: Value: Status: { + ${Name} = { + inherit Value Status; + }; + }; + mkLockedPref = Name: Value: mkPref Name Value "locked"; + mkUserPref = Name: Value: mkPref Name Value "user"; in -{ - enable = true; - package = pkgs.firefox-esr; - # languagePacks = [ "en-US" "ru" ]; - profiles.default = { - inherit userChrome userContent; - }; - # REF: https://mozilla.github.io/policy-templates/ - policies = { - AppAutoUpdate = false; - BackgroundAppUpdate = false; - DisableBuiltinPDFViewer = true; - DisableFirefoxAccounts = true; - DisableFirefoxStudies = true; - DisableFormHistory = true; - DisableMasterPasswordCreation = true; - DisablePasswordReveal = true; - DisablePocket = true; - DisableProfileImport = true; - DisableSetDesktopBackground = true; - DisableTelemetry = true; - DontCheckDefaultBrowser = true; - ExtensionUpdate = true; - ManagedBookmarks = [ { toplevel_name = "Pin"; } ] ++ bookmarks; - NoDefaultBookmarks = true; - OfferToSaveLogins = false; - PasswordManagerEnabled = false; - Preferences = builtins.foldl' (acc: pref: acc // pref) { } prefs; - PromptForDownloadLocation = false; - SearchSuggestEnabled = false; - ShowHomeButton = false; - StartDownloadsInTempDirectory = false; - UseSystemPrintDialog = true; - EnableTrackingProtection = { - Value = true; - Locked = false; - Cryptomining = true; - Fingerprinting = true; - EmailTracking = true; - Exceptions = [ "https://example.com" ]; - }; - EncryptedMediaExtensions = { - Enabled = true; - Locked = true; - }; - ExtensionSettings = { - # Block extension installation outside of this config. - "*" = { - install_sources = [ "*" ]; - installation_mode = "blocked"; - }; - } // builtins.foldl' (acc: ext: acc // ext) { } extensions; - "3rdparty".Extensions = { - "uBlock0@raymondhill.net".adminSettings = { - userSettings = { - uiTheme = "dark"; - cloudStorageEnabled = false; - }; - # NOTE: Check in `Support` -> `Troubleshooting Information` tab. - selectedFilterLists = [ - "user-filters" - "ublock-badware" - "ublock-privacy" - "ublock-quick-fixes" - "ublock-filters" - "easyprivacy" - "ublock-unbreak" - "urlhaus-1" - "easylist" - "plowe-0" - "adguard-cookies" - "fanboy-cookiemonster" - "ublock-cookies-easylist" - "adguard-other-annoyances" - "ublock-cookies-adguard" - "adguard-widgets" - "fanboy-social" - "ublock-annoyances" - "adguard-social" - "fanboy-thirdparty_social" - "easylist-chat" - "easylist-newsletters" - "easylist-notifications" - "easylist-annoyances" - "adguard-mobile-app-banners" - "adguard-popup-overlays" - "RUS-0" - ]; - }; - "addon@darkreader.org" = { - enabled = true; - enabledByDefault = true; - changeBrowserTheme = false; - detectDarkTheme = false; - enableContextMenus = false; - enableForPDF = true; - enableForProtectedPages = false; - fetchNews = false; - previewNewDesign = true; - syncSettings = true; - syncSitesFixes = true; - disabledFor = [ "home.voronind.com" ]; - theme = { - mode = 1; - brightness = 100; - contrast = 100; - grayscale = 0; - sepia = 0; - useFont = false; - fontFamily = config.style.font.sansSerif.name; - textStroke = 0; - engine = "dynamicTheme"; # dynamicTheme, cssFilter or svgFilter. - stylesheet = ""; - darkSchemeBackgroundColor = "#${config.style.color.bg.dark}"; - darkSchemeTextColor = "#${config.style.color.fg.light}"; - lightSchemeBackgroundColor = "#${config.style.color.bg.light}"; - lightSchemeTextColor = "#${config.style.color.fg.dark}"; - scrollbarColor = "#${config.style.color.neutral}"; - selectionColor = "#${config.style.color.selection}"; - styleSystemControls = true; - lightColorScheme = "Default"; - darkColorScheme = "Default"; - immediateModify = true; - }; - automation = { - enabled = false; - mode = ""; - behavior = "OnOff"; - }; - time = { - activation = "18:00"; - deactivation = "9:00"; - }; - location = { - latitude = null; - longitude = null; - }; - }; - }; - # NOTE: `firefox-esr` edition is required to change search engines. - SearchEngines = { - Add = searchEngines; - Default = "SearX"; - PreventInstalls = true; - Remove = [ - "Bing" - "DuckDuckGo" - "Google" - "Wikipedia (en)" - ]; - }; - FirefoxHome = { - Search = false; - TopSites = false; - SponsoredTopSites = false; - Highlights = false; - Pocket = false; - Snippets = false; - Locked = true; - }; - FirefoxSuggest = { - WebSuggestions = false; - SponsoredSuggestions = false; - ImproveSuggest = false; - Locked = true; - }; - PDFjs = { - Enabled = false; - EnablePermissions = false; - }; - Handlers = { - mimeTypes."application/pdf".action = "saveToDisk"; - }; - extensions = { - pdf = { - action = "useHelperApp"; - ask = true; - handlers = [ - { - name = "GNOME Document Viewer"; - path = "${pkgs.evince}/bin/evince"; - } - ]; - }; - }; - Permissions = { - Camera = { - Allow = [ ]; - Block = [ ]; - BlockNewRequests = false; - Locked = false; - }; - Microphome = { - Allow = [ ]; - Block = [ ]; - BlockNewRequests = false; - Locked = false; - }; - Location = { - Allow = [ ]; - Block = [ ]; - BlockNewRequests = true; - Locked = true; - }; - Autoplay = { - Allow = [ ]; - Block = [ ]; - Default = "block-audio-video"; # allow-audio-video | block-audio | block-audio-video - Locked = true; - }; - }; - PictureInPicture = { - Enabled = false; - Locked = false; - }; - SanitizeOnShutdown = { - Cache = true; - Cookies = false; - Downloads = false; - FormData = true; - History = false; - Sessions = false; - SiteSettings = false; - OfflineApps = true; - Locked = true; - }; - UserMessaging = { - ExtensionRecommendations = false; - FeatureRecommendations = false; - MoreFromMozilla = false; - SkipOnboarding = true; - UrlbarInterventions = false; - WhatsNew = false; - Locked = true; - }; - }; + { + enable = true; + package = pkgs.firefox-esr; + # languagePacks = [ "en-US" "ru" ]; + profiles.default = { + inherit userChrome userContent; + }; + # REF: https://mozilla.github.io/policy-templates/ + policies = { + AppAutoUpdate = false; + BackgroundAppUpdate = false; + DisableBuiltinPDFViewer = true; + DisableFirefoxAccounts = true; + DisableFirefoxStudies = true; + DisableFormHistory = true; + DisableMasterPasswordCreation = true; + DisablePasswordReveal = true; + DisablePocket = true; + DisableProfileImport = true; + DisableSetDesktopBackground = true; + DisableTelemetry = true; + DontCheckDefaultBrowser = true; + ExtensionUpdate = true; + ManagedBookmarks = [ { toplevel_name = "Pin"; } ] ++ bookmarks; + NoDefaultBookmarks = true; + OfferToSaveLogins = false; + PasswordManagerEnabled = false; + Preferences = builtins.foldl' (acc: pref: acc // pref) { } prefs; + PromptForDownloadLocation = false; + SearchSuggestEnabled = false; + ShowHomeButton = false; + StartDownloadsInTempDirectory = false; + UseSystemPrintDialog = true; + EnableTrackingProtection = { + Value = true; + Locked = false; + Cryptomining = true; + Fingerprinting = true; + EmailTracking = true; + Exceptions = [ "https://example.com" ]; + }; + EncryptedMediaExtensions = { + Enabled = true; + Locked = true; + }; + ExtensionSettings = { + # Block extension installation outside of this config. + "*" = { + install_sources = [ "*" ]; + installation_mode = "blocked"; + }; + } // builtins.foldl' (acc: ext: acc // ext) { } extensions; + "3rdparty".Extensions = { + "uBlock0@raymondhill.net".adminSettings = { + userSettings = { + uiTheme = "dark"; + cloudStorageEnabled = false; + }; + # NOTE: Check in `Support` -> `Troubleshooting Information` tab. + selectedFilterLists = [ + "user-filters" + "ublock-badware" + "ublock-privacy" + "ublock-quick-fixes" + "ublock-filters" + "easyprivacy" + "ublock-unbreak" + "urlhaus-1" + "easylist" + "plowe-0" + "adguard-cookies" + "fanboy-cookiemonster" + "ublock-cookies-easylist" + "adguard-other-annoyances" + "ublock-cookies-adguard" + "adguard-widgets" + "fanboy-social" + "ublock-annoyances" + "adguard-social" + "fanboy-thirdparty_social" + "easylist-chat" + "easylist-newsletters" + "easylist-notifications" + "easylist-annoyances" + "adguard-mobile-app-banners" + "adguard-popup-overlays" + "RUS-0" + ]; + }; + "addon@darkreader.org" = { + enabled = true; + enabledByDefault = true; + changeBrowserTheme = false; + detectDarkTheme = false; + enableContextMenus = false; + enableForPDF = true; + enableForProtectedPages = false; + fetchNews = false; + previewNewDesign = true; + syncSettings = true; + syncSitesFixes = true; + disabledFor = [ "home.voronind.com" ]; + theme = { + mode = 1; + brightness = 100; + contrast = 100; + grayscale = 0; + sepia = 0; + useFont = false; + fontFamily = config.module.style.font.sansSerif.name; + textStroke = 0; + engine = "dynamicTheme"; # dynamicTheme, cssFilter or svgFilter. + stylesheet = ""; + darkSchemeBackgroundColor = "#${config.module.style.color.bg.dark}"; + darkSchemeTextColor = "#${config.module.style.color.fg.light}"; + lightSchemeBackgroundColor = "#${config.module.style.color.bg.light}"; + lightSchemeTextColor = "#${config.module.style.color.fg.dark}"; + scrollbarColor = "#${config.module.style.color.neutral}"; + selectionColor = "#${config.module.style.color.selection}"; + styleSystemControls = true; + lightColorScheme = "Default"; + darkColorScheme = "Default"; + immediateModify = true; + }; + automation = { + enabled = false; + mode = ""; + behavior = "OnOff"; + }; + time = { + activation = "18:00"; + deactivation = "9:00"; + }; + location = { + latitude = null; + longitude = null; + }; + }; + }; + # NOTE: `firefox-esr` edition is required to change search engines. + SearchEngines = { + Add = searchEngines; + Default = "SearX"; + PreventInstalls = true; + Remove = [ + "Bing" + "DuckDuckGo" + "Google" + "Wikipedia (en)" + ]; + }; + FirefoxHome = { + Search = false; + TopSites = false; + SponsoredTopSites = false; + Highlights = false; + Pocket = false; + Snippets = false; + Locked = true; + }; + FirefoxSuggest = { + WebSuggestions = false; + SponsoredSuggestions = false; + ImproveSuggest = false; + Locked = true; + }; + PDFjs = { + Enabled = false; + EnablePermissions = false; + }; + Handlers = { + mimeTypes."application/pdf".action = "saveToDisk"; + }; + extensions = { + pdf = { + action = "useHelperApp"; + ask = true; + handlers = [ + { + name = "GNOME Document Viewer"; + path = "${pkgs.evince}/bin/evince"; + } + ]; + }; + }; + Permissions = { + Camera = { + Allow = [ ]; + Block = [ ]; + BlockNewRequests = false; + Locked = false; + }; + Microphome = { + Allow = [ ]; + Block = [ ]; + BlockNewRequests = false; + Locked = false; + }; + Location = { + Allow = [ ]; + Block = [ ]; + BlockNewRequests = true; + Locked = true; + }; + Autoplay = { + Allow = [ ]; + Block = [ ]; + Default = "block-audio-video"; # allow-audio-video | block-audio | block-audio-video + Locked = true; + }; + }; + PictureInPicture = { + Enabled = false; + Locked = false; + }; + SanitizeOnShutdown = { + Cache = true; + Cookies = false; + Downloads = false; + FormData = true; + History = false; + Sessions = false; + SiteSettings = false; + OfflineApps = true; + Locked = true; + }; + UserMessaging = { + ExtensionRecommendations = false; + FeatureRecommendations = false; + MoreFromMozilla = false; + SkipOnboarding = true; + UrlbarInterventions = false; + WhatsNew = false; + Locked = true; + }; + }; } diff --git a/home/user/x86_64-linux/root/default.nix b/home/user/x86_64-linux/root/default.nix deleted file mode 100644 index 780c1a2..0000000 --- a/home/user/x86_64-linux/root/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ ... }: -{ - home.hm = { - homeDirectory = "/root"; - package = { - core.enable = true; - }; - }; -} diff --git a/home/user/x86_64-linux/voronind/default.nix b/home/user/x86_64-linux/voronind/default.nix deleted file mode 100644 index fdaa16d..0000000 --- a/home/user/x86_64-linux/voronind/default.nix +++ /dev/null @@ -1,9 +0,0 @@ -{ ... }: -{ - home.hm = { - homeDirectory = "/home/voronind"; - package = { - core.enable = true; - }; - }; -} diff --git a/home/variable/default.nix b/home/variable/default.nix index e6e9a64..c718e08 100644 --- a/home/variable/default.nix +++ b/home/variable/default.nix @@ -1,29 +1,28 @@ -{ pkgs, ... }: -{ - # Default text editor. - EDITOR = "nvim"; +{ pkgs, ... }: { + # Default text editor. + EDITOR = "nvim"; - # App to use for man pages. - MANPAGER = "nvim +Man!"; + # App to use for man pages. + MANPAGER = "nvim +Man!"; - # Allow unfree packages in shell. - NIXPKGS_ALLOW_UNFREE = "1"; + # Allow unfree packages in shell. + NIXPKGS_ALLOW_UNFREE = "1"; - # Current system architecture. - NIX_CURRENT_SYSTEM = "${pkgs.stdenv.system}"; + # Current system architecture. + NIX_CURRENT_SYSTEM = "${pkgs.stdenv.system}"; - # Enable Mangohud by default. - MANGOHUD = "1"; + # Enable Mangohud by default. + MANGOHUD = "1"; - # Use fsync for Wine. - WINEFSYNC = "1"; + # Use fsync for Wine. + WINEFSYNC = "1"; - # Disable Firefox profile switching on rebuild. - MOZ_LEGACY_PROFILES = "1"; + # Disable Firefox profile switching on rebuild. + MOZ_LEGACY_PROFILES = "1"; - # GTK apps compat. - GTK_CSD = 0; + # GTK apps compat. + GTK_CSD = 0; - # Terminal settings. - TERM = "xterm-256color"; + # Terminal settings. + TERM = "xterm-256color"; } diff --git a/home/xdg/default.nix b/home/xdg/default.nix index 68f4d08..4bc542b 100644 --- a/home/xdg/default.nix +++ b/home/xdg/default.nix @@ -1,19 +1,18 @@ -{ homeDirectory, ... }: -{ - userDirs = { - enable = true; - createDirectories = true; - desktop = "${homeDirectory}/"; - documents = "${homeDirectory}/document/"; - download = "${homeDirectory}/download/"; - music = "${homeDirectory}/music/"; - pictures = "${homeDirectory}/picture/"; - publicShare = "${homeDirectory}/share/"; - templates = "${homeDirectory}/.template/"; - videos = "${homeDirectory}/video/"; - extraConfig = { - XDG_CONFIG_HOME = "${homeDirectory}/.config"; - XDG_TMP_DIR = "${homeDirectory}/tmp/"; - }; - }; +{ homeDirectory, ... }: { + userDirs = { + enable = true; + createDirectories = true; + desktop = "${homeDirectory}/"; + documents = "${homeDirectory}/document/"; + download = "${homeDirectory}/download/"; + music = "${homeDirectory}/music/"; + pictures = "${homeDirectory}/picture/"; + publicShare = "${homeDirectory}/share/"; + templates = "${homeDirectory}/.template/"; + videos = "${homeDirectory}/video/"; + extraConfig = { + XDG_CONFIG_HOME = "${homeDirectory}/.config"; + XDG_TMP_DIR = "${homeDirectory}/tmp/"; + }; + }; } diff --git a/host/x86_64-linux/dasha/Filesystem.nix b/host/x86_64-linux/dasha/Filesystem.nix index 0ee9c86..6932ca6 100644 --- a/host/x86_64-linux/dasha/Filesystem.nix +++ b/host/x86_64-linux/dasha/Filesystem.nix @@ -1,22 +1,21 @@ -{ ... }: -{ - fileSystems = { - "/storage/hot" = { - device = "/dev/storage/hot"; - fsType = "ext4"; - options = [ - "nofail" - "noatime" - ]; - }; +{ ... }: { + fileSystems = { + "/storage/hot" = { + device = "/dev/storage/hot"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; - "/storage/cold" = { - device = "/dev/storage/cold"; - fsType = "ext4"; - options = [ - "nofail" - "noatime" - ]; - }; - }; + "/storage/cold" = { + device = "/dev/storage/cold"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; + }; } diff --git a/host/x86_64-linux/dasha/default.nix b/host/x86_64-linux/dasha/default.nix index da3ed68..7c8ebc6 100644 --- a/host/x86_64-linux/dasha/default.nix +++ b/host/x86_64-linux/dasha/default.nix @@ -1,40 +1,35 @@ -{ ... }: -{ - home.nixos.enable = true; - user = { - dasha.enable = true; - root.enable = true; - }; - - module = { - amd.gpu.enable = true; - autoupdate.enable = true; - builder.client.enable = true; - desktop.sway.enable = true; - kernel.enable = true; - keyd.enable = true; - print.enable = true; - tablet.enable = true; - intel.cpu = { - enable = true; - powersave = true; - }; - package = { - common.enable = true; - core.enable = true; - creative.enable = true; - desktop.enable = true; - dev.enable = true; - extra.enable = true; - gaming.enable = true; - }; - }; - - setting = { - cpu.hwmon = { - path = "/sys/devices/platform/coretemp.0/hwmon"; - file = "temp1_input"; - }; - }; +{ ... }: { + home.nixos.enable = true; + user = { + dasha.enable = true; + root.enable = true; + }; + module = { + amd.gpu.enable = true; + autoupdate.enable = true; + builder.client.enable = true; + desktop.sway.enable = true; + kernel.enable = true; + keyd.enable = true; + print.enable = true; + tablet.enable = true; + hwmon = { + file = "temp1_input"; + path = "/sys/devices/platform/coretemp.0/hwmon"; + }; + intel.cpu = { + enable = true; + powersave = true; + }; + package = { + common.enable = true; + core.enable = true; + creative.enable = true; + desktop.enable = true; + dev.enable = true; + extra.enable = true; + gaming.enable = true; + }; + }; } diff --git a/host/x86_64-linux/desktop/Filesystem.nix b/host/x86_64-linux/desktop/Filesystem.nix index 39d9c5a..a29db5f 100644 --- a/host/x86_64-linux/desktop/Filesystem.nix +++ b/host/x86_64-linux/desktop/Filesystem.nix @@ -1,33 +1,32 @@ -{ ... }: -{ - fileSystems = { - "/storage/hot" = { - device = "/dev/storage/hot"; - fsType = "ext4"; - options = [ - "noatime" - "nofail" - ]; - }; +{ ... }: { + fileSystems = { + "/storage/hot" = { + device = "/dev/storage/hot"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; - "/storage/cold_1" = { - device = "/dev/storage/cold_1"; - fsType = "ext4"; - options = [ - "noatime" - "noauto" - "nofail" - ]; - }; + "/storage/cold_1" = { + device = "/dev/storage/cold_1"; + fsType = "ext4"; + options = [ + "noatime" + "noauto" + "nofail" + ]; + }; - "/storage/cold_2" = { - device = "/dev/storage/cold_2"; - fsType = "ext4"; - options = [ - "noatime" - "noauto" - "nofail" - ]; - }; - }; + "/storage/cold_2" = { + device = "/dev/storage/cold_2"; + fsType = "ext4"; + options = [ + "noatime" + "noauto" + "nofail" + ]; + }; + }; } diff --git a/host/x86_64-linux/desktop/default.nix b/host/x86_64-linux/desktop/default.nix index 6f0bfb8..1009f87 100644 --- a/host/x86_64-linux/desktop/default.nix +++ b/host/x86_64-linux/desktop/default.nix @@ -1,59 +1,55 @@ -{ ... }: -{ - home.nixos.enable = true; - user = { - root.enable = true; - voronind.enable = true; - }; +{ ... }: { + home.nixos.enable = true; + user = { + root.enable = true; + voronind.enable = true; + }; - module = { - autoupdate.enable = true; - builder.client.enable = true; - distrobox.enable = true; - keyd.enable = true; - ollama.enable = true; - print.enable = true; - virtmanager.enable = true; - amd = { - compute.enable = true; - gpu.enable = true; - cpu = { - enable = true; - powersave = true; - }; - }; - desktop.sway = { - enable = true; - extraConfig = '' - output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" mode 1920x1080@74.986Hz transform 180 pos 780,0 - output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" pos 0,1080 - workspace 1 output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" - ''; - }; - docker = { - enable = true; - autostart = false; - rootless = false; - }; - kernel = { - enable = true; - latest = true; - }; - package = { - common.enable = true; - core.enable = true; - creative.enable = true; - desktop.enable = true; - dev.enable = true; - extra.enable = true; - gaming.enable = true; - }; - }; - - setting = { - cpu.hwmon = { - path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; - file = "temp1_input"; - }; - }; + module = { + autoupdate.enable = true; + builder.client.enable = true; + distrobox.enable = true; + keyd.enable = true; + ollama.enable = true; + print.enable = true; + virtmanager.enable = true; + amd = { + compute.enable = true; + gpu.enable = true; + cpu = { + enable = true; + powersave = true; + }; + }; + desktop.sway = { + enable = true; + extraConfig = '' + output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" mode 1920x1080@74.986Hz transform 180 pos 780,0 + output "Huawei Technologies Co., Inc. ZQE-CBA 0xC080F622" pos 0,1080 + workspace 1 output "ASUSTek COMPUTER INC ASUS VA24E R2LMTF127165" + ''; + }; + docker = { + enable = true; + autostart = false; + rootless = false; + }; + hwmon = { + file = "temp1_input"; + path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; + }; + kernel = { + enable = true; + latest = true; + }; + package = { + common.enable = true; + core.enable = true; + creative.enable = true; + desktop.enable = true; + dev.enable = true; + extra.enable = true; + gaming.enable = true; + }; + }; } diff --git a/host/x86_64-linux/home/Backup.nix b/host/x86_64-linux/home/Backup.nix index 03b7241..2e1b5bb 100644 --- a/host/x86_64-linux/home/Backup.nix +++ b/host/x86_64-linux/home/Backup.nix @@ -1,110 +1,112 @@ { - pkgs, - util, - __findFile, - ... -}@args: -let - bash = import args; - script = pkgs.writeText "backupScript" '' - source ${bash.modulesFile} + __findFile, + pkgs, + util, + ... +} @args: let + bash = import args; + script = pkgs.writeText "backupScript" (util.trimTabs '' + source ${bash.modulesFile} - function report() { - echo "''${*}" - notify "''${*}" - } + function report() { + echo "''${*}" + notify "''${*}" + } - # Define constants. - path_src="/storage/hot" - path_mount="/storage/cold_1" - path_backup="''${path_mount}/backup" - path_container="''${path_backup}/home" - path_media="/storage/cold_1 /storage/cold_2" + # Define constants. + path_src="/storage/hot" + path_mount="/storage/cold_1" + path_backup="''${path_mount}/backup" + path_container="''${path_backup}/home" + path_media="/storage/cold_1 /storage/cold_2" - # Check if backup drive is mounted. - if [ ! -f "''${path_mount}"/.mount ]; then - report "Backup : ''${path_mount} not mounted!" - exit 1 - fi + # Check if backup drive is mounted. + if [ ! -f "''${path_mount}"/.mount ]; then + report "Backup : ''${path_mount} not mounted!" + exit 1 + fi - # Check if hot storage is mounted. - if [ ! -f "''${path_src}"/.mount ]; then - report "Backup : ''${path_src} not mounted!" - exit 1 - fi + # Check if hot storage is mounted. + if [ ! -f "''${path_src}"/.mount ]; then + report "Backup : ''${path_src} not mounted!" + exit 1 + fi - # Cd to src storage. - cd "''${path_src}" + # Cd to src storage. + cd "''${path_src}" - # Save media list. - find ''${path_media} -type d > ''${path_backup}/cold/ColdMedia.txt || report "Backup : Failed to save media list!" - cd ''${path_backup}/cold/ - archive ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!" - cd - + # Save media list. + find ''${path_media} -type d > ''${path_backup}/cold/ColdMedia.txt || report "Backup : Failed to save media list!" + cd ''${path_backup}/cold/ + archive ColdMedia.txt && rm ColdMedia.txt || report "Backup : Failed to archive media list!" + cd - - # Backup containers. - container=$(archive container/) - bupsize=$(tdu ''${container} | awk '{print $1}') - mv ''${container} ''${path_container}/ || report "Backup : Failed to save containers!" + # Backup containers. + container=$(archive container/) + bupsize=$(tdu ''${container} | awk '{print $1}') + mv ''${container} ''${path_container}/ || report "Backup : Failed to save containers!" - # Backup some media. - cd ''${path_src} - paper=$(archive paper/) - mv ''${paper} ''${path_backup}/paper/ || report "Backup : Failed to save paper!" - cd - + # Backup some media. + cd ''${path_src} + paper=$(archive paper/) + mv ''${paper} ''${path_backup}/paper/ || report "Backup : Failed to save paper!" + cd - - # Prune media copies. - cd ''${path_backup}/paper/ - archive_prune Paper 7 - cd - + # Prune media copies. + cd ''${path_backup}/paper/ + archive_prune Paper 7 + cd - - cd ''${path_backup}/cold/ - archive_prune ColdMediaTxt 30 - cd - + cd ''${path_backup}/cold/ + archive_prune ColdMediaTxt 30 + cd - - # Prune old container copies. - cd ''${path_container} - archive_prune Container 7 - cd - + # Prune old container copies. + cd ''${path_container} + archive_prune Container 7 + cd - - # Prune game saves. - cd "''${path_backup}/save/" - archive_prune - cd - + # Prune game saves. + cd "''${path_backup}/save/" + archive_prune + cd - - # Sync writes. - sync + # Sync writes. + sync - # Notify completion & size. - notify_silent "Backup : Complete ''${bupsize}." - echo "Backup : Complete ''${bupsize}." - ''; -in -{ - systemd.services.backup = util.mkStaticSystemdService { - enable = true; - description = "Home system backup."; - serviceConfig.Type = "oneshot"; - path = with pkgs; [ - bashInteractive - curl - gawk - gnutar - procps - pv - xz - ]; - script = '' - ${pkgs.bashInteractive}/bin/bash ${script} - ''; - }; + # Notify completion & size. + notify_silent "Backup : Complete ''${bupsize}." + echo "Backup : Complete ''${bupsize}." + ''); +in { + systemd.services.backup = util.mkStaticSystemdService { + enable = true; + description = "Home system backup."; + serviceConfig = { + Type = "oneshot"; + }; + path = with pkgs; [ + bashInteractive + curl + gawk + gnutar + procps + pv + xz + ]; + script = '' + ${pkgs.bashInteractive}/bin/bash ${script} + ''; + }; - systemd.timers.backup = { - timerConfig = { - OnCalendar = "*-*-* 06:00:00"; - Persistent = true; - Unit = "backup.service"; - }; - wantedBy = [ "timers.target" ]; - }; + systemd.timers.backup = { + timerConfig = { + OnCalendar = "*-*-* 06:00:00"; + Persistent = true; + Unit = "backup.service"; + }; + wantedBy = [ + "timers.target" + ]; + }; } diff --git a/host/x86_64-linux/home/Container.nix b/host/x86_64-linux/home/Container.nix index 3499d6f..59baf08 100644 --- a/host/x86_64-linux/home/Container.nix +++ b/host/x86_64-linux/home/Container.nix @@ -1,80 +1,89 @@ -{ ... }: -{ - container = { - enable = true; - autoStart = true; +{ ... }: { + container = { + enable = true; + autoStart = true; - module = { - # ISSUE: hdd.enable = true; - change.enable = true; - cloud.enable = true; - ddns.enable = true; - dns.enable = true; - download.enable = true; - frkn.enable = true; - git.enable = true; - home.enable = true; - iot.enable = true; - jobber.enable = true; - mail.enable = true; - office.enable = true; - paper.enable = true; - pass.enable = true; - paste.enable = true; - postgres.enable = true; - print.enable = true; - proxy.enable = true; - rabbitmq.enable = true; - read.enable = true; - redis.enable = true; - search.enable = true; - status.enable = true; - stock.enable = true; - vpn.enable = true; - watch.enable = true; - yt.enable = true; - }; + module = { + change.enable = true; + cloud.enable = true; + ddns.enable = true; + dns.enable = true; + download.enable = true; + frkn.enable = true; + git.enable = true; + home.enable = true; + iot.enable = true; + jobber.enable = true; + mail.enable = true; + office.enable = true; + paper.enable = true; + pass.enable = true; + paste.enable = true; + postgres.enable = true; + print.enable = true; + proxy.enable = true; + rabbitmq.enable = true; + read.enable = true; + redis.enable = true; + search.enable = true; + status.enable = true; + stock.enable = true; + watch.enable = true; + yt.enable = true; + }; - storage = "/storage/hot/container"; - domain = "voronind.com"; - host = "188.242.247.132"; - interface = "enp8s0"; - localAccess = "10.0.0.0/24"; - media = { - anime = [ - "/storage/cold_1/anime" - "/storage/cold_2/anime" - ]; - book = [ "/storage/hot/book" ]; - download = [ "/storage/hot/download" ]; - manga = [ - "/storage/cold_1/manga" - "/storage/cold_2/manga" - ]; - movie = [ - "/storage/cold_1/movie" - "/storage/cold_2/movie" - ]; - music = [ "/storage/cold_2/music" ]; - paper = [ "/storage/hot/paper" ]; - porn = [ "/storage/cold_2/porn" ]; - photo = [ - "/storage/hot/container/cloud/data/data/cakee/files/photo" - "/storage/cold_1/backup/tmp/photo" - ]; - show = [ - "/storage/cold_1/show" - "/storage/cold_2/show" - ]; - study = [ - "/storage/cold_1/study" - "/storage/cold_2/study" - ]; - work = [ "/storage/cold_2/work" ]; - youtube = [ - "/storage/cold_1/youtube" - "/storage/cold_2/youtube" - ]; - }; - }; + domain = "voronind.com"; + host = "188.242.247.132"; + interface = "enp8s0"; + localAccess = "10.0.0.0/24"; + storage = "/storage/hot/container"; + media = { + anime = [ + "/storage/cold_1/anime" + "/storage/cold_2/anime" + ]; + book = [ + "/storage/hot/book" + ]; + download = [ + "/storage/hot/download" + ]; + manga = [ + "/storage/cold_1/manga" + "/storage/cold_2/manga" + ]; + movie = [ + "/storage/cold_1/movie" + "/storage/cold_2/movie" + ]; + music = [ + "/storage/cold_2/music" + ]; + paper = [ + "/storage/hot/paper" + ]; + porn = [ + "/storage/cold_2/porn" + ]; + photo = [ + "/storage/hot/container/cloud/data/data/cakee/files/photo" + "/storage/cold_1/backup/tmp/photo" + ]; + show = [ + "/storage/cold_1/show" + "/storage/cold_2/show" + ]; + study = [ + "/storage/cold_1/study" + "/storage/cold_2/study" + ]; + work = [ + "/storage/cold_2/work" + ]; + youtube = [ + "/storage/cold_1/youtube" + "/storage/cold_2/youtube" + ]; + }; + }; } diff --git a/host/x86_64-linux/home/Filesystem.nix b/host/x86_64-linux/home/Filesystem.nix index 936decb..1735bef 100644 --- a/host/x86_64-linux/home/Filesystem.nix +++ b/host/x86_64-linux/home/Filesystem.nix @@ -1,37 +1,36 @@ -{ ... }: -{ - fileSystems = { - "/storage/cold_1" = { - device = "/dev/storage/cold_1"; - fsType = "ext4"; - options = [ - "nofail" - "noatime" - ]; - }; +{ ... }: { + fileSystems = { + "/storage/cold_1" = { + device = "/dev/storage/cold_1"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; - "/storage/cold_2" = { - device = "/dev/storage/cold_2"; - fsType = "ext4"; - options = [ - "nofail" - "noatime" - ]; - }; + "/storage/cold_2" = { + device = "/dev/storage/cold_2"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; - "/storage/hot" = { - device = "/dev/storage/hot"; - fsType = "ext4"; - options = [ - "nofail" - "noatime" - ]; - }; - }; + "/storage/hot" = { + device = "/dev/storage/hot"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; + }; - # swapDevices = [{ - # device = "/storage/hot/.swapfile"; - # size = 128 * 1024; - # options = [ "nofail" ]; - # }]; + # swapDevices = [{ + # device = "/storage/hot/.swapfile"; + # size = 128 * 1024; + # options = [ "nofail" ]; + # }]; } diff --git a/host/x86_64-linux/home/Network.nix b/host/x86_64-linux/home/Network.nix index f6d9336..c9c95d1 100644 --- a/host/x86_64-linux/home/Network.nix +++ b/host/x86_64-linux/home/Network.nix @@ -1,136 +1,135 @@ -{ config, lib, ... }: -let - internal = "10.0.0.1"; # Lan host IP address. - external = "188.242.247.132"; # Wan host IP address. - wifi = "10.0.0.2"; # Wifi router IP address. - - lan = "br0"; # Lan interface. - wan = "enp8s0"; # Wan interface. -in { - # Allow packet routing (we are a router). - boot.kernel.sysctl = { - "net.ipv4.conf.all.src_valid_mark" = lib.mkForce 1; - "net.ipv4.ip_forward" = lib.mkForce 1; - }; + config, + lib, + util, + ... +}: let + external = "188.242.247.132"; # Wan host IP address. + internal = "10.0.0.1"; # Lan host IP address. + wifi = "10.0.0.2"; # Wifi router IP address. - # Disable SSH access from everywhere, configure access bellow. - services.openssh.openFirewall = false; + lan = "br0"; # Lan interface. + wan = "enp8s0"; # Wan interface. +in { + # Allow packet routing (we are a router). + boot.kernel.sysctl = { + "net.ipv4.conf.all.src_valid_mark" = lib.mkForce 1; + "net.ipv4.ip_forward" = lib.mkForce 1; + }; - networking = { - # Use only external DNS. - networkmanager.insertNameservers = [ - "1.1.1.1" - "8.8.8.8" - ]; + # Disable SSH access from everywhere, configure access bellow. + services.openssh.openFirewall = false; - # Some extra hosts for local access. - extraHosts = with config.container.module; '' - ${git.address} git.voronind.com - ${proxy.address} iot.voronind.com - ${proxy.address} pass.voronind.com - ''; + networking = { + # Use only external DNS. + networkmanager.insertNameservers = [ + "1.1.1.1" + "8.8.8.8" + ]; - firewall = { - enable = true; - extraCommands = - let - # Container configs. - cfg = config.container.module; + # Some extra hosts for local access. + extraHosts = with config.container.module; (util.trimTabs '' + ${git.address} git.voronind.com + ${proxy.address} iot.voronind.com + ${proxy.address} pass.voronind.com + ''); - # Const. - tcp = "tcp"; - udp = "udp"; + firewall = { + enable = true; + extraCommands = let + # Container configs. + cfg = config.container.module; - # Create port forwarding rule. - mkForward = - src: sport: dst: dport: proto: - "iptables -t nat -I PREROUTING -d ${src} -p ${proto} --dport ${toString sport} -j DNAT --to-destination ${dst}:${toString dport}\n"; - in - '' - # Wan access for 10.0.0.0/24 subnet. - iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -d 0/0 -o ${wan} -j MASQUERADE + # Const. + tcp = "tcp"; + udp = "udp"; - # Full access from VPN clients. - iptables -I INPUT -j ACCEPT -s ${cfg.vpn.address} -d ${internal} - iptables -I INPUT -j ACCEPT -s ${cfg.frkn.address} -d ${internal} + # Create port forwarding rule. + mkForward = src: sport: dst: dport: proto: "iptables -t nat -I PREROUTING -d ${src} -p ${proto} --dport ${toString sport} -j DNAT --to-destination ${dst}:${toString dport}\n"; + in (util.trimTabs '' + # Wan access for 10.0.0.0/24 subnet. + iptables -t nat -A POSTROUTING -s 10.0.0.0/24 -d 0/0 -o ${wan} -j MASQUERADE - # Full access from Lan. - iptables -I INPUT -j ACCEPT -i ${lan} -d ${internal} - '' - # Expose DNS server for internal network. - + (mkForward internal cfg.dns.port cfg.dns.address cfg.dns.port tcp) - + (mkForward internal cfg.dns.port cfg.dns.address cfg.dns.port udp) + # Full access from VPN clients. + iptables -I INPUT -j ACCEPT -s ${cfg.vpn.address} -d ${internal} + iptables -I INPUT -j ACCEPT -s ${cfg.frkn.address} -d ${internal} - # Email server. - + (mkForward external 25 cfg.mail.address 25 tcp) - + (mkForward internal 25 cfg.mail.address 25 tcp) - + (mkForward internal 465 cfg.mail.address 465 tcp) - + (mkForward internal 993 cfg.mail.address 993 tcp) + # Full access from Lan. + iptables -I INPUT -j ACCEPT -i ${lan} -d ${internal} + '') + # Expose DNS server for internal network. + + (mkForward internal cfg.dns.port cfg.dns.address cfg.dns.port tcp) + + (mkForward internal cfg.dns.port cfg.dns.address cfg.dns.port udp) - # FRKN internal proxy server. - + (mkForward internal cfg.frkn.port cfg.frkn.address cfg.frkn.port tcp) - + (mkForward internal cfg.frkn.torport cfg.frkn.address cfg.frkn.torport tcp) - + (mkForward internal cfg.frkn.xrayport cfg.frkn.address cfg.frkn.xrayport tcp) - + (mkForward internal cfg.frkn.port cfg.frkn.address cfg.frkn.port udp) - + (mkForward internal cfg.frkn.torport cfg.frkn.address cfg.frkn.torport udp) - + (mkForward internal cfg.frkn.xrayport cfg.frkn.address cfg.frkn.xrayport udp) + # Email server. + + (mkForward external 25 cfg.mail.address 25 tcp) + + (mkForward internal 25 cfg.mail.address 25 tcp) + + (mkForward internal 465 cfg.mail.address 465 tcp) + + (mkForward internal 993 cfg.mail.address 993 tcp) - # Allow VPN connections from Wan. - + (mkForward external cfg.vpn.port cfg.vpn.address cfg.vpn.port udp) + # FRKN internal proxy server. + + (mkForward internal cfg.frkn.port cfg.frkn.address cfg.frkn.port tcp) + + (mkForward internal cfg.frkn.torport cfg.frkn.address cfg.frkn.torport tcp) + + (mkForward internal cfg.frkn.xrayport cfg.frkn.address cfg.frkn.xrayport tcp) + + (mkForward internal cfg.frkn.port cfg.frkn.address cfg.frkn.port udp) + + (mkForward internal cfg.frkn.torport cfg.frkn.address cfg.frkn.torport udp) + + (mkForward internal cfg.frkn.xrayport cfg.frkn.address cfg.frkn.xrayport udp) - # Nginx HTTP access from Wan. - + (mkForward external cfg.proxy.port cfg.proxy.address cfg.proxy.port tcp) - + (mkForward internal cfg.proxy.port cfg.proxy.address cfg.proxy.port tcp) + # Allow VPN connections from Wan. + # + (mkForward external cfg.vpn.port cfg.vpn.address cfg.vpn.port udp) - # Download ports for torrents. - + (mkForward external 54630 cfg.download.address 54630 tcp) - + (mkForward external 54631 cfg.download.address 54631 tcp) - + (mkForward external 54630 cfg.download.address 54630 udp) - + (mkForward external 54631 cfg.download.address 54631 udp) + # Nginx HTTP access from Wan. + + (mkForward external cfg.proxy.port cfg.proxy.address cfg.proxy.port tcp) + + (mkForward internal cfg.proxy.port cfg.proxy.address cfg.proxy.port tcp) - # Git ssh connections. - + (mkForward external cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp) - + (mkForward internal cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp) + # Download ports for torrents. + + (mkForward external 54630 cfg.download.address 54630 tcp) + + (mkForward external 54631 cfg.download.address 54631 tcp) + + (mkForward external 54630 cfg.download.address 54630 udp) + + (mkForward external 54631 cfg.download.address 54631 udp) - # Print serivce. - + (mkForward internal cfg.print.port cfg.print.address cfg.print.port tcp); - }; + # Git ssh connections. + # + (mkForward external cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp) + + (mkForward internal cfg.git.portSsh cfg.git.address cfg.git.portSsh tcp) - # Create Lan bridge. - bridges.${lan}.interfaces = [ - "enp6s0f0" - "enp6s0f1" - "enp7s0f1" - "enp7s0f1" - ]; + # Print serivce. + + (mkForward internal cfg.print.port cfg.print.address cfg.print.port tcp); + }; - interfaces = { - ${lan}.ipv4 = { - # Assign Lan address and subnet. - addresses = [ - { - address = internal; - prefixLength = 24; - } - ]; + # Create Lan bridge. + bridges.${lan}.interfaces = [ + "enp6s0f0" + "enp6s0f1" + "enp7s0f0" + "enp7s0f1" + ]; - # Assign traffic routes. - routes = [ - # Wifi 5G clients. - { - address = "192.168.1.0"; - prefixLength = 24; - via = wifi; - } - # Wifi 2.4G clients. - { - address = "192.168.2.0"; - prefixLength = 24; - via = wifi; - } - ]; - }; - }; - }; + interfaces = { + ${lan}.ipv4 = { + # Assign Lan address and subnet. + addresses = [ + { + address = internal; + prefixLength = 24; + } + ]; + + # Assign traffic routes. + routes = [ + # Wifi 5G clients. + { + address = "192.168.1.0"; + prefixLength = 24; + via = wifi; + } + # Wifi 2.4G clients. + { + address = "192.168.2.0"; + prefixLength = 24; + via = wifi; + } + ]; + }; + }; + }; } diff --git a/host/x86_64-linux/home/Photoprocess.nix b/host/x86_64-linux/home/Photoprocess.nix index e1d9737..4a9585b 100644 --- a/host/x86_64-linux/home/Photoprocess.nix +++ b/host/x86_64-linux/home/Photoprocess.nix @@ -1,89 +1,87 @@ # Takes pictures from first photo dir, processes and stores to the second one. { - util, - pkgs, - lib, - secret, - ... -}@args: -let - imgInput = "/storage/hot/container/cloud/data/data/cakee/files/photo"; - imgOutput = "/storage/cold_1/backup/tmp/photo"; -in -{ - systemd.services.photosprocess = - let - script = pkgs.writeText "PhotoprocessScript" '' - function notify_silent() { - curl -X POST -H 'Content-Type: Application/json' -d "${secret.tg.dt "true"}" ${secret.tg.bt} &> /dev/null - } + lib, + pkgs, + secret, + util, + ... +} @args: let + imgInput = "/storage/hot/container/cloud/data/data/cakee/files/photo"; + imgOutput = "/storage/cold_1/backup/tmp/photo"; +in { + systemd.services.photosprocess = let + script = pkgs.writeText "PhotoprocessScript" (util.trimTabs '' + function notify_silent() { + curl -X POST -H 'Content-Type: Application/json' -d "${secret.tg.dt "true"}" ${secret.tg.bt} &> /dev/null + } - cd ${imgInput} + cd ${imgInput} - # Convert png to jpg. - for img in $(ls *.png) $(ls *.PNG); do - filename=''${img%.*} - convert "$filename.png" "$filename.jpg" - done - rm *.png *.PNG + # Convert png to jpg. + for img in $(ls *.png) $(ls *.PNG); do + filename=''${img%.*} + convert "$filename.png" "$filename.jpg" + done + rm *.png *.PNG - # Rename bad extensions. - for img in $(ls *.jpeg) $(ls *.JPG) $(ls *.JPEG); do - filename=''${img%.*} - mv "$img" "$filename.jpg" - done + # Rename bad extensions. + for img in $(ls *.jpeg) $(ls *.JPG) $(ls *.JPEG); do + filename=''${img%.*} + mv "$img" "$filename.jpg" + done - # Compress jpg. - mogrify -resize 2073600@ *.jpg - jpegoptim --size=1000k *.jpg + # Compress jpg. + mogrify -resize 2073600@ *.jpg + jpegoptim --size=1000k *.jpg - # Rename to hash. - for file in *; do - if [[ -f "$file" ]]; then - extension="''${file##*.}" - if [ -f "$file" ] && [ "$extension" != "$file" ]; then - new_name="''${file%$extension}" - else - new_name="$file" - extension="" - fi - new_name=$(sha1sum "$file" | cut -d\ -f1) - if [[ "$extension" != "" ]]; then - new_name="''${new_name,,}.$extension" - else - new_name="''${new_name,,}" - fi - mv "$file" "$new_name" - fi - done + # Rename to hash. + for file in *; do + if [[ -f "$file" ]]; then + extension="''${file##*.}" + if [ -f "$file" ] && [ "$extension" != "$file" ]; then + new_name="''${file%$extension}" + else + new_name="$file" + extension="" + fi + new_name=$(sha1sum "$file" | cut -d\ -f1) + if [[ "$extension" != "" ]]; then + new_name="''${new_name,,}.$extension" + else + new_name="''${new_name,,}" + fi + mv "$file" "$new_name" + fi + done - # Move to images. - total_photos=$(ls | wc -l) - mv *.jpg ${imgOutput} - notify_silent "Photos processed: $total_photos" - ''; - in - util.mkStaticSystemdService { - enable = true; - description = "Process uploaded photos."; - serviceConfig = { - Type = "oneshot"; - ExecStart = "-${lib.getExe pkgs.bashInteractive} ${script}"; - Restart = "on-failure"; - }; - path = with pkgs; [ - curl - imagemagick - jpegoptim - ]; - }; + # Move to images. + total_photos=$(ls | wc -l) + mv *.jpg ${imgOutput} + notify_silent "Photos processed: $total_photos" + ''); + in util.mkStaticSystemdService { + enable = true; + description = "Process uploaded photos"; + serviceConfig = { + ExecStart = "-${lib.getExe pkgs.bashInteractive} ${script}"; + Restart = "on-failure"; + Type = "oneshot"; + }; + path = with pkgs; [ + curl + imagemagick + jpegoptim + ]; + }; - systemd.timers.photosprocess = { - timerConfig = { - OnCalendar = "daily"; - Persistent = true; - Unit = "photosprocess.service"; - }; - wantedBy = [ "timers.target" ]; - }; + systemd.timers.photosprocess = { + timerConfig = { + OnCalendar = "daily"; + Persistent = true; + Unit = "photosprocess.service"; + }; + wantedBy = [ + "timers.target" + ]; + }; } diff --git a/host/x86_64-linux/home/default.nix b/host/x86_64-linux/home/default.nix index 68efa9a..282994c 100644 --- a/host/x86_64-linux/home/default.nix +++ b/host/x86_64-linux/home/default.nix @@ -1,66 +1,62 @@ -{ config, ... }: -{ - home.nixos.enable = true; - user = { - root.enable = true; - voronind.enable = true; - }; +{ ... }: { + home.nixos.enable = true; + user = { + root.enable = true; + voronind.enable = true; + }; - module = { - builder.server.enable = true; - desktop.sway.enable = true; - kernel.enable = true; - keyd.enable = true; - amd = { - cpu.enable = true; - gpu.enable = true; - }; - ftpd = { - enable = true; - storage = "/storage/hot/ftp"; - }; - package = { - common.enable = true; - core.enable = true; - desktop.enable = true; - }; - zapret = { - enable = true; - params = [ - "--dpi-desync=fake,disorder2" - "--dpi-desync-ttl=1" - "--dpi-desync-autottl=2" - ]; - whitelist = [ - "youtube.com" - "googlevideo.com" - "ytimg.com" - "youtu.be" - "rutracker.org" - "rutracker.cc" - "rutrk.org" - "t-ru.org" - "medium.com" - "dis.gd" - "discord.co" - "discord.com" - "discord.dev" - "discord.gg" - "discord.gift" - "discord.media" - "discord.new" - "discordapp.com" - "discordapp.net" - "discordcdn.com" - "discordstatus.com" - ]; - }; - }; - - setting = { - cpu.hwmon = { - path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; - file = "temp1_input"; - }; - }; + module = { + builder.server.enable = true; + desktop.sway.enable = true; + kernel.enable = true; + keyd.enable = true; + amd = { + cpu.enable = true; + gpu.enable = true; + }; + ftpd = { + enable = true; + storage = "/storage/hot/ftp"; + }; + hwmon = { + file = "temp1_input"; + path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; + }; + package = { + common.enable = true; + core.enable = true; + desktop.enable = true; + }; + zapret = { + enable = true; + params = [ + "--dpi-desync=fake,disorder2" + "--dpi-desync-ttl=1" + "--dpi-desync-autottl=2" + ]; + whitelist = [ + "youtube.com" + "googlevideo.com" + "ytimg.com" + "youtu.be" + "rutracker.org" + "rutracker.cc" + "rutrk.org" + "t-ru.org" + "medium.com" + "dis.gd" + "discord.co" + "discord.com" + "discord.dev" + "discord.gg" + "discord.gift" + "discord.media" + "discord.new" + "discordapp.com" + "discordapp.net" + "discordcdn.com" + "discordstatus.com" + ]; + }; + }; } diff --git a/host/x86_64-linux/laptop/Filesystem.nix b/host/x86_64-linux/laptop/Filesystem.nix index c427bcd..9916d88 100644 --- a/host/x86_64-linux/laptop/Filesystem.nix +++ b/host/x86_64-linux/laptop/Filesystem.nix @@ -1,11 +1,10 @@ -{ ... }: -{ - fileSystems."/storage/hot" = { - device = "/dev/storage/hot"; - fsType = "ext4"; - options = [ - "noatime" - "nofail" - ]; - }; +{ ... }: { + fileSystems."/storage/hot" = { + device = "/dev/storage/hot"; + fsType = "ext4"; + options = [ + "noatime" + "nofail" + ]; + }; } diff --git a/host/x86_64-linux/laptop/default.nix b/host/x86_64-linux/laptop/default.nix index 62a0f36..d32981a 100644 --- a/host/x86_64-linux/laptop/default.nix +++ b/host/x86_64-linux/laptop/default.nix @@ -1,35 +1,34 @@ -{ ... }: -{ - home.nixos.enable = true; - user = { - dasha.enable = true; - root.enable = true; - voronind.enable = true; - }; +{ ... }: { + home.nixos.enable = true; + user = { + dasha.enable = true; + root.enable = true; + voronind.enable = true; + }; - module = { - autoupdate.enable = true; - builder.client.enable = true; - desktop.sway.enable = true; - kernel.enable = true; - keyd.enable = true; - print.enable = true; - tablet.enable = true; - amd = { - compute.enable = true; - cpu = { - enable = true; - powersave = true; - }; - gpu.enable = true; - }; - package = { - common.enable = true; - core.enable = true; - desktop.enable = true; - gaming.enable = true; - creative.enable = true; - dev.enable = true; - }; - }; + module = { + autoupdate.enable = true; + builder.client.enable = true; + desktop.sway.enable = true; + kernel.enable = true; + keyd.enable = true; + print.enable = true; + tablet.enable = true; + amd = { + compute.enable = true; + cpu = { + enable = true; + powersave = true; + }; + gpu.enable = true; + }; + package = { + common.enable = true; + core.enable = true; + desktop.enable = true; + gaming.enable = true; + creative.enable = true; + dev.enable = true; + }; + }; } diff --git a/host/x86_64-linux/live/default.nix b/host/x86_64-linux/live/default.nix index 81cd3be..1122495 100644 --- a/host/x86_64-linux/live/default.nix +++ b/host/x86_64-linux/live/default.nix @@ -1,19 +1,22 @@ -{ inputs, lib, ... }: { - imports = [ - "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" - "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix" - ]; + inputs, + lib, + ... +}: { + imports = [ + "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/channel.nix" + "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/installation-cd-minimal.nix" + ]; - networking.wireless.enable = lib.mkForce false; + networking.wireless.enable = lib.mkForce false; - # Override my settings to allow SSH logins using root password. - services.openssh.settings = { - PasswordAuthentication = lib.mkForce true; - PermitRootLogin = lib.mkForce "yes"; - }; + # Override my settings to allow SSH logins using root password. + services.openssh.settings = { + PasswordAuthentication = lib.mkForce true; + PermitRootLogin = lib.mkForce "yes"; + }; - # Root user setup. - home.nixos.enable = true; - user.root.enable = true; + # Root user setup. + home.nixos.enable = true; + user.root.enable = true; } diff --git a/host/x86_64-linux/work/Fprint.nix b/host/x86_64-linux/work/Fprint.nix index bdf5d16..1ca044f 100644 --- a/host/x86_64-linux/work/Fprint.nix +++ b/host/x86_64-linux/work/Fprint.nix @@ -1,12 +1,16 @@ -{ pkgs, ... }: { - environment.systemPackages = with pkgs; [ fprintd ]; + pkgs, + ... +}: { + environment.systemPackages = with pkgs; [ + fprintd + ]; - services.fprintd = { - enable = true; - tod = { - enable = true; - driver = pkgs.libfprint-2-tod1-vfs0090; - }; - }; + services.fprintd = { + enable = true; + tod = { + enable = true; + driver = pkgs.libfprint-2-tod1-vfs0090; + }; + }; } diff --git a/host/x86_64-linux/work/default.nix b/host/x86_64-linux/work/default.nix index 2948c9b..c13081d 100644 --- a/host/x86_64-linux/work/default.nix +++ b/host/x86_64-linux/work/default.nix @@ -1,41 +1,37 @@ -{ ... }: -{ - # Keyd Print to Macro remap. - services.keyd.keyboards.default.settings.main.print = "layer(layer_number)"; +{ ... }: { + # Keyd Print to Macro remap. + services.keyd.keyboards.default.settings.main.print = "layer(layer_number)"; - home.nixos.enable = true; - user = { - root.enable = true; - dasha.enable = true; - voronind.enable = true; - }; + home.nixos.enable = true; + user = { + root.enable = true; + dasha.enable = true; + voronind.enable = true; + }; - module = { - autoupdate.enable = true; - builder.client.enable = true; - desktop.sway.enable = true; - kernel.enable = true; - keyd.enable = true; - powerlimit.thinkpad.enable = true; - print.enable = true; - intel.cpu = { - enable = true; - powersave = true; - }; - package = { - common.enable = true; - core.enable = true; - desktop.enable = true; - dev.enable = true; - extra.enable = true; - gaming.enable = true; - }; - }; - - setting = { - cpu.hwmon = { - path = "/sys/devices/platform/coretemp.0/hwmon"; - file = "temp1_input"; - }; - }; + module = { + autoupdate.enable = true; + builder.client.enable = true; + desktop.sway.enable = true; + kernel.enable = true; + keyd.enable = true; + powerlimit.thinkpad.enable = true; + print.enable = true; + hwmon = { + file = "temp1_input"; + path = "/sys/devices/platform/coretemp.0/hwmon"; + }; + intel.cpu = { + enable = true; + powersave = true; + }; + package = { + common.enable = true; + core.enable = true; + desktop.enable = true; + dev.enable = true; + extra.enable = true; + gaming.enable = true; + }; + }; } diff --git a/lib/Container.nix b/lib/Container.nix index e62a7d4..9f90fc0 100644 --- a/lib/Container.nix +++ b/lib/Container.nix @@ -1,87 +1,81 @@ { - lib, - pkgs, - const, - config, - ... -}: -{ - mkContainer = - cfg: extra: - lib.recursiveUpdate { - # Allow nested containers. - additionalCapabilities = [ ''all" --system-call-filter="add_key keyctl bpf" --capability="all'' ]; - enableTun = true; + config, + const, + lib, + pkgs, + util, + ... +}: { + mkContainer = cfg: extra: lib.recursiveUpdate { + # Allow nested containers. + additionalCapabilities = [ ''all" --system-call-filter="add_key keyctl bpf" --capability="all'' ]; + enableTun = true; - # Start containers with the system by default. - autoStart = config.container.autoStart; + # Start containers with the system by default. + autoStart = config.container.autoStart; - # IP Address of the host. This is required for container to have access to the Internet. - hostAddress = config.container.host; + # IP Address of the host. This is required for container to have access to the Internet. + hostAddress = config.container.host; - # Container's IP address. - localAddress = cfg.address; + # Container's IP address. + localAddress = cfg.address; - # Isolate container from other hosts. - privateNetwork = true; - } extra; + # Isolate container from other hosts. + privateNetwork = true; + } extra; - # Common configuration for the system inside the container. - mkContainerConfig = - cfg: extra: - lib.recursiveUpdate { - boot.isContainer = true; + # Common configuration for the system inside the container. + mkContainerConfig = cfg: extra: lib.recursiveUpdate { + boot.isContainer = true; - # HACK: Do not evaluate nixpkgs inside the container. Use host's instead. - nixpkgs.pkgs = lib.mkForce pkgs; + # HACK: Do not evaluate nixpkgs inside the container. Use host's instead. + nixpkgs.pkgs = lib.mkForce pkgs; - # Release version. - system.stateVersion = const.stateVersion; + # Release version. + system.stateVersion = const.stateVersion; - # Allow passwordless login as root. - users = { - users.root.password = ""; - mutableUsers = false; - }; + # Allow passwordless login as root. + users = { + users.root.password = ""; + mutableUsers = false; + }; - networking = { - # Default DNS servers. - nameservers = [ - "1.1.1.1" - "1.0.0.1" - ]; + networking = { + # Default DNS servers. + nameservers = [ + "1.1.1.1" + "1.0.0.1" + ]; - # HACK: Fix for upstream issue: https://github.com/NixOS/nixpkgs/issues/162686 - useHostResolvConf = lib.mkForce false; + # HACK: Fix for upstream issue: https://github.com/NixOS/nixpkgs/issues/162686 + useHostResolvConf = lib.mkForce false; - # Configure firewall. - firewall = { - enable = true; - extraCommands = '' - # Full access from the host. - iptables -I INPUT -s ${config.container.host} -j ALLOW - ''; - }; - }; - } extra; + # Configure firewall. + firewall = { + enable = true; + extraCommands = (util.trimTabs '' + # Full access from the host. + iptables -I INPUT -s ${config.container.host} -j ALLOW + ''); + }; + }; + } extra; - # Create a directory on the host for container use. - mkContainerDir = cfg: dirs: map (path: "d '${cfg.storage}/${path}' 1777 root root - -") dirs; + # Create a directory on the host for container use. + mkContainerDir = cfg: dirs: map (path: "d '${cfg.storage}/${path}' 1777 root root - -") dirs; - # Common configuration for Nginx server. - mkServer = cfg: lib.recursiveUpdate { forceSSL = false; } cfg; + # Common configuration for Nginx server. + mkServer = cfg: lib.recursiveUpdate { forceSSL = false; } cfg; - # Attach the host media directory to container. - # They will be added to /type/{0..9} - attachMedia = - type: ro: - builtins.listToAttrs ( - lib.imap0 (i: path: { - name = "/${type}/${toString i}"; - value = { - hostPath = path; - isReadOnly = ro; - }; - }) config.container.media.${type} - ); + # Attach the host media directory to container. + # They will be added to /type/{0..9} + attachMedia = type: ro: builtins.listToAttrs ( + lib.imap0 (i: path: { + name = "/${type}/${toString i}"; + value = { + hostPath = path; + isReadOnly = ro; + }; + }) config.container.media.${type} + ); } diff --git a/lib/Util.nix b/lib/Util.nix index a29e63f..0923af7 100644 --- a/lib/Util.nix +++ b/lib/Util.nix @@ -1,36 +1,28 @@ # Collection of common functions. -{ lib }: -{ - # Remove tabs indentation, - trimTabs = - text: - let - shouldStripTab = lines: builtins.all (line: (line == "") || (lib.strings.hasPrefix " " line)) lines; - stripTab = lines: builtins.map (line: lib.strings.removePrefix " " line) lines; - stripTabs = lines: if (shouldStripTab lines) then (stripTabs (stripTab lines)) else lines; - in - builtins.concatStringsSep "\n" (stripTabs (lib.strings.splitString "\n" text)); +{ lib }: rec { + # Remove tabs indentation, + trimTabs = text: let + shouldStripTab = lines: builtins.all (line: (line == "") || (lib.strings.hasPrefix " " line)) lines; + stripTab = lines: builtins.map (line: lib.strings.removePrefix " " line) lines; + stripTabs = lines: if (shouldStripTab lines) then (stripTabs (stripTab lines)) else lines; + in builtins.concatStringsSep "\n" (stripTabs (lib.strings.splitString "\n" text)); - # List all files in a dir. - ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path)); + # List all files in a dir. + ls = path: map (f: "${path}/${f}") (builtins.attrNames (builtins.readDir path)); - # Concat all files by `text` key. - catText = files: args: builtins.foldl' (acc: mod: acc + (import mod args).text) "" files; + # Concat all files by `text` key. + catText = files: args: builtins.foldl' (acc: mod: acc + (trimTabs (import mod args).text)) "" files; - # Concat all file paths by `file` key. - catFile = - files: args: builtins.foldl' (acc: mod: acc + (builtins.readFile (import mod args).file)) "" files; + # Concat all file paths by `file` key. + catFile = files: args: builtins.foldl' (acc: mod: acc + (trimTabs (builtins.readFile (import mod args).file))) "" files; - # Concat all files as a set. - catSet = files: args: lib.mkMerge (map (file: import file args) files); + # Concat all files as a set. + catSet = files: args: builtins.foldl' (acc: mod: acc // mod) { } (map (file: import file args) files); - # Systemd service that does not restart with system switch. - mkStaticSystemdService = - params: - params - // { - restartIfChanged = false; - stopIfChanged = false; - unitConfig.X-StopOnRemoval = false; - }; + # Systemd service that does not restart with system switch. + mkStaticSystemdService = params: params // { + restartIfChanged = false; + stopIfChanged = false; + unitConfig.X-StopOnRemoval = false; + }; } diff --git a/module/AmdCompute.nix b/module/AmdCompute.nix index d6d894e..85b7c75 100644 --- a/module/AmdCompute.nix +++ b/module/AmdCompute.nix @@ -1,21 +1,18 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.amd.compute; -in -{ - options = { - module.amd.compute.enable = mkEnableOption "Enable AMD Rocm support i.e. for Blender."; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.amd.compute; +in { + options.module.amd.compute.enable = lib.mkEnableOption "the AMD Rocm support i.e. for Blender."; - config = mkIf cfg.enable { - nixpkgs.config.rocmSupport = true; - systemd.tmpfiles.rules = [ "L+ /opt/rocm/hip - - - - ${pkgs.rocmPackages.clr}" ]; - hardware.graphics.extraPackages = with pkgs; [ rocmPackages.clr.icd ]; - }; + config = lib.mkIf cfg.enable { + nixpkgs.config.rocmSupport = true; + systemd.tmpfiles.rules = [ "L+ /opt/rocm/hip - - - - ${pkgs.rocmPackages.clr}" ]; + hardware.graphics.extraPackages = with pkgs; [ + rocmPackages.clr.icd + ]; + }; } diff --git a/module/AmdCpu.nix b/module/AmdCpu.nix index 269bf78..61768d5 100644 --- a/module/AmdCpu.nix +++ b/module/AmdCpu.nix @@ -1,37 +1,32 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.amd.cpu; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.amd.cpu; - controlFile = "/sys/devices/system/cpu/cpufreq/boost"; - enableCmd = "0"; - disableCmd = "1"; -in -{ - options = { - module.amd.cpu = { - enable = mkEnableOption "Enable AMD Cpu support."; - powersave = mkEnableOption "Enable AMD Cpu powersave."; - }; - }; + controlFile = "/sys/devices/system/cpu/cpufreq/boost"; + disableCmd = "1"; + enableCmd = "0"; +in { + options.module.amd.cpu = { + enable = lib.mkEnableOption "the AMD Cpu support."; + powersave = lib.mkEnableOption "the AMD Cpu powersave."; + }; - config = mkIf cfg.enable (mkMerge [ - { - boot.kernelModules = [ "kvm-amd" ]; - hardware.cpu.amd.updateMicrocode = mkDefault config.hardware.enableRedistributableFirmware; - } - (mkIf cfg.powersave { - module.powersave = { - enable = true; - cpu.boost = { - inherit controlFile enableCmd disableCmd; - }; - }; - }) - ]); + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + boot.kernelModules = [ "kvm-amd" ]; + hardware.cpu.amd.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware; + } + (lib.mkIf cfg.powersave { + module.powersave = { + enable = true; + cpu.boost = { + inherit controlFile enableCmd disableCmd; + }; + }; + }) + ]); } diff --git a/module/AmdGpu.nix b/module/AmdGpu.nix index 3dd3048..5d92f98 100644 --- a/module/AmdGpu.nix +++ b/module/AmdGpu.nix @@ -1,33 +1,32 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.amd.gpu; -in -{ - options = { - module.amd.gpu.enable = mkEnableOption "Enable AMD Gpu support."; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.amd.gpu; +in { + options.module.amd.gpu.enable = lib.mkEnableOption "the AMD Gpu support."; - config = mkIf cfg.enable { - boot.initrd.kernelModules = [ "amdgpu" ]; - services.xserver.videoDrivers = [ "amdgpu" ]; - hardware.graphics = { - enable = true; - enable32Bit = true; - }; - environment.variables.AMD_VULKAN_ICD = "RADV"; + config = lib.mkIf cfg.enable { + environment.variables.AMD_VULKAN_ICD = "RADV"; + boot.initrd.kernelModules = [ + "amdgpu" + ]; + services.xserver.videoDrivers = [ + "amdgpu" + ]; + hardware.graphics = { + enable = true; + enable32Bit = true; + }; - # AMDVLK was broken for me (huge stuttering). So keep it disabled, at least for now. - # hardware.opengl.extraPackages = with pkgs; [ - # amdvlk - # ]; - # hardware.opengl.extraPackages32 = with pkgs; [ - # driversi686Linux.amdvlk - # ]; - }; + # AMDVLK was broken for me (huge stuttering). So keep it disabled, at least for now. + # hardware.opengl.extraPackages = with pkgs; [ + # amdvlk + # ]; + # hardware.opengl.extraPackages32 = with pkgs; [ + # driversi686Linux.amdvlk + # ]; + }; } diff --git a/module/AutoUpdateSigned.nix b/module/AutoUpdateSigned.nix index 9f7591c..539186c 100644 --- a/module/AutoUpdateSigned.nix +++ b/module/AutoUpdateSigned.nix @@ -3,72 +3,72 @@ # Unlike system.autoUpgrade, this script also verifies my git signature # to prevent unathorized changes to hosts. { - const, - pkgs, - lib, - util, - config, - secret, - ... -}: -with lib; -let - cfg = config.module.autoupdate; -in -{ - options = { - module.autoupdate = { - enable = mkEnableOption "System auto-updates."; - }; - }; + config, + const, + lib, + pkgs, + secret, + util, + ... +}: let + cfg = config.module.autoupdate; +in { + options.module.autoupdate = { + enable = lib.mkEnableOption "the system auto-updates."; + }; - config = mkIf cfg.enable { - programs.git = { - enable = true; - config = { - gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed; - }; - }; + config = lib.mkIf cfg.enable { + programs.git = { + enable = true; + config = { + gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed; + }; + }; - systemd.services.autoupdate = util.mkStaticSystemdService { - enable = true; - description = "Signed system auto-update."; - serviceConfig = { - # RuntimeMaxSec = "55m"; # Doesn't work with oneshot, using timeout bellow. - Type = "oneshot"; - }; - path = with pkgs; [ - bash - coreutils - git - gnumake - nixos-rebuild - openssh - ]; - script = '' - pushd /tmp - rm -rf ./nixos - git clone --depth=1 --single-branch --branch=main ${const.url} ./nixos - pushd ./nixos - git verify-commit HEAD && git fsck || { - echo "Verification failed." - exit 1 - }; - timeout 55m make switch - ''; - after = [ "network-online.target" ]; - wants = [ "network-online.target" ]; - }; + systemd.services.autoupdate = util.mkStaticSystemdService { + enable = true; + description = "Signed system auto-update."; + serviceConfig = { + Type = "oneshot"; + }; + path = with pkgs; [ + bash + coreutils + git + gnumake + nixos-rebuild + openssh + ]; + script = '' + pushd /tmp + rm -rf ./nixos + git clone --depth=1 --single-branch --branch=main ${const.url} ./nixos + pushd ./nixos + git verify-commit HEAD && git fsck || { + echo "Verification failed." + exit 1 + }; + timeout 55m make switch + ''; + after = [ + "network-online.target" + ]; + wants = [ + "network-online.target" + ]; + }; - systemd.timers.autoupdate = { - enable = true; - timerConfig = { - OnCalendar = "hourly"; - Persistent = true; - Unit = "autoupdate.service"; - RandomizedDelaySec = 60; - }; - wantedBy = [ "timers.target" ]; - }; - }; + systemd.timers.autoupdate = { + enable = true; + timerConfig = { + OnCalendar = "hourly"; + Persistent = true; + RandomizedDelaySec = 60; + Unit = "autoupdate.service"; + }; + wantedBy = [ + "timers.target" + ]; + }; + }; } diff --git a/module/Bluetooth.nix b/module/Bluetooth.nix index bbe2dde..64bcce4 100644 --- a/module/Bluetooth.nix +++ b/module/Bluetooth.nix @@ -1,18 +1,17 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.module.desktop.bluetooth; -in { - options = { - module.desktop.bluetooth.enable = mkEnableOption "Bluetooth."; - }; + config, + lib, + ... +}: let + cfg = config.module.desktop.bluetooth; +in { + options.module.desktop.bluetooth.enable = lib.mkEnableOption "the bluetooth support."; - config = mkIf cfg.enable { - hardware.bluetooth = { - enable = true; - powerOnBoot = true; - }; - services.blueman.enable = true; - }; + config = lib.mkIf cfg.enable { + services.blueman.enable = true; + hardware.bluetooth = { + enable = true; + powerOnBoot = true; + }; + }; } diff --git a/module/Brightness.nix b/module/Brightness.nix index c3f2d8a..3272254 100644 --- a/module/Brightness.nix +++ b/module/Brightness.nix @@ -1,12 +1,13 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.module.desktop.brightness; -in { - options = { - module.desktop.brightness.enable = mkEnableOption "Brightness."; - }; + lib, + config, + ... +}: let + cfg = config.module.desktop.brightness; +in { + options.module.desktop.brightness.enable = lib.mkEnableOption "the brightness control."; - config = mkIf cfg.enable { programs.light.enable = true; }; + config = lib.mkIf cfg.enable { + programs.light.enable = true; + }; } diff --git a/module/DisplayManager.nix b/module/DisplayManager.nix index fedc8d1..1c59511 100644 --- a/module/DisplayManager.nix +++ b/module/DisplayManager.nix @@ -1,18 +1,19 @@ -{ config, lib, ... }: -with lib; -let - cfg = config.module.desktop.dm; -in { - options = { - module.desktop.dm.enable = mkEnableOption "Display Manager."; - }; + config, + lib, + ... +}: let + cfg = config.module.desktop.dm; +in { + options.module.desktop.dm.enable = lib.mkEnableOption "the display manager."; - config = mkIf cfg.enable { - services.xserver.enable = true; - services.xserver.xkb = { - layout = config.setting.keyboard.layouts; - options = config.setting.keyboard.options; - }; - }; + config = lib.mkIf cfg.enable { + services.xserver = { + enable = true; + xkb = { + layout = config.module.keyboard.layouts; + options = config.module.keyboard.options; + }; + }; + }; } diff --git a/module/Distrobox.nix b/module/Distrobox.nix index 73f4315..9e68985 100644 --- a/module/Distrobox.nix +++ b/module/Distrobox.nix @@ -1,24 +1,20 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.distrobox; -in -{ - options = { - module.distrobox = { - enable = mkEnableOption "Distrobox."; - }; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.distrobox; +in { + options.module.distrobox = { + enable = lib.mkEnableOption "the distrobox."; + }; - config = mkIf cfg.enable { - # Distrobox works best with Podman, so enable it here. - module.podman.enable = true; - - environment.systemPackages = with pkgs; [ distrobox ]; - }; + config = lib.mkIf cfg.enable { + # Distrobox works best with Podman, so enable it here. + module.podman.enable = true; + environment.systemPackages = with pkgs; [ + distrobox + ]; + }; } diff --git a/module/Docker.nix b/module/Docker.nix index 9b1ea4c..657f925 100644 --- a/module/Docker.nix +++ b/module/Docker.nix @@ -1,45 +1,40 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.module.docker; -in { - options = { - module.docker = { - enable = mkEnableOption "Enable Cocker"; - rootless = mkOption { - default = false; - type = types.bool; - }; - autostart = mkOption { - default = false; - type = types.bool; - }; - }; - }; + lib, + config, + ... +}: let + cfg = config.module.docker; +in { + options.module.docker = { + enable = lib.mkEnableOption "the docker."; + rootless = lib.mkOption { + default = false; + type = lib.types.bool; + }; + autostart = lib.mkOption { + default = false; + type = lib.types.bool; + }; + }; - config = mkIf cfg.enable (mkMerge [ - { - virtualisation.docker.enable = true; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + virtualisation.docker.enable = true; - systemd = - if cfg.autostart then - { } - else - { - services = { - docker-prune.wantedBy = mkForce [ ]; - docker.wantedBy = mkForce [ ]; - }; - sockets.docker.wantedBy = mkForce [ ]; - }; - } + systemd = if cfg.autostart then { } else { + sockets.docker.wantedBy = lib.mkForce [ ]; + services = { + docker-prune.wantedBy = lib.mkForce [ ]; + docker.wantedBy = lib.mkForce [ ]; + }; + }; + } - (mkIf cfg.rootless { - virtualisation.docker.rootless = { - enable = true; - setSocketVariable = true; - }; - }) - ]); + (lib.mkIf cfg.rootless { + virtualisation.docker.rootless = { + enable = true; + setSocketVariable = true; + }; + }) + ]); } diff --git a/module/Dpi.nix b/module/Dpi.nix new file mode 100644 index 0000000..f4d5a1c --- /dev/null +++ b/module/Dpi.nix @@ -0,0 +1,14 @@ +{ + config, + lib, + ... +}: let + cfg = config.module.dpi; +in { + options.module.dpi = { + aware = lib.mkOption { + default = false; + type = lib.types.bool; + }; + }; +} diff --git a/module/Ftpd.nix b/module/Ftpd.nix index bb59670..d938673 100644 --- a/module/Ftpd.nix +++ b/module/Ftpd.nix @@ -1,39 +1,36 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.ftpd; + config, + lib, + pkgs, + util, + ... +}: let + cfg = config.module.ftpd; in -{ - options = { - module.ftpd = { - enable = mkEnableOption "Enable FTP server"; - storage = mkOption { - default = null; - type = types.str; - }; - }; - }; + { + options.module.ftpd = { + enable = lib.mkEnableOption "the FTP server"; + storage = lib.mkOption { + default = null; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - services.vsftpd = { - enable = true; - anonymousUser = true; - anonymousUserNoPassword = true; - anonymousUploadEnable = true; - anonymousMkdirEnable = true; - anonymousUmask = "000"; - anonymousUserHome = cfg.storage; - allowWriteableChroot = true; - writeEnable = true; - localUsers = false; - extraConfig = '' - anon_other_write_enable=YES - ''; - }; - }; + config = lib.mkIf cfg.enable { + services.vsftpd = { + enable = true; + allowWriteableChroot = true; + anonymousMkdirEnable = true; + anonymousUmask = "000"; + anonymousUploadEnable = true; + anonymousUser = true; + anonymousUserHome = cfg.storage; + anonymousUserNoPassword = true; + localUsers = false; + writeEnable = true; + extraConfig = util.trimTabs '' + anon_other_write_enable=YES + ''; + }; + }; } diff --git a/module/Gnome.nix b/module/Gnome.nix index b3a160f..d17e4bb 100644 --- a/module/Gnome.nix +++ b/module/Gnome.nix @@ -1,62 +1,60 @@ +# This is pretty much abandoned module. I keep it just in case. { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.desktop.gnome; -in -{ - options = { - module.desktop.gnome.enable = mkEnableOption "Enable GnOmE"; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.desktop.gnome; +in { + options.module.desktop.gnome.enable = lib.mkEnableOption "the Gnome DE."; - config = mkIf cfg.enable { - module.desktop = { - dm.enable = true; - sound.enable = true; - wayland.enable = true; - }; + config = lib.mkIf cfg.enable { + module.desktop = { + dm.enable = true; + sound.enable = true; + wayland.enable = true; + }; - services.xserver.displayManager.gdm.enable = true; - services.xserver.desktopManager.gnome.enable = true; + services.xserver = { + displayManager.gdm.enable = true; + desktopManager.gnome.enable = true; + }; - environment.systemPackages = with pkgs; [ - gnome.gnome-tweaks # Gnome "hidden" settings. - openssl # It was needed for something, can't remember. - ]; + environment.systemPackages = with pkgs; [ + gnome.gnome-tweaks # Gnome "hidden" settings. + openssl # It was needed for something, can't remember. + ]; - # Disable some Gnome apps. - services.gnome.gnome-keyring.enable = mkForce false; - environment.gnome.excludePackages = with pkgs.gnome; [ - # baobab # Disk usage analyzer. - # cheese # Photo booth. - # epiphany # Web browser. - # simple-scan # Document scanner. - # totem # Video player. - # yelp # Help viewer. - # file-roller # Archive manager. - # geary # Email client. - # seahorse # Password manager. + # Disable some Gnome apps. + services.gnome.gnome-keyring.enable = lib.mkForce false; + environment.gnome.excludePackages = with pkgs.gnome; [ + # baobab # Disk usage analyzer. + # cheese # Photo booth. + # epiphany # Web browser. + # simple-scan # Document scanner. + # totem # Video player. + # yelp # Help viewer. + # file-roller # Archive manager. + # geary # Email client. + # seahorse # Password manager. - # gnome-calculator - # gnome-calendar - # gnome-characters - # gnome-clocks - # gnome-contacts - # gnome-font-viewer - # gnome-keyring - # gnome-logs - # gnome-maps - # gnome-music - # gnome-shell-extensions - gnome-software - # gnome-system-monitor - # gnome-weather - # gnome-disk-utility - # pkgs.gnome-text-editor - ]; - }; + # gnome-calculator + # gnome-calendar + # gnome-characters + # gnome-clocks + # gnome-contacts + # gnome-font-viewer + # gnome-keyring + # gnome-logs + # gnome-maps + # gnome-music + # gnome-shell-extensions + gnome-software + # gnome-system-monitor + # gnome-weather + # gnome-disk-utility + # pkgs.gnome-text-editor + ]; + }; } diff --git a/module/Hwmon.nix b/module/Hwmon.nix new file mode 100644 index 0000000..54ae069 --- /dev/null +++ b/module/Hwmon.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + ... +}: let + cfg = config.module.hwmon; +in { + options.module.hwmon = { + path = lib.mkOption { + default = ""; + type = lib.types.str; + }; + file = lib.mkOption { + default = ""; + type = lib.types.str; + }; + }; +} diff --git a/module/IntelCpu.nix b/module/IntelCpu.nix index 00ac071..e17ff12 100644 --- a/module/IntelCpu.nix +++ b/module/IntelCpu.nix @@ -1,35 +1,34 @@ # Intel CPU specific configuration. { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.intel.cpu; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.intel.cpu; - controlFile = "/sys/devices/system/cpu/intel_pstate/no_turbo"; - enableCmd = "1"; - disableCmd = "0"; -in -{ - options = { - module.intel.cpu = { - enable = mkEnableOption "Support for Shintel CPUs"; - powersave = mkEnableOption "Enable Shintel Cpu powersave."; - }; - }; + controlFile = "/sys/devices/system/cpu/intel_pstate/no_turbo"; + disableCmd = "0"; + enableCmd = "1"; +in { + options.module.intel.cpu = { + enable = lib.mkEnableOption "the support for Intel CPUs"; + powersave = lib.mkEnableOption "the Intel CPU powersave."; + }; - config = mkIf cfg.enable (mkMerge [ - { boot.kernelModules = [ "kvm-intel" ]; } - (mkIf cfg.powersave { - module.powersave = { - enable = true; - cpu.boost = { - inherit controlFile enableCmd disableCmd; - }; - }; - }) - ]); + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + boot.kernelModules = [ + "kvm-intel" + ]; + } + (lib.mkIf cfg.powersave { + module.powersave = { + enable = true; + cpu.boost = { + inherit controlFile enableCmd disableCmd; + }; + }; + }) + ]); } diff --git a/module/Kernel.nix b/module/Kernel.nix index ff03fd7..06bf626 100644 --- a/module/Kernel.nix +++ b/module/Kernel.nix @@ -1,92 +1,91 @@ { - pkgs, - config, - lib, - ... -}: -with lib; -let - cfg = config.module.kernel; -in -{ - options = { - module.kernel = { - enable = mkEnableOption "Enable kernel tweaks."; - hardening = mkOption { - default = false; - type = types.bool; - }; - hotspotTtlBypass = mkOption { - default = false; - type = types.bool; - }; - latest = mkOption { - default = false; - type = types.bool; - }; - }; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.kernel; +in { + options.module.kernel = { + enable = lib.mkEnableOption "the kernel tweaks."; + hardening = lib.mkOption { + default = false; + type = lib.types.bool; + }; + hotspotTtlBypass = lib.mkOption { + default = false; + type = lib.types.bool; + }; + latest = lib.mkOption { + default = false; + type = lib.types.bool; + }; + }; - config = mkIf cfg.enable (mkMerge [ - { - boot.kernel.sysctl = { - # Allow sysrq. - "kernel.sysrq" = 1; + config = lib.mkIf cfg.enable (lib.mkMerge [ + { + boot.kernel.sysctl = { + # Allow sysrq. + "kernel.sysrq" = 1; - # Increase file watchers. - "fs.inotify.max_user_instances" = 9999999; - "fs.inotify.max_user_watches" = 9999999; - "fs.inotify.max_user_event" = 9999999; - # "fs.file-max" = 999999; - }; - } + # Increase file watchers. + "fs.inotify.max_user_event" = 9999999; + "fs.inotify.max_user_instances" = 9999999; + "fs.inotify.max_user_watches" = 9999999; + # "fs.file-max" = 999999; + }; + } - (mkIf cfg.hardening { - boot.kernel.sysctl = { - # Spoof protection. - "net.ipv4.conf.all.rp_filter" = 1; - "net.ipv4.conf.default.rp_filter" = 1; + (lib.mkIf cfg.hardening { + boot.kernel.sysctl = { + # Spoof protection. + "net.ipv4.conf.all.rp_filter" = 1; + "net.ipv4.conf.default.rp_filter" = 1; - # Packet forwarding. - "net.ipv4.ip_forward" = 0; - "net.ipv6.conf.all.forwarding" = 1; + # Packet forwarding. + "net.ipv4.ip_forward" = 0; + "net.ipv6.conf.all.forwarding" = 1; - # MITM protection. - "net.ipv4.conf.all.accept_redirects" = 0; - "net.ipv6.conf.all.accept_redirects" = 0; + # MITM protection. + "net.ipv4.conf.all.accept_redirects" = 0; + "net.ipv6.conf.all.accept_redirects" = 0; - # Do not send ICMP redirects (we are not a router). - "net.ipv4.conf.all.send_redirects" = 0; + # Do not send ICMP redirects (we are not a router). + "net.ipv4.conf.all.send_redirects" = 0; - # Do not accept IP source route packets (we are not a router). - "net.ipv4.conf.all.accept_source_route" = 0; - "net.ipv6.conf.all.accept_source_route" = 0; + # Do not accept IP source route packets (we are not a router). + "net.ipv4.conf.all.accept_source_route" = 0; + "net.ipv6.conf.all.accept_source_route" = 0; - # Protect filesystem links. - "fs.protected_hardlinks" = 0; - "fs.protected_symlinks" = 0; + # Protect filesystem links. + "fs.protected_hardlinks" = 0; + "fs.protected_symlinks" = 0; - # Lynis config. - "kernel.core_uses_pid" = 1; - "kernel.kptr_restrict" = 2; + # Lynis config. + "kernel.core_uses_pid" = 1; + "kernel.kptr_restrict" = 2; - # IP hardening. - "net.ipv4.conf.all.log_martians" = 1; - "net.ipv4.conf.default.accept_redirects" = 0; - "net.ipv4.conf.default.accept_source_route" = 0; - "net.ipv4.conf.default.log_martians" = 0; - "net.ipv4.tcp_timestamps" = 0; - "net.ipv6.conf.default.accept_redirects" = 0; + # IP hardening. + "net.ipv4.conf.all.log_martians" = 1; + "net.ipv4.conf.default.accept_redirects" = 0; + "net.ipv4.conf.default.accept_source_route" = 0; + "net.ipv4.conf.default.log_martians" = 0; + "net.ipv4.tcp_timestamps" = 0; + "net.ipv6.conf.default.accept_redirects" = 0; - # Disable ipv6. - "net.ipv6.conf.all.disable_ipv6" = 1; - "net.ipv6.conf.default.disable_ipv6" = 1; - "net.ipv6.conf.lo.disable_ipv6" = 1; - }; - }) + # Disable ipv6. + "net.ipv6.conf.all.disable_ipv6" = 1; + "net.ipv6.conf.default.disable_ipv6" = 1; + "net.ipv6.conf.lo.disable_ipv6" = 1; + }; + }) - (mkIf cfg.hotspotTtlBypass { boot.kernel.sysctl."net.ipv4.ip_default_ttl" = 65; }) + (lib.mkIf cfg.hotspotTtlBypass { + boot.kernel.sysctl."net.ipv4.ip_default_ttl" = 65; + }) - (mkIf cfg.latest { boot.kernelPackages = pkgs.linuxPackages_latest; }) - ]); + (lib.mkIf cfg.latest { + boot.kernelPackages = pkgs.linuxPackages_latest; + }) + ]); } diff --git a/module/Keyboard.nix b/module/Keyboard.nix new file mode 100644 index 0000000..2d3c88a --- /dev/null +++ b/module/Keyboard.nix @@ -0,0 +1,18 @@ +{ + config, + lib, + ... +}: let + cfg = config.module.keyboard; +in { + options.module.keyboard = { + layouts = lib.mkOption { + default = "us,ru"; + type = lib.types.str; + }; + options = lib.mkOption { + default = "grp:toggle"; + type = lib.types.str; + }; + }; +} diff --git a/module/Keyd.nix b/module/Keyd.nix index c5563ba..dea1f00 100644 --- a/module/Keyd.nix +++ b/module/Keyd.nix @@ -1,103 +1,101 @@ { - pkgs, - config, - lib, - ... -}: -with lib; -let - cfg = config.module.keyd; -in -{ - options = { - module.keyd = { - enable = mkEnableOption "Keyboard remaps."; - }; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.keyd; +in { + options.module.keyd = { + enable = lib.mkEnableOption "the keyboard remaps."; + }; - config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ keyd ]; + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + keyd + ]; - services.keyd = { - enable = true; - keyboards.default = { - ids = [ "*" ]; - settings = { - # NOTE: Use `wev` to find key names. - main = { - backspace = "delete"; # Delete key on backspace. - capslock = "overload(control, esc)"; # Ctrl/esc combo. - compose = "layer(layer_number)"; # Number input layer. - esc = "print"; # System controls. - leftcontrol = "overload(layer_alternative, leftcontrol)"; # Alternative layer for home, end etc. - rightcontrol = "layer(layer_control)"; # Media and other controls. - rightshift = "backspace"; # Backspace. - }; + services.keyd = { + enable = true; + keyboards.default = { + ids = [ "*" ]; + settings = { + # NOTE: Use `wev` to find key names. + main = { + backspace = "delete"; # Delete key on backspace. + capslock = "overload(control, esc)"; # Ctrl/esc combo. + compose = "layer(layer_number)"; # Number input layer. + esc = "print"; # System controls. + leftcontrol = "overload(layer_alternative, leftcontrol)"; # Alternative layer for home, end etc. + rightcontrol = "layer(layer_control)"; # Media and other controls. + rightshift = "backspace"; # Backspace. + }; - # Alternative navigation. - layer_alternative = { - w = "pageup"; - a = "home"; - s = "pagedown"; - d = "end"; - x = "cut"; - c = "copy"; - v = "paste"; - h = "left"; - j = "down"; - k = "up"; - l = "right"; - esc = "esc"; - rightcontrol = "leftcontrol"; - capslock = "capslock"; - # space = "macro2(1, 100, macro(space))"; # NOTE: Possible bhop example. Use in per-application, not here. - }; + # Alternative navigation. + layer_alternative = { + a = "home"; + c = "copy"; + d = "end"; + h = "left"; + j = "down"; + k = "up"; + l = "right"; + s = "pagedown"; + v = "paste"; + w = "pageup"; + x = "cut"; + esc = "esc"; + rightcontrol = "leftcontrol"; + capslock = "capslock"; + }; - # Media controls. - layer_control = { - space = "playpause"; - a = "back"; - c = "ejectcd"; - d = "forward"; - e = "nextsong"; - q = "previoussong"; - s = "volumedown"; - v = "micmute"; - w = "volumeup"; - x = "stopcd"; - z = "mute"; - }; + # Media controls. + layer_control = { + a = "back"; + c = "ejectcd"; + d = "forward"; + e = "nextsong"; + q = "previoussong"; + s = "volumedown"; + v = "micmute"; + w = "volumeup"; + x = "stopcd"; + z = "mute"; + space = "playpause"; + }; - # Number inputs. - layer_number = { - q = "7"; - w = "8"; - e = "9"; - a = "4"; - s = "5"; - d = "6"; - z = "1"; - x = "2"; - c = "3"; - space = "0"; - "1" = "kpequal"; - "2" = "kpslash"; - "3" = "kpasterisk"; - "4" = "kpminus"; - f = "kpenter"; - r = "kpplus"; - v = "kpcomma"; - shift = "backspace"; - }; - }; - }; - }; + # Number inputs. + layer_number = { + "1" = "kpequal"; + "2" = "kpslash"; + "3" = "kpasterisk"; + "4" = "kpminus"; + a = "4"; + c = "3"; + d = "6"; + e = "9"; + f = "kpenter"; + q = "7"; + r = "kpplus"; + s = "5"; + v = "kpcomma"; + w = "8"; + x = "2"; + z = "1"; + shift = "backspace"; + space = "0"; + }; + }; + }; + }; - # HACK: Workaround for https://github.com/NixOS/nixpkgs/issues/290161 - users.groups.keyd = { }; - systemd.services.keyd.serviceConfig.CapabilityBoundingSet = [ "CAP_SETGID" ]; + # HACK: Workaround for https://github.com/NixOS/nixpkgs/issues/290161 + users.groups.keyd = { }; + systemd.services.keyd.serviceConfig.CapabilityBoundingSet = [ + "CAP_SETGID" + ]; - # Debug toggle just in case I need it again. - # systemd.services.keyd.environment.KEYD_DEBUG = "1"; - }; + # Debug toggle just in case I need it again. + # systemd.services.keyd.environment.KEYD_DEBUG = "1"; + }; } diff --git a/module/Ld.nix b/module/Ld.nix deleted file mode 100644 index 6b4d4a1..0000000 --- a/module/Ld.nix +++ /dev/null @@ -1,68 +0,0 @@ -{ pkgs, ... }: -{ - # This thing allow you to run ELF (binary) files just like in other distros. - # The only difference is that we need to specify their linking dependencies - # bellow in `libraries` section. - # programs.nix-ld = { - # enable = true; - # package = pkgs.nix-ld; - # libraries = with pkgs; [ - # # Add any missing dynamic libraries for unpackaged programs here, NOT in environment.systemPackages. - # alsa-lib - # at-spi2-atk - # at-spi2-core - # atk - # cairo - # cups - # curl - # dbus - # expat - # fontconfig - # fontconfig - # freetype - # freetype - # fuse3 - # gdk-pixbuf - # glib - # gtk3 - # icu - # libGL - # libappindicator-gtk3 - # libdrm - # libglvnd - # libglvnd - # libnotify - # libpulseaudio - # libunwind - # libusb1 - # libuuid - # libxkbcommon - # libxml2 - # mesa - # nspr - # nss - # openssl - # pango - # pipewire - # sqlite - # stdenv.cc.cc - # systemd - # vulkan-loader - # xorg.libX11 - # xorg.libXScrnSaver - # xorg.libXcomposite - # xorg.libXcursor - # xorg.libXdamage - # xorg.libXext - # xorg.libXfixes - # xorg.libXi - # xorg.libXrandr - # xorg.libXrender - # xorg.libXtst - # xorg.libxcb - # xorg.libxkbfile - # xorg.libxshmfence - # zlib - # ]; - # }; -} diff --git a/module/Ollama.nix b/module/Ollama.nix index af7f8b0..8011df2 100644 --- a/module/Ollama.nix +++ b/module/Ollama.nix @@ -1,61 +1,66 @@ # SRC: https://github.com/ollama/ollama { - pkgsUnstable, - lib, - config, - ... -}: -let - cfg = config.module.ollama; -in -{ - options = { - module.ollama = { - enable = lib.mkEnableOption "Local LLM server"; - primaryModel = lib.mkOption { - default = "llama3.2"; - type = lib.types.str; - }; - models = lib.mkOption { - default = [ cfg.primaryModel ]; - type = with lib.types; listOf str; - }; - }; - }; + pkgsUnstable, + lib, + config, + util, + ... +}: let + cfg = config.module.ollama; +in { + options.module.ollama = { + enable = lib.mkEnableOption "the local LLM server."; + models = lib.mkOption { + default = [ cfg.primaryModel ]; + type = with lib.types; listOf str; + }; + primaryModel = lib.mkOption { + default = "llama3.2"; + type = lib.types.str; + }; + }; - config = lib.mkIf cfg.enable { - # Specify default model. - environment.variables.OLLAMA_MODEL = cfg.primaryModel; + config = lib.mkIf cfg.enable { + # Specify default model. + environment.variables.OLLAMA_MODEL = cfg.primaryModel; - systemd.services = { - # Enable Ollama server. - ollama = { - description = "Ollama LLM server."; - wantedBy = [ "multi-user.target" ]; - serviceConfig.Type = "simple"; - script = '' - HOME=/root ${lib.getExe pkgsUnstable.ollama} serve - ''; - }; + systemd.services = { + # Enable Ollama server. + ollama = { + description = "Ollama LLM server"; + serviceConfig = { + Type = "simple"; + }; + wantedBy = [ + "multi-user.target" + ]; + script = '' + HOME=/root ${lib.getExe pkgsUnstable.ollama} serve + ''; + }; - # Download Ollama models. - ollama-pull = { - description = "Ollama LLM model."; - wantedBy = [ "multi-user.target" ]; - wants = [ - "NetworkManager-wait-online.service" - "ollama.service" - ]; - after = [ - "NetworkManager-wait-online.service" - "ollama.service" - ]; - serviceConfig.Type = "simple"; - script = '' - sleep 5 - ${lib.getExe pkgsUnstable.ollama} pull ${lib.concatStringsSep " " cfg.models} - ''; - }; - }; - }; + # Download Ollama models. + ollama-pull = { + description = "Ollama LLM model"; + after = [ + "NetworkManager-wait-online.service" + "ollama.service" + ]; + wantedBy = [ + "multi-user.target" + ]; + wants = [ + "NetworkManager-wait-online.service" + "ollama.service" + ]; + serviceConfig = { + Type = "simple"; + }; + script = util.trimTabs '' + sleep 5 + ${lib.getExe pkgsUnstable.ollama} pull ${lib.concatStringsSep " " cfg.models} + ''; + }; + }; + }; } diff --git a/module/Package.nix b/module/Package.nix index 9e2af76..76061d5 100644 --- a/module/Package.nix +++ b/module/Package.nix @@ -1,105 +1,102 @@ { - pkgs, - config, - lib, - __findFile, - ... -}@args: -with lib; -let - cfg = config.module.package; - package = import args; -in -{ - options = { - module.package = { - common.enable = mkEnableOption "Common Apps."; - core.enable = mkEnableOption "Core apps."; - creative.enable = mkEnableOption "Creative Apps."; - desktop.enable = mkEnableOption "Desktop Apps."; - dev.enable = mkEnableOption "Dev Apps."; - extra.enable = mkEnableOption "Extra Apps."; - gaming.enable = mkEnableOption "Gaming Apps."; - }; - }; + __findFile, + config, + lib, + pkgs, + ... +} @args: let + cfg = config.module.package; + package = import args; +in { + options.module.package = { + common.enable = lib.mkEnableOption "Common Apps."; + core.enable = lib.mkEnableOption "Core apps."; + creative.enable = lib.mkEnableOption "Creative Apps."; + desktop.enable = lib.mkEnableOption "Desktop Apps."; + dev.enable = lib.mkEnableOption "Dev Apps."; + extra.enable = lib.mkEnableOption "Extra Apps."; + gaming.enable = lib.mkEnableOption "Gaming Apps."; + }; - config = mkMerge [ - # Core apps. - (mkIf cfg.core.enable { - environment.systemPackages = package.core; + config = lib.mkMerge [ + # Core apps. + (lib.mkIf cfg.core.enable { + environment.systemPackages = package.core; - programs = { - adb.enable = true; - git.enable = true; - java = { - enable = true; - package = pkgs.corretto21; - }; - }; - services = { - udisks2.enable = true; - }; - }) + programs = { + adb.enable = true; + git.enable = true; + java = { + enable = true; + package = pkgs.corretto21; + }; + }; + services = { + udisks2.enable = true; + }; + }) - # Common apps. - (mkIf cfg.common.enable { - environment.systemPackages = package.common; + # Common apps. + (lib.mkIf cfg.common.enable { + environment.systemPackages = package.common; - xdg.mime.defaultApplications = { - # Use `file -i file.txt` to find file mime type. - # Use `xdg-mime query default "text/plain"` to find default app. - "application/pdf" = "org.gnome.Evince.desktop"; - "application/vnd.openxmlformats-officedocument.*" = "onlyoffice-desktopeditors.desktop"; - "audio/*" = "mpv.desktop"; - "image/*" = "org.gnome.Loupe.desktop"; - "text/*" = "nvim.desktop"; - "video/*" = "mpv.desktop"; - }; + xdg.mime.defaultApplications = { + # Use `file -i file.txt` to find file mime type. + # Use `xdg-mime query default "text/plain"` to find default app. + "application/pdf" = "org.gnome.Evince.desktop"; + "application/vnd.openxmlformats-officedocument.*" = "onlyoffice-desktopeditors.desktop"; + "audio/*" = "mpv.desktop"; + "image/*" = "org.gnome.Loupe.desktop"; + "text/*" = "nvim.desktop"; + "video/*" = "mpv.desktop"; + }; - services.gvfs.enable = true; + services.gvfs.enable = true; - # Chromium config. - environment.etc = - let - chromium = import args; - in - { - "chromium/initial_preferences".source = lib.mkForce chromium.preferences; - "chromium/policies/managed/extra.json".source = lib.mkForce chromium.policy; - }; - }) + # Chromium config. + environment.etc = let + chromium = import args; + in { + "chromium/initial_preferences".source = lib.mkForce chromium.preferences; + "chromium/policies/managed/extra.json".source = lib.mkForce chromium.policy; + }; + }) - # Desktop apps. - (mkIf cfg.desktop.enable { environment.systemPackages = package.desktop; }) + # Desktop apps. + (lib.mkIf cfg.desktop.enable { + environment.systemPackages = package.desktop; + }) - # Gaming. - (mkIf cfg.gaming.enable { - hardware.graphics = - let - packages = with pkgs; [ - dxvk - gamescope - pkgs.mangohud - vkd3d - ]; - in - { - extraPackages = packages; - extraPackages32 = packages; - }; + # Gaming. + (lib.mkIf cfg.gaming.enable { + programs.steam.enable = true; + environment.systemPackages = package.gaming; + hardware.graphics = let + packages = with pkgs; [ + dxvk + gamescope + pkgs.mangohud + vkd3d + ]; + in { + extraPackages = packages; + extraPackages32 = packages; + }; + }) - programs.steam.enable = true; + # Creative. + (lib.mkIf cfg.creative.enable { + environment.systemPackages = package.creative; + }) - environment.systemPackages = package.gaming; - }) + # Development. + (lib.mkIf cfg.dev.enable { + environment.systemPackages = package.dev; + }) - # Creative. - (mkIf cfg.creative.enable { environment.systemPackages = package.creative; }) - - # Development. - (mkIf cfg.dev.enable { environment.systemPackages = package.dev; }) - - # Extras. - (mkIf cfg.extra.enable { environment.systemPackages = package.extra; }) - ]; + # Extras. + (lib.mkIf cfg.extra.enable { + environment.systemPackages = package.extra; + }) + ]; } diff --git a/module/Podman.nix b/module/Podman.nix index c0317a3..614b4ad 100644 --- a/module/Podman.nix +++ b/module/Podman.nix @@ -1,27 +1,24 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.module.podman; -in { - options = { - module.podman = { - enable = mkEnableOption "OCI Podman."; - }; - }; + lib, + config, + ... +}: let + cfg = config.module.podman; +in { + options.module.podman = { + enable = lib.mkEnableOption "the OCI Podman."; + }; - config = mkIf cfg.enable { - virtualisation = { - podman = { - enable = true; + config = lib.mkIf cfg.enable { + virtualisation.podman = { + enable = true; - # Free the 53 port ffs. - defaultNetwork.settings.dns_enabled = false; + # Free the 53 port ffs. + defaultNetwork.settings.dns_enabled = false; - # Do not interfere with Docker so we can have both installed at the same time. - # Podman can't replace Docker anyway. - dockerCompat = false; - }; - }; - }; + # Do not interfere with Docker so we can have both installed at the same time. + # Podman can't replace Docker anyway. + dockerCompat = false; + }; + }; } diff --git a/module/Polkit.nix b/module/Polkit.nix index d4143cc..c27006b 100644 --- a/module/Polkit.nix +++ b/module/Polkit.nix @@ -1,34 +1,33 @@ # Polkit agent is used by apps to ask for Root password with a popup. { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.desktop.polkit; -in -{ - options = { - module.desktop.polkit.enable = mkEnableOption "Polkit."; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.desktop.polkit; +in { + options.module.desktop.polkit.enable = lib.mkEnableOption "the polkit."; - config = mkIf cfg.enable { - security.polkit.enable = true; - systemd = { - packages = with pkgs; [ polkit-kde-agent ]; - user = { - services.plasma-polkit-agent = { - serviceConfig = { - Restart = "always"; - RestartSec = 2; - Slice = "session.slice"; - }; - environment.PATH = mkForce null; - wantedBy = [ "gui-session.target" ]; - }; - }; - }; - }; + config = lib.mkIf cfg.enable { + security.polkit.enable = true; + systemd = { + packages = with pkgs; [ + polkit-kde-agent + ]; + user = { + services.plasma-polkit-agent = { + environment.PATH = lib.mkForce null; + serviceConfig = { + Restart = "always"; + RestartSec = 2; + Slice = "session.slice"; + }; + wantedBy = [ + "gui-session.target" + ]; + }; + }; + }; + }; } diff --git a/module/Portal.nix b/module/Portal.nix index b9c236b..56cdeab 100644 --- a/module/Portal.nix +++ b/module/Portal.nix @@ -1,33 +1,26 @@ # Portals are needed for Wayland apps to select files, screen shares etc. { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.desktop.portal; -in -{ - options = { - module.desktop.portal.enable = mkEnableOption "Portals."; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.desktop.portal; +in { + options.module.desktop.portal.enable = lib.mkEnableOption "the portals."; - config = mkIf cfg.enable { - xdg.portal = { - enable = true; - extraPortals = with pkgs; [ xdg-desktop-portal-gtk ]; - config = { - common = { - default = [ - "gtk" - "wlr" - ]; - }; - }; - wlr.enable = true; - xdgOpenUsePortal = false; - }; - }; + config = lib.mkIf cfg.enable { + xdg.portal = { + enable = true; + wlr.enable = true; + xdgOpenUsePortal = false; + extraPortals = with pkgs; [ + xdg-desktop-portal-gtk + ]; + config.common.default = [ + "gtk" + "wlr" + ]; + }; + }; } diff --git a/module/PowerlimitThinkpad.nix b/module/PowerlimitThinkpad.nix index 2c0ff0b..11bcb75 100644 --- a/module/PowerlimitThinkpad.nix +++ b/module/PowerlimitThinkpad.nix @@ -1,88 +1,88 @@ # ThinkPad charge limits. { - pkgs, - lib, - config, - ... -}@args: -with lib; -let - cfg = config.module.powerlimit.thinkpad; + config, + lib, + pkgs, + util, + ... +}: let + cfg = config.module.powerlimit.thinkpad; - controlFileMin = "/sys/class/power_supply/BAT0/charge_control_start_threshold"; - controlFileMax = "/sys/class/power_supply/BAT0/charge_control_end_threshold"; + controlFileMax = "/sys/class/power_supply/BAT0/charge_control_end_threshold"; + controlFileMin = "/sys/class/power_supply/BAT0/charge_control_start_threshold"; - script = pkgs.writeShellScriptBin "powerlimit" '' - function toggle() { - if status; then - echo ${toString cfg.offMax} > ${controlFileMax} - echo ${toString cfg.offMin} > ${controlFileMin} - else - echo ${toString cfg.onMin} > ${controlFileMin} - echo ${toString cfg.onMax} > ${controlFileMax} - fi + script = pkgs.writeShellScriptBin "powerlimit" (util.trimTabs '' + function toggle() { + if status; then + echo ${toString cfg.offMax} > ${controlFileMax} + echo ${toString cfg.offMin} > ${controlFileMin} + else + echo ${toString cfg.onMin} > ${controlFileMin} + echo ${toString cfg.onMax} > ${controlFileMax} + fi - pkill -RTMIN+6 waybar - true - } + pkill -RTMIN+6 waybar + true + } - function widget() { - status && printf '​' || printf '' - } + function widget() { + status && printf '​' || printf '' + } - function status() { - local current=$(cat ${controlFileMax}) - local enabled="${toString cfg.onMax}" + function status() { + local current=$(cat ${controlFileMax}) + local enabled="${toString cfg.onMax}" - [[ "''${current}" = "''${enabled}" ]] - } + [[ "''${current}" = "''${enabled}" ]] + } - ''${@} - ''; -in -{ - options = { - module.powerlimit.thinkpad = { - enable = mkEnableOption "Powerlimit Service"; - onMin = mkOption { - default = 40; - type = types.int; - }; - onMax = mkOption { - default = 80; - type = types.int; - }; - offMin = mkOption { - default = 90; - type = types.int; - }; - offMax = mkOption { - default = 95; - type = types.int; - }; - }; - }; + ''${@} + ''); +in { + options.module.powerlimit.thinkpad = { + enable = lib.mkEnableOption "the powerlimit service"; + onMin = lib.mkOption { + default = 40; + type = lib.types.int; + }; + onMax = lib.mkOption { + default = 80; + type = lib.types.int; + }; + offMin = lib.mkOption { + default = 90; + type = lib.types.int; + }; + offMax = lib.mkOption { + default = 95; + type = lib.types.int; + }; + }; - config = mkIf cfg.enable { - environment.systemPackages = [ script ]; - systemd = { - services.powerlimit = { - description = "Limit battery charge."; - enable = true; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "simple"; - RemainAfterExit = "yes"; - ExecStart = "${getExe pkgs.bash} -c 'echo ${toString cfg.onMin} > ${controlFileMin}; echo ${toString cfg.onMax} > ${controlFileMax};'"; - ExecStop = "${getExe pkgs.bash} -c 'echo ${toString cfg.offMax} > ${controlFileMax}; echo ${toString cfg.offMin} > ${controlFileMin};'"; - }; - }; + config = lib.mkIf cfg.enable { + environment.systemPackages = [ + script + ]; + systemd = { + services.powerlimit = { + enable = true; + description = "Limit battery charge"; + wantedBy = [ + "multi-user.target" + ]; + serviceConfig = { + Type = "simple"; + RemainAfterExit = "yes"; + ExecStart = "${lib.getExe pkgs.bash} -c 'echo ${toString cfg.onMin} > ${controlFileMin}; echo ${toString cfg.onMax} > ${controlFileMax};'"; + ExecStop = "${lib.getExe pkgs.bash} -c 'echo ${toString cfg.offMax} > ${controlFileMax}; echo ${toString cfg.offMin} > ${controlFileMin};'"; + }; + }; - # HACK: Allow user access. - tmpfiles.rules = [ - "z ${controlFileMax} 0777 - - - -" - "z ${controlFileMin} 0777 - - - -" - ]; - }; - }; + # HACK: Allow user access. + tmpfiles.rules = [ + "z ${controlFileMax} 0777 - - - -" + "z ${controlFileMin} 0777 - - - -" + ]; + }; + }; } diff --git a/module/Powersave.nix b/module/Powersave.nix index cb672b5..ad20065 100644 --- a/module/Powersave.nix +++ b/module/Powersave.nix @@ -1,82 +1,79 @@ { - lib, - config, - pkgs, - ... -}: -with lib; -let - cfg = config.module.powersave; + lib, + config, + pkgs, + util, + ... +}: let + cfg = config.module.powersave; - script = pkgs.writeShellScriptBin "powersave" '' - function toggle() { - if status; then - echo ${cfg.cpu.boost.disableCmd} > ${cfg.cpu.boost.controlFile} - else - echo ${cfg.cpu.boost.enableCmd} > ${cfg.cpu.boost.controlFile} - fi + script = pkgs.writeShellScriptBin "powersave" (util.trimTabs '' + function toggle() { + if status; then + echo ${cfg.cpu.boost.disableCmd} > ${cfg.cpu.boost.controlFile} + else + echo ${cfg.cpu.boost.enableCmd} > ${cfg.cpu.boost.controlFile} + fi - pkill -RTMIN+5 waybar - true - } + pkill -RTMIN+5 waybar + true + } - function widget() { - status && printf '​' || printf '󰓅' - } + function widget() { + status && printf '​' || printf '󰓅' + } - function status() { - local current=$(cat ${cfg.cpu.boost.controlFile}) - local enabled="${cfg.cpu.boost.enableCmd}" + function status() { + local current=$(cat ${cfg.cpu.boost.controlFile}) + local enabled="${cfg.cpu.boost.enableCmd}" - [[ "''${current}" = "''${enabled}" ]] - } + [[ "''${current}" = "''${enabled}" ]] + } - ''${@} - ''; -in -{ - options = { - module.powersave = { - enable = mkEnableOption "Powersave"; - cpu.boost = mkOption { - default = { }; - type = types.submodule { - options = { - disableCmd = mkOption { - default = null; - type = types.str; - }; - enableCmd = mkOption { - default = null; - type = types.str; - }; - controlFile = mkOption { - default = null; - type = types.str; - }; - }; - }; - }; - }; - }; + ''${@} + ''); +in { + options.module.powersave = { + enable = lib.mkEnableOption "the powersave"; + cpu.boost = { + disableCmd = lib.mkOption { + default = null; + type = lib.types.str; + }; + enableCmd = lib.mkOption { + default = null; + type = lib.types.str; + }; + controlFile = lib.mkOption { + default = null; + type = lib.types.str; + }; + }; + }; - config = mkIf cfg.enable { - environment.systemPackages = [ script ]; - systemd = { - services.powersave-cpu = { - description = "Disable CPU Boost"; - enable = true; - wantedBy = [ "multi-user.target" ]; - serviceConfig = { - Type = "simple"; - RemainAfterExit = "yes"; - ExecStart = "${getExe pkgs.bash} -c 'echo ${cfg.cpu.boost.enableCmd} > ${cfg.cpu.boost.controlFile}'"; - ExecStop = "${getExe pkgs.bash} -c 'echo ${cfg.cpu.boost.disableCmd} > ${cfg.cpu.boost.controlFile}'"; - }; - }; + config = lib.mkIf cfg.enable { + environment.systemPackages = [ + script + ]; + systemd = { + services.powersave-cpu = { + enable = true; + description = "disable CPU Boost"; + wantedBy = [ + "multi-user.target" + ]; + serviceConfig = { + Type = "simple"; + RemainAfterExit = "yes"; + ExecStart = "${lib.getExe pkgs.bash} -c 'echo ${cfg.cpu.boost.enableCmd} > ${cfg.cpu.boost.controlFile}'"; + ExecStop = "${lib.getExe pkgs.bash} -c 'echo ${cfg.cpu.boost.disableCmd} > ${cfg.cpu.boost.controlFile}'"; + }; + }; - # HACK: Allow user access. - tmpfiles.rules = [ "z ${cfg.cpu.boost.controlFile} 0777 - - - -" ]; - }; - }; + # HACK: Allow user access. + tmpfiles.rules = [ + "z ${cfg.cpu.boost.controlFile} 0777 - - - -" + ]; + }; + }; } diff --git a/module/Print.nix b/module/Print.nix index 73fec70..170d7cb 100644 --- a/module/Print.nix +++ b/module/Print.nix @@ -1,25 +1,21 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.print; -in -{ - options = { - module.print.enable = mkEnableOption "Add support for printers."; - }; + config, + lib, + pkgs, + util, + ... +}: let + cfg = config.module.print; +in { + options.module.print.enable = lib.mkEnableOption "the support for printers."; - config = mkIf cfg.enable { - services.printing = { - enable = true; - clientConf = '' - DigestOptions DenyMD5 - ServerName 10.0.0.1 - ''; - }; - }; + config = lib.mkIf cfg.enable { + services.printing = { + enable = true; + clientConf = util.trimTabs '' + DigestOptions DenyMD5 + ServerName 10.0.0.1 + ''; + }; + }; } diff --git a/module/Realtime.nix b/module/Realtime.nix index bc790aa..fbeb1ca 100644 --- a/module/Realtime.nix +++ b/module/Realtime.nix @@ -1,22 +1,19 @@ # Improve DE performance. -{ lib, config, ... }: -with lib; -let - cfg = config.module.realtime; -in { - options = { - module.realtime.enable = mkEnableOption "Realtime access."; - }; + lib, + config, + ... +}: let + cfg = config.module.realtime; +in { + options.module.realtime.enable = lib.mkEnableOption "the realtime access."; - config = mkIf cfg.enable { - security.pam.loginLimits = [ - { - domain = "@users"; - item = "rtprio"; - type = "-"; - value = 1; - } - ]; - }; + config = lib.mkIf cfg.enable { + security.pam.loginLimits = [{ + domain = "@users"; + item = "rtprio"; + type = "-"; + value = 1; + }]; + }; } diff --git a/module/RemoteBuild.nix b/module/RemoteBuild.nix index 49b9b27..4ecc0ce 100644 --- a/module/RemoteBuild.nix +++ b/module/RemoteBuild.nix @@ -1,102 +1,111 @@ { - pkgs, - lib, - config, - secret, - ... -}: -with lib; -let - cfg = config.module.builder; - serverKeyPath = "/root/.nixbuilder"; - serverSshPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFqr7zKGOy/2bbAQCD85Ol+NoGGtvdMbSy3jGb98jM+f"; # Use ssh-keyscan. -in -{ - options = { - module.builder = { - server.enable = mkEnableOption "This is a builder server."; - client.enable = mkEnableOption "This is a builder client."; - }; - }; + config, + lib, + pkgs, + secret, + ... +}: let + cfg = config.module.builder; + serverKeyPath = "/root/.nixbuilder"; + serverSshPublicKey = "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFqr7zKGOy/2bbAQCD85Ol+NoGGtvdMbSy3jGb98jM+f"; # Use ssh-keyscan. +in { + options.module.builder = { + server.enable = lib.mkEnableOption "the builder server."; + client.enable = lib.mkEnableOption "the builder client."; + }; - config = mkMerge [ - (mkIf cfg.server.enable { - # Service that generates new key on boot if not present. - # Don't forget to add new public key to secret.ssh.buildKeys. - systemd.services.generate-nix-cache-key = { - wantedBy = [ "multi-user.target" ]; - serviceConfig.Type = "oneshot"; - path = [ pkgs.nix ]; - script = '' - [[ -f "${serverKeyPath}/private-key" ]] && exit - mkdir ${serverKeyPath} || true - nix-store --generate-binary-cache-key "nixbuilder-1" "${serverKeyPath}/private-key" "${serverKeyPath}/public-key" - nix store sign --all -k "${serverKeyPath}/private-key" - ''; - }; + config = lib.mkMerge [ + (lib.mkIf cfg.server.enable { + # Service that generates new key on boot if not present. + # Don't forget to add new public key to secret.ssh.buildKeys. + systemd.services.generate-nix-cache-key = { + wantedBy = [ + "multi-user.target" + ]; + serviceConfig = { + Type = "oneshot"; + }; + path = [ + pkgs.nix + ]; + script = '' + [[ -f "${serverKeyPath}/private-key" ]] && exit + mkdir ${serverKeyPath} || true + nix-store --generate-binary-cache-key "nixbuilder-1" "${serverKeyPath}/private-key" "${serverKeyPath}/public-key" + nix store sign --all -k "${serverKeyPath}/private-key" + ''; + }; - # Add `nixbuilder` restricted user. - users.groups.nixbuilder = { }; - users.users.nixbuilder = { - openssh.authorizedKeys.keys = secret.ssh.buildKeys; - description = "Nix Remote Builder"; - isNormalUser = true; - createHome = lib.mkForce false; - uid = 1234; - home = "/"; - group = "nixbuilder"; - }; + # Add `nixbuilder` restricted user. + users.groups.nixbuilder = { }; + users.users.nixbuilder = { + createHome = lib.mkForce false; + description = "Nix Remote Builder"; + group = "nixbuilder"; + home = "/"; + isNormalUser = true; + openssh.authorizedKeys.keys = secret.ssh.buildKeys; + uid = 1234; + }; - # Sign store automatically. - # Sign existing store with: nix store sign --all -k /path/to/secret-key-file - nix.settings = { - trusted-users = [ "nixbuilder" ]; - secret-key-files = [ "${serverKeyPath}/private-key" ]; - }; - }) + # Sign store automatically. + # Sign existing store with: nix store sign --all -k /path/to/secret-key-file + nix.settings = { + trusted-users = [ + "nixbuilder" + ]; + secret-key-files = [ + "${serverKeyPath}/private-key" + ]; + }; + }) - (mkIf cfg.client.enable { - # NOTE: Requires host public key to be present in secret.ssh.builderKeys. - nix = { - distributedBuilds = true; - buildMachines = [ - { - hostName = "nixbuilder"; - protocol = "ssh-ng"; - systems = [ - "x86_64-linux" - "i686-linux" - "aarch64-linux" - ]; - maxJobs = 16; - speedFactor = 2; - mandatoryFeatures = [ ]; - supportedFeatures = [ - "nixos-test" - "benchmark" - "big-parallel" - "kvm" - ]; - } - ]; - settings = - let - substituters = [ "ssh-ng://nixbuilder" ]; - in - { - substituters = mkForce substituters; - trusted-substituters = substituters ++ [ "https://cache.nixos.org/" ]; - builders-use-substitutes = true; - max-jobs = 0; - trusted-public-keys = [ secret.ssh.builderKey ]; - # require-sigs = false; - # substitute = false; - }; - }; - services.openssh.knownHosts.nixbuilder = { - publicKey = serverSshPublicKey; - extraHostNames = [ "[10.0.0.1]:22143" ]; - }; - }) - ]; + (lib.mkIf cfg.client.enable { + # NOTE: Requires host public key to be present in secret.ssh.builderKeys. + nix = { + distributedBuilds = true; + buildMachines = [{ + hostName = "nixbuilder"; + maxJobs = 16; + protocol = "ssh-ng"; + speedFactor = 2; + mandatoryFeatures = [ ]; + systems = [ + "aarch64-linux" + "i686-linux" + "x86_64-linux" + ]; + supportedFeatures = [ + "benchmark" + "big-parallel" + "kvm" + "nixos-test" + ]; + }]; + settings = let + substituters = [ + "ssh-ng://nixbuilder" + ]; + in { + builders-use-substitutes = true; + max-jobs = 0; + substituters = lib.mkForce substituters; + trusted-substituters = substituters ++ [ + "https://cache.nixos.org/" + ]; + trusted-public-keys = [ + secret.ssh.builderKey + ]; + # require-sigs = false; + # substitute = false; + }; + }; + services.openssh.knownHosts.nixbuilder = { + publicKey = serverSshPublicKey; + extraHostNames = [ + "[10.0.0.1]:22143" + ]; + }; + }) + ]; } diff --git a/module/Sound.nix b/module/Sound.nix index 09a12d0..b345236 100644 --- a/module/Sound.nix +++ b/module/Sound.nix @@ -1,23 +1,22 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.module.desktop.sound; -in { - options = { - module.desktop.sound.enable = mkEnableOption "Sound."; - }; + config, + lib, + ... +}: let + cfg = config.module.desktop.sound; +in { + options.module.desktop.sound.enable = lib.mkEnableOption "the sound."; - config = mkIf cfg.enable { - hardware.pulseaudio.enable = false; - security.rtkit.enable = true; - services.pipewire = { - enable = true; - pulse.enable = true; - alsa = { - enable = true; - support32Bit = true; - }; - }; - }; + config = lib.mkIf cfg.enable { + hardware.pulseaudio.enable = false; + security.rtkit.enable = true; + services.pipewire = { + enable = true; + pulse.enable = true; + alsa = { + enable = true; + support32Bit = true; + }; + }; + }; } diff --git a/module/Style.nix b/module/Style.nix new file mode 100644 index 0000000..a176a66 --- /dev/null +++ b/module/Style.nix @@ -0,0 +1,115 @@ +{ + __findFile, + config, + lib, + pkgs, + ... +}: let + cfg = config.module.style; + + mkTypeOption = default: type: lib.mkOption { inherit default type; }; + mkFloatOption = default: mkTypeOption default lib.types.float; + mkIntOption = default: mkTypeOption default lib.types.int; + mkPkgOption = default: mkTypeOption default lib.types.package; + mkStrOption = default: mkTypeOption default lib.types.str; +in { + options.module.style = { + color = { + accent = mkStrOption config.lib.stylix.colors.base0A; + heading = mkStrOption config.lib.stylix.colors.base0D; + hl = mkStrOption config.lib.stylix.colors.base03; + keyword = mkStrOption config.lib.stylix.colors.base0E; + link = mkStrOption config.lib.stylix.colors.base09; + misc = mkStrOption config.lib.stylix.colors.base0F; + negative = mkStrOption config.lib.stylix.colors.base08; + neutral = mkStrOption config.lib.stylix.colors.base0C; + positive = mkStrOption config.lib.stylix.colors.base0B; + selection = mkStrOption config.lib.stylix.colors.base02; + bg = { + dark = mkStrOption config.lib.stylix.colors.base00; + light = mkStrOption config.lib.stylix.colors.base07; + regular = mkStrOption config.lib.stylix.colors.base01; + }; + fg = { + dark = mkStrOption config.lib.stylix.colors.base04; + light = mkStrOption config.lib.stylix.colors.base06; + regular = mkStrOption config.lib.stylix.colors.base05; + }; + + accent-r = mkStrOption config.lib.stylix.colors.base0A-rgb-r; + accent-g = mkStrOption config.lib.stylix.colors.base0A-rgb-g; + accent-b = mkStrOption config.lib.stylix.colors.base0A-rgb-b; + + bg-r = mkStrOption config.lib.stylix.colors.base00-rgb-r; + bg-g = mkStrOption config.lib.stylix.colors.base00-rgb-g; + bg-b = mkStrOption config.lib.stylix.colors.base00-rgb-b; + + border = mkStrOption config.lib.stylix.colors.base01; + border-r = mkStrOption config.lib.stylix.colors.base01-rgb-r; + border-g = mkStrOption config.lib.stylix.colors.base01-rgb-g; + border-b = mkStrOption config.lib.stylix.colors.base01-rgb-b; + + fg-r = mkStrOption config.lib.stylix.colors.base06-rgb-r; + fg-g = mkStrOption config.lib.stylix.colors.base06-rgb-g; + fg-b = mkStrOption config.lib.stylix.colors.base06-rgb-b; + + negative-r = mkStrOption config.lib.stylix.colors.base08-rgb-r; + negative-g = mkStrOption config.lib.stylix.colors.base08-rgb-g; + negative-b = mkStrOption config.lib.stylix.colors.base08-rgb-b; + + neutral-r = mkStrOption config.lib.stylix.colors.base0C-rgb-r; + neutral-g = mkStrOption config.lib.stylix.colors.base0C-rgb-g; + neutral-b = mkStrOption config.lib.stylix.colors.base0C-rgb-b; + + positive-r = mkStrOption config.lib.stylix.colors.base0B-rgb-r; + positive-g = mkStrOption config.lib.stylix.colors.base0B-rgb-g; + positive-b = mkStrOption config.lib.stylix.colors.base0B-rgb-b; + + transparent = mkStrOption "ffffff00"; + }; + + cursor = { + name = mkStrOption "phinger-cursors-light"; + package = mkPkgOption pkgs.phinger-cursors; + size = mkIntOption 24; + }; + + font = { + emoji = { + name = mkStrOption "Noto Color Emoji"; + package = mkPkgOption pkgs.noto-fonts-emoji; + }; + monospace = { + name = mkStrOption "Terminess Nerd Font Mono"; + package = mkPkgOption (pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }); + }; + sansSerif = { + name = mkStrOption "SF Pro Display"; + package = mkPkgOption (pkgs.callPackage { }); + }; + serif = { + name = mkStrOption "SF Pro Display"; + package = mkPkgOption (pkgs.callPackage { }); + }; + size = { + application = mkIntOption 12; + desktop = mkIntOption 14; + popup = mkIntOption 12; + terminal = mkIntOption 14; + }; + }; + + opacity = { + application = mkFloatOption 0.85; + desktop = mkFloatOption 0.85; + hex = mkStrOption "D9"; + popup = mkFloatOption 0.85; + terminal = mkFloatOption 0.85; + }; + + window = { + border = mkIntOption 4; + gap = mkIntOption 8; + }; + }; +} diff --git a/module/Sway.nix b/module/Sway.nix index f96b6e2..cae4b6f 100644 --- a/module/Sway.nix +++ b/module/Sway.nix @@ -1,47 +1,42 @@ { - lib, - config, - pkgs, - ... -}: -with lib; -let - cfg = config.module.desktop.sway; -in -{ - options = { - module.desktop.sway = { - enable = mkEnableOption "Use Sway WM."; - extraConfig = mkOption { - default = ""; - type = types.str; - }; - }; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.desktop.sway; +in { + options.module.desktop.sway = { + enable = lib.mkEnableOption "the Sway WM."; + extraConfig = lib.mkOption { + default = ""; + type = lib.types.str; + }; + }; - config = mkIf cfg.enable { - module = { - desktop = { - bluetooth.enable = true; - brightness.enable = true; - portal.enable = true; - sound.enable = true; - waybar.enable = true; - wayland.enable = true; - }; - realtime.enable = true; - }; - - services.gnome.gnome-keyring.enable = mkForce false; - environment.variables.XDG_CURRENT_DESKTOP = "sway"; - - programs.sway = { - enable = true; - wrapperFeatures = { - base = true; - gtk = true; - }; - extraPackages = with pkgs; [ swaykbdd ]; - }; - }; + config = lib.mkIf cfg.enable { + services.gnome.gnome-keyring.enable = lib.mkForce false; + environment.variables.XDG_CURRENT_DESKTOP = "sway"; + module = { + desktop = { + bluetooth.enable = true; + brightness.enable = true; + portal.enable = true; + sound.enable = true; + waybar.enable = true; + wayland.enable = true; + }; + realtime.enable = true; + }; + programs.sway = { + enable = true; + wrapperFeatures = { + base = true; + gtk = true; + }; + extraPackages = with pkgs; [ + swaykbdd + ]; + }; + }; } diff --git a/module/Tablet.nix b/module/Tablet.nix index 803369a..f9a7efb 100644 --- a/module/Tablet.nix +++ b/module/Tablet.nix @@ -1,15 +1,16 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.module.tablet; -in { - options = { - module.tablet.enable = mkEnableOption "Support for tables."; - }; + lib, + config, + ... +}: let + cfg = config.module.tablet; +in { + options.module.tablet.enable = lib.mkEnableOption "the support for tables."; - config = mkIf cfg.enable { - hardware.opentabletdriver.enable = true; - systemd.user.services.opentabletdriver.wantedBy = [ "default.target" ]; - }; + config = lib.mkIf cfg.enable { + hardware.opentabletdriver.enable = true; + systemd.user.services.opentabletdriver.wantedBy = [ + "default.target" + ]; + }; } diff --git a/module/VirtManager.nix b/module/VirtManager.nix index a14ef63..08f0c3c 100644 --- a/module/VirtManager.nix +++ b/module/VirtManager.nix @@ -1,27 +1,22 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.virtmanager; -in -{ - options = { - module.virtmanager.enable = mkEnableOption "VM support."; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.virtmanager; +in { + options.module.virtmanager.enable = lib.mkEnableOption "the VM support."; - config = mkIf cfg.enable { - virtualisation.libvirtd.enable = true; - programs.virt-manager.enable = true; + config = lib.mkIf cfg.enable { + virtualisation.libvirtd.enable = true; + programs.virt-manager.enable = true; - # HACK: Fixes bug: https://www.reddit.com/r/NixOS/comments/1afbjiu/i_get_a_nonetype_error_when_trying_to_launch_a_vm/ - # May also need to run: `gsettings set org.gnome.desktop.interface cursor-theme "Adwaita"` - environment.systemPackages = with pkgs; [ - # glib - adwaita-icon-theme # default gnome cursors, - ]; - }; + # HACK: Fixes bug: https://www.reddit.com/r/NixOS/comments/1afbjiu/i_get_a_nonetype_error_when_trying_to_launch_a_vm/ + # May also need to run: `gsettings set org.gnome.desktop.interface cursor-theme "Adwaita"` + environment.systemPackages = with pkgs; [ + # glib + adwaita-icon-theme # default gnome cursors, + ]; + }; } diff --git a/module/Wallpaper.nix b/module/Wallpaper.nix new file mode 100644 index 0000000..e0ed1db --- /dev/null +++ b/module/Wallpaper.nix @@ -0,0 +1,20 @@ +{ + pkgs, + lib, + ... +}: let + url = "https://i.imgur.com/yuZ2XSf.jpeg"; + sha256 = "sha256-Z35D7gn28d2dtPHHVwzySOingy/d8CWKmK9LQjpyjEk="; + forceContrastText = false; +in { + options.module.wallpaper = { + forceContrastText = lib.mkOption { + default = lib.warnIf forceContrastText "Wallpaper: Forced text contrast." forceContrastText; + type = lib.types.bool; + }; + path = lib.mkOption { + default = pkgs.fetchurl { inherit url sha256; }; + type = lib.types.path; + }; + }; +} diff --git a/module/Waybar.nix b/module/Waybar.nix index f443ec9..8ec87e9 100644 --- a/module/Waybar.nix +++ b/module/Waybar.nix @@ -1,19 +1,16 @@ { - lib, - config, - pkgs, - ... -}: -with lib; -let - cfg = config.module.desktop.waybar; -in -{ - options = { - module.desktop.waybar = { - enable = mkEnableOption "Use Waybar."; - }; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.desktop.waybar; +in { + options.module.desktop.waybar.enable = lib.mkEnableOption "the Waybar."; - config = mkIf cfg.enable { environment.systemPackages = with pkgs; [ waybar ]; }; + config = lib.mkIf cfg.enable { + environment.systemPackages = with pkgs; [ + waybar + ]; + }; } diff --git a/module/Wayland.nix b/module/Wayland.nix index 3c440ef..390891c 100644 --- a/module/Wayland.nix +++ b/module/Wayland.nix @@ -1,38 +1,31 @@ { - pkgs, - lib, - config, - ... -}: -with lib; -let - cfg = config.module.desktop.wayland; -in -{ - options = { - module.desktop.wayland.enable = mkEnableOption "Wayland."; - }; + config, + lib, + pkgs, + ... +}: let + cfg = config.module.desktop.wayland; +in { + options.module.desktop.wayland.enable = lib.mkEnableOption "the wayland."; - config = { - programs.xwayland.enable = true; - - environment = { - systemPackages = with pkgs; [ - wl-clipboard # CLI clipboard support. - ]; - - variables = { - # Compatibility variables. - ECORE_EVAS_ENGINE = "wayland_egl"; - ELM_ENGINE = "wayland_egl"; - GDK_BACKEND = "wayland"; - MOZ_ENABLE_WAYLAND = "1"; - QT_QPA_PLATFORM = "wayland-egl;wayland;xcb"; - QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; - SAL_USE_VCLPLUGIN = "gtk3"; - SDL_VIDEODRIVER = "wayland"; - _JAVA_AWT_WM_NONREPARENTING = "1"; - }; - }; - }; + config = { + programs.xwayland.enable = true; + environment = { + systemPackages = with pkgs; [ + wl-clipboard # CLI clipboard support. + ]; + variables = { + # Compatibility variables. + ECORE_EVAS_ENGINE = "wayland_egl"; + ELM_ENGINE = "wayland_egl"; + GDK_BACKEND = "wayland"; + MOZ_ENABLE_WAYLAND = "1"; + QT_QPA_PLATFORM = "wayland-egl;wayland;xcb"; + QT_WAYLAND_DISABLE_WINDOWDECORATION = "1"; + SAL_USE_VCLPLUGIN = "gtk3"; + SDL_VIDEODRIVER = "wayland"; + _JAVA_AWT_WM_NONREPARENTING = "1"; + }; + }; + }; } diff --git a/module/Zapret.nix b/module/Zapret.nix index 9228707..5556535 100644 --- a/module/Zapret.nix +++ b/module/Zapret.nix @@ -1,156 +1,153 @@ { - lib, - config, - pkgs, - ... -}: -let - cfg = config.module.zapret; + config, + lib, + pkgs, + util, + ... +}: let + cfg = config.module.zapret; - whitelist = - if cfg.whitelist != null then - "--hostlist ${pkgs.writeText "zapret-whitelist" (lib.concatStringsSep "\n" cfg.whitelist)}" - else - ""; + whitelist = if cfg.whitelist != null then + "--hostlist ${pkgs.writeText "zapret-whitelist" (lib.concatStringsSep "\n" cfg.whitelist)}" + else + ""; - blacklist = - if cfg.blacklist != null then - "--hostlist-exclude ${pkgs.writeText "zapret-blacklist" (lib.concatStringsSep "\n" cfg.blacklist)}" - else - ""; + blacklist = if cfg.blacklist != null then + "--hostlist-exclude ${pkgs.writeText "zapret-blacklist" (lib.concatStringsSep "\n" cfg.blacklist)}" + else + ""; - ports = if cfg.httpSupport then "80,443" else "443"; -in -{ - options.module.zapret = { - enable = lib.mkEnableOption "Enable Zapret DPI bypass service."; - package = lib.mkPackageOption pkgs "zapret" { }; - params = lib.mkOption { - default = null; - type = with lib.types; listOf str; - example = '' - [ - "--dpi-desync=fake,disorder2" - "--dpi-desync-ttl=1" - "--dpi-desync-autottl=2" - ]; - ''; - description = '' - Specify the bypass parameters for Zapret binary. - There are no universal parameters as they vary between different networks, so you'll have to find them yourself. + ports = if cfg.httpSupport then "80,443" else "443"; +in { + options.module.zapret = { + enable = lib.mkEnableOption "Enable Zapret DPI bypass service."; + package = lib.mkPackageOption pkgs "zapret" { }; + params = lib.mkOption { + default = null; + type = with lib.types; listOf str; + example = '' + [ + "--dpi-desync=fake,disorder2" + "--dpi-desync-ttl=1" + "--dpi-desync-autottl=2" + ]; + ''; + description = '' + Specify the bypass parameters for Zapret binary. + There are no universal parameters as they vary between different networks, so you'll have to find them yourself. - This can be done by running the `blockcheck` binary from zapret package, i.e. `nix-shell -p zapret --command blockcheck`. - It'll try different params and then tell you which params are working for your network. - ''; - }; - whitelist = lib.mkOption { - default = null; - type = with lib.types; nullOr (listOf str); - example = '' - [ - "youtube.com" - "googlevideo.com" - "ytimg.com" - "youtu.be" - ] - ''; - description = '' - Specify a list of domains to bypass. All other domains will be ignored. - You can specify either whitelist or blacklist, but not both. - If neither are specified, then bypass all domains. + This can be done by running the `blockcheck` binary from zapret package, i.e. `nix-shell -p zapret --command blockcheck`. + It'll try different params and then tell you which params are working for your network. + ''; + }; + whitelist = lib.mkOption { + default = null; + type = with lib.types; nullOr (listOf str); + example = '' + [ + "youtube.com" + "googlevideo.com" + "ytimg.com" + "youtu.be" + ] + ''; + description = '' + Specify a list of domains to bypass. All other domains will be ignored. + You can specify either whitelist or blacklist, but not both. + If neither are specified, then bypass all domains. - It is recommended to specify the whitelist. This will make sure that other resources won't be affected by this service. - ''; - }; - blacklist = lib.mkOption { - default = null; - type = with lib.types; nullOr (listOf str); - example = '' - [ - "example.com" - ] - ''; - description = '' - Specify a list of domains NOT to bypass. All other domains will be bypassed. - You can specify either whitelist or blacklist, but not both. - If neither are specified, then bypass all domains. - ''; - }; - qnum = lib.mkOption { - default = 200; - type = lib.types.int; - description = '' - Routing queue number. - Only change this if you already use the default queue number somewhere else. - ''; - }; - configureFirewall = lib.mkOption { - default = true; - type = lib.types.bool; - description = '' - Whether to setup firewall routing so that system http(s) traffic is forwarded via this service. - Disable if you want to set it up manually. - ''; - }; - httpSupport = lib.mkOption { - default = true; - type = lib.types.bool; - description = '' - Whether to route http traffic on port 80. - Http bypass rarely works and you might want to disable it if you don't utilise http connections. - ''; - }; - }; + It is recommended to specify the whitelist. This will make sure that other resources won't be affected by this service. + ''; + }; + blacklist = lib.mkOption { + default = null; + type = with lib.types; nullOr (listOf str); + example = '' + [ + "example.com" + ] + ''; + description = '' + Specify a list of domains NOT to bypass. All other domains will be bypassed. + You can specify either whitelist or blacklist, but not both. + If neither are specified, then bypass all domains. + ''; + }; + qnum = lib.mkOption { + default = 200; + type = lib.types.int; + description = '' + Routing queue number. + Only change this if you already use the default queue number somewhere else. + ''; + }; + configureFirewall = lib.mkOption { + default = true; + type = lib.types.bool; + description = '' + Whether to setup firewall routing so that system http(s) traffic is forwarded via this service. + Disable if you want to set it up manually. + ''; + }; + httpSupport = lib.mkOption { + default = true; + type = lib.types.bool; + description = '' + Whether to route http traffic on port 80. + Http bypass rarely works and you might want to disable it if you don't utilise http connections. + ''; + }; + }; - config = lib.mkIf cfg.enable ( - lib.mkMerge [ - { - assertions = [ - { - assertion = cfg.whitelist == null || cfg.blacklist == null; - message = "Can't specify both whitelist and blacklist."; - } - ]; + config = lib.mkIf cfg.enable ( + lib.mkMerge [ + { + assertions = [ + { + assertion = cfg.whitelist == null || cfg.blacklist == null; + message = "Can't specify both whitelist and blacklist."; + } + ]; - systemd.services.zapret = { - description = "DPI bypass service."; - wantedBy = [ "multi-user.target" ]; - after = [ "network.target" ]; - serviceConfig = { - ExecStart = "${cfg.package}/bin/nfqws --pidfile=/run/nfqws.pid ${lib.concatStringsSep " " cfg.params} ${whitelist} ${blacklist} --qnum=${toString cfg.qnum}"; - Type = "simple"; - PIDFile = "/run/nfqws.pid"; - Restart = "always"; - RuntimeMaxSec = "1h"; # This service loves to crash silently or cause network slowdowns. It also restarts instantly. In my experience restarting it hourly provided the best experience. + systemd.services.zapret = { + description = "DPI bypass service."; + wantedBy = [ "multi-user.target" ]; + after = [ "network.target" ]; + serviceConfig = { + ExecStart = "${cfg.package}/bin/nfqws --pidfile=/run/nfqws.pid ${lib.concatStringsSep " " cfg.params} ${whitelist} ${blacklist} --qnum=${toString cfg.qnum}"; + Type = "simple"; + PIDFile = "/run/nfqws.pid"; + Restart = "always"; + RuntimeMaxSec = "1h"; # This service loves to crash silently or cause network slowdowns. It also restarts instantly. In my experience restarting it hourly provided the best experience. - # Hardening. - DevicePolicy = "closed"; - KeyringMode = "private"; - PrivateTmp = true; - PrivateMounts = true; - ProtectHome = true; - ProtectHostname = true; - ProtectKernelModules = true; - ProtectKernelTunables = true; - ProtectSystem = "strict"; - ProtectProc = "invisible"; - RemoveIPC = true; - RestrictNamespaces = true; - RestrictRealtime = true; - RestrictSUIDSGID = true; - SystemCallArchitectures = "native"; - }; - }; - } + # Hardening. + DevicePolicy = "closed"; + KeyringMode = "private"; + PrivateTmp = true; + PrivateMounts = true; + ProtectHome = true; + ProtectHostname = true; + ProtectKernelModules = true; + ProtectKernelTunables = true; + ProtectSystem = "strict"; + ProtectProc = "invisible"; + RemoveIPC = true; + RestrictNamespaces = true; + RestrictRealtime = true; + RestrictSUIDSGID = true; + SystemCallArchitectures = "native"; + }; + }; + } - # Route system traffic via service for specified ports. - (lib.mkIf cfg.configureFirewall { - networking.firewall.extraCommands = '' - iptables -t mangle -I POSTROUTING -p tcp -m multiport --dports ${ports} -m connbytes --connbytes-dir=original --connbytes-mode=packets --connbytes 1:6 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num ${toString cfg.qnum} --queue-bypass - ''; - }) - ] - ); + # Route system traffic via service for specified ports. + (lib.mkIf cfg.configureFirewall { + networking.firewall.extraCommands = util.trimTabs '' + iptables -t mangle -I POSTROUTING -p tcp -m multiport --dports ${ports} -m connbytes --connbytes-dir=original --connbytes-mode=packets --connbytes 1:6 -m mark ! --mark 0x40000000/0x40000000 -j NFQUEUE --queue-num ${toString cfg.qnum} --queue-bypass + ''; + }) + ] + ); - meta.maintainers = with lib.maintainers; [ voronind ]; + meta.maintainers = with lib.maintainers; [ voronind ]; } diff --git a/overlay/Example.nix b/overlay/Example.nix index ad853d5..4d8e9d8 100644 --- a/overlay/Example.nix +++ b/overlay/Example.nix @@ -2,27 +2,26 @@ # Overlays can change parameters in package builds, like source version. # This way you can change something in package without recreating the whole build process. # More info: https://nixos.wiki/wiki/Overlays -{ ... }: -{ - # Use a different revision. - # nixpkgs.overlays = [ (final: prev: { - # yt-dlp = prev.yt-dlp.overrideAttrs (old: { - # src = prev.fetchFromGitHub { - # owner = "yt-dlp"; - # repo = "yt-dlp"; - # rev = "2024.03.10"; - # hash = "sha256-A6uciGErM4QgLrY5jMFGlPV2uH9O2cOhj5+IapyjVo0="; - # }; - # }); - # })]; +{ ... }: { + # Use a different revision. + # nixpkgs.overlays = [ (final: prev: { + # yt-dlp = prev.yt-dlp.overrideAttrs (old: { + # src = prev.fetchFromGitHub { + # owner = "yt-dlp"; + # repo = "yt-dlp"; + # rev = "2024.03.10"; + # hash = "sha256-A6uciGErM4QgLrY5jMFGlPV2uH9O2cOhj5+IapyjVo0="; + # }; + # }); + # })]; - # Apply patch to a program. - # nixpkgs.overlays = [ (final: prev: { - # keyd = prev.keyd.overrideAttrs (old: { - # patches = (old.patches or []) ++ [(prev.fetchpatch { - # url = "https://patch-diff.githubusercontent.com/raw/rvaiya/keyd/pull/545.patch"; - # hash = "sha256-aal8oAXws6DcpeCl7G9GMJQXeLDDbyotWFut0Rf82WI="; - # })]; - # }); - # })]; + # Apply patch to a program. + # nixpkgs.overlays = [ (final: prev: { + # keyd = prev.keyd.overrideAttrs (old: { + # patches = (old.patches or []) ++ [(prev.fetchpatch { + # url = "https://patch-diff.githubusercontent.com/raw/rvaiya/keyd/pull/545.patch"; + # hash = "sha256-aal8oAXws6DcpeCl7G9GMJQXeLDDbyotWFut0Rf82WI="; + # })]; + # }); + # })]; } diff --git a/overlay/Keyd.nix b/overlay/Keyd.nix index a75e934..bbd5d51 100644 --- a/overlay/Keyd.nix +++ b/overlay/Keyd.nix @@ -1,47 +1,42 @@ # HACK: Add a patch for https://github.com/rvaiya/keyd/pull/545 -{ lib, ... }: { - nixpkgs.overlays = [ - (final: prev: { - keyd = prev.keyd.overrideAttrs (old: rec { - patches = (old.patches or [ ]) ++ [ - (prev.fetchpatch { - url = "https://patch-diff.githubusercontent.com/raw/rvaiya/keyd/pull/545.patch"; - hash = "sha256-aal8oAXws6DcpeCl7G9GMJQXeLDDbyotWFut0Rf82WI="; - }) - ]; + lib, + util, + ... +}: { + nixpkgs.overlays = [(final: prev: { + keyd = prev.keyd.overrideAttrs (old: rec { + patches = (old.patches or [ ]) ++ [ + (prev.fetchpatch { + hash = "sha256-aal8oAXws6DcpeCl7G9GMJQXeLDDbyotWFut0Rf82WI="; + url = "https://patch-diff.githubusercontent.com/raw/rvaiya/keyd/pull/545.patch"; + }) + ]; - postInstall = - let - pypkgs = prev.python3.pkgs; - appMap = pypkgs.buildPythonApplication rec { - inherit (prev.keyd) version src; - inherit patches; - - pname = "keyd-application-mapper"; - format = "other"; - - postPatch = '' - substituteInPlace scripts/${pname} \ - --replace /bin/sh ${prev.runtimeShell} - ''; - - propagatedBuildInputs = with pypkgs; [ xlib ]; - - dontBuild = true; - - installPhase = '' - install -Dm555 -t $out/bin scripts/${pname} - ''; - - meta.mainProgram = "keyd-application-mapper"; - }; - in - '' - ln -sf ${lib.getExe appMap} $out/bin/${appMap.pname} - rm -rf $out/etc - ''; - }); - }) - ]; + postInstall = let + pypkgs = prev.python3.pkgs; + appMap = pypkgs.buildPythonApplication rec { + inherit (prev.keyd) version src; + inherit patches; + dontBuild = true; + format = "other"; + meta.mainProgram = "keyd-application-mapper"; + pname = "keyd-application-mapper"; + postPatch = util.trimTabs '' + substituteInPlace scripts/${pname} \ + --replace /bin/sh ${prev.runtimeShell} + ''; + propagatedBuildInputs = with pypkgs; [ + xlib + ]; + installPhase = util.trimTabs '' + install -Dm555 -t $out/bin scripts/${pname} + ''; + }; + in '' + ln -sf ${lib.getExe appMap} $out/bin/${appMap.pname} + rm -rf $out/etc + ''; + }); + })]; } diff --git a/overlay/Nix.nix b/overlay/Nix.nix index adbf63c..88606f7 100644 --- a/overlay/Nix.nix +++ b/overlay/Nix.nix @@ -1,10 +1,10 @@ # Use stable packages for Nix and Nixos-Rebuild. -{ pkgsStable, ... }: { - nixpkgs.overlays = [ - (final: prev: { - nix = pkgsStable.nix; - nixos-rebuild = pkgsStable.nixos-rebuild; - }) - ]; + pkgsStable, + ... +}: { + nixpkgs.overlays = [(final: prev: { + nix = pkgsStable.nix; + nixos-rebuild = pkgsStable.nixos-rebuild; + })]; } diff --git a/package/applefont/default.nix b/package/applefont/default.nix index e5c9a89..6c446b8 100644 --- a/package/applefont/default.nix +++ b/package/applefont/default.nix @@ -2,65 +2,57 @@ # They are not available in Nixpkgs repo, so this script # downloads the fonts from Apple website and adds them to Nix store. { - lib, - stdenv, - fetchurl, - p7zip, -}: -let - pro = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/SF-Pro.dmg"; - sha256 = "1krvzxz7kal6y0l5cx9svmgikqdj5v0fl5vnfjig0z4nwp903ir1"; - }; + fetchurl, + lib, + p7zip, + stdenv, +}: let + pro = fetchurl { + sha256 = "1krvzxz7kal6y0l5cx9svmgikqdj5v0fl5vnfjig0z4nwp903ir1"; + url = "https://devimages-cdn.apple.com/design/resources/download/SF-Pro.dmg"; + }; + compact = fetchurl { + sha256 = "0ncybkrzqazw13azy2s30ss7ml5pxaia6hbmqq9wn7xhlhrxlniy"; + url = "https://devimages-cdn.apple.com/design/resources/download/SF-Compact.dmg"; + }; + mono = fetchurl { + sha256 = "0ibrk9fvbq52f5qnv1a8xlsazd3x3jnwwhpn2gwhdkdawdw0njkd"; + url = "https://devimages-cdn.apple.com/design/resources/download/SF-Mono.dmg"; + }; + ny = fetchurl { + sha256 = "1x7qi3dqwq1p4l3md31cd93mcds3ba7rgsmpz0kg7h3caasfsbhw"; + url = "https://devimages-cdn.apple.com/design/resources/download/NY.dmg"; + }; +in stdenv.mkDerivation { + name = "applefont"; + dontUnpack = true; + nativeBuildInputs = [ + p7zip + ]; + installPhase = let + unpackFont = dmg: dir: pkg: '' + 7z x '${dmg}' + pushd '${dir}' + 7z x '${pkg}' + 7z x 'Payload~' + cp Library/Fonts/* $TMPDIR + popd + ''; + in '' + ${unpackFont pro "SFProFonts" "SF Pro Fonts.pkg"} + ${unpackFont mono "SFMonoFonts" "SF Mono Fonts.pkg"} + ${unpackFont compact "SFCompactFonts" "SF Compact Fonts.pkg"} + ${unpackFont ny "NYFonts" "NY Fonts.pkg"} - compact = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/SF-Compact.dmg"; - sha256 = "0ncybkrzqazw13azy2s30ss7ml5pxaia6hbmqq9wn7xhlhrxlniy"; - }; + mkdir -p $out/usr/share/fonts/{TTF,OTF} + mv $TMPDIR/*.otf $out/usr/share/fonts/OTF + mv $TMPDIR/*.ttf $out/usr/share/fonts/TTF + ''; - mono = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/SF-Mono.dmg"; - sha256 = "0ibrk9fvbq52f5qnv1a8xlsazd3x3jnwwhpn2gwhdkdawdw0njkd"; - }; - - ny = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/NY.dmg"; - sha256 = "1x7qi3dqwq1p4l3md31cd93mcds3ba7rgsmpz0kg7h3caasfsbhw"; - }; -in -stdenv.mkDerivation { - name = "applefont"; - - dontUnpack = true; - - nativeBuildInputs = [ p7zip ]; - - installPhase = - let - unpackFont = dmg: dir: pkg: '' - 7z x '${dmg}' - pushd '${dir}' - 7z x '${pkg}' - 7z x 'Payload~' - cp Library/Fonts/* $TMPDIR - popd - ''; - in - '' - ${unpackFont pro "SFProFonts" "SF Pro Fonts.pkg"} - ${unpackFont mono "SFMonoFonts" "SF Mono Fonts.pkg"} - ${unpackFont compact "SFCompactFonts" "SF Compact Fonts.pkg"} - ${unpackFont ny "NYFonts" "NY Fonts.pkg"} - - mkdir -p $out/usr/share/fonts/{TTF,OTF} - mv $TMPDIR/*.otf $out/usr/share/fonts/OTF - mv $TMPDIR/*.ttf $out/usr/share/fonts/TTF - ''; - - meta = with lib; { - description = "Apple San Francisco, New York fonts."; - homepage = "https://developer.apple.com/fonts"; - license = licenses.mit; - meta.platforms = platforms.all; - }; + meta = with lib; { + description = "Apple San Francisco, New York fonts."; + homepage = "https://developer.apple.com/fonts"; + license = licenses.mit; + meta.platforms = platforms.all; + }; } diff --git a/package/darkreader/default.nix b/package/darkreader/default.nix index a6f5a9d..02caf55 100644 --- a/package/darkreader/default.nix +++ b/package/darkreader/default.nix @@ -1,34 +1,27 @@ { - fetchFromGitHub, - buildNpmPackage, - fetchpatch, - ... -}: -buildNpmPackage rec { - version = "4.9.96"; - - pname = "dark-reader"; - - src = fetchFromGitHub { - # owner = "darkreader"; - owner = "voronind-com"; - repo = "darkreader"; - # rev = "v${version}"; - rev = "ddd532cb92594d2f4a73480dae6e6c024657dfe2"; - hash = "sha256-mONoHe/Aphm6T5UcucxlzMLDaNnqIKd35uCAVoYlJ8s="; - }; - - npmDepsHash = "sha256-e41PXGgoQkVSHQj6kElqXPhzc6irnr09ltBAPmcUjik="; - - # patches = [ - # (fetchpatch { - # url = "https://github.com/darkreader/darkreader/pull/12920.diff"; - # hash = "sha256-3r54SliCgxihGXzZDRklB0vB3bk9rc1H31PojAYn2Ic="; - # }) - # ]; - - installPhase = '' - mkdir -p $out - cp build/release/darkreader-firefox.xpi $out/latest.xpi - ''; + buildNpmPackage, + fetchFromGitHub, + ... +}: buildNpmPackage { + version = "4.9.96"; + pname = "dark-reader"; + npmDepsHash = "sha256-e41PXGgoQkVSHQj6kElqXPhzc6irnr09ltBAPmcUjik="; + src = fetchFromGitHub { + hash = "sha256-mONoHe/Aphm6T5UcucxlzMLDaNnqIKd35uCAVoYlJ8s="; + # owner = "darkreader"; + owner = "voronind-com"; + repo = "darkreader"; + # rev = "v${version}"; + rev = "ddd532cb92594d2f4a73480dae6e6c024657dfe2"; + }; + # patches = [ + # (fetchpatch { + # url = "https://github.com/darkreader/darkreader/pull/12920.diff"; + # hash = "sha256-3r54SliCgxihGXzZDRklB0vB3bk9rc1H31PojAYn2Ic="; + # }) + # ]; + installPhase = '' + mkdir -p $out + cp build/release/darkreader-firefox.xpi $out/latest.xpi + ''; } diff --git a/package/default.nix b/package/default.nix index 88edbbb..4d4f82a 100644 --- a/package/default.nix +++ b/package/default.nix @@ -1,151 +1,152 @@ { - pkgs, - pkgsStable, - pkgsMaster, - ... -}@args: -{ - core = with pkgs; [ - android-tools # Android adb tool. Can be used to connect to itself via wireless debugging. binwalk # Can analyze files for other files inside them. - bat # Pretty cat. - bridge-utils # Network bridges. - btop # System monitoring. - chafa # CLI file manager. - coreutils # UNIX Core utilities. - cryptsetup # Filesystem encryption (LUKS). - curl # Http client. - ddrescue # Data rescue extractor. - diffutils # Diff tool. - dnsutils # NS utilities. - exiftool # Image info. - fastfetch # Systeminfo summary. - ffmpeg # Video/audio converter. - file # Get general info about a file. - findutils # Find tool. - gawk # Awk. - gcc # C compiler. - gdu # TUI storage analyzer. - git # Version control system. - gnugrep # Grep. - gnumake # Make. - gnused # Sed. - gnutar # Tar. - gzip # Fast compression. - htop # System monitors. - imagemagick # Image converter and transformation tool. - inetutils # Things like FTP. - iputils # IP tools. - jq # Json parser. - lm_sensors # Hardware sensors, like temperature and fan speeds. - lshw # Detailed hardware info tool. - lsof # Find current file users. - ltex-ls # Latex LSP for neovim spellcheck. - man # App to read manuals. - neovim # Text editor. - nmap # Network scanning. - openssh # Ssh client. - parallel # Run programs in parallel. - parted # CLI disk partition tool. - pv # IO progress bar. - radare2 # Hex editor. - ripgrep # Better grep. - rsync # File copy tool. - smartmontools # S.M.A.R.T. tools. - sqlite # Serverless file-based database engine. - sshfs # Ssh client. - testdisk # Apps to recover data from drives. - tmux # Terminal multiplexor. - tree # Show directory stricture as a tree. - tree-sitter # A parser generator tool and an incremental parsing library. - tun2socks # Use proxy as a vpn. - unzip # Zip archive/unarchive tools. - usbutils # Usb utilities like udiskctl. - utillinux # Common Linux utilities. - ventoy # Boot multiple ISO/images from a single USB stick. - wcurl # CLI http client. - wireguard-tools # Tools to work with Wireguard. - xray # Proxy. - xz # Archive and compression tools. - yazi # File manager. - yt-dlp # Video downloader. - zapret # FRKN. - zip # Zip utility. - zmap # Network analyzer. + pkgs, + pkgsMaster, + pkgsStable, + ... +} @args: { + core = with pkgs; [ + android-tools # Android adb tool. Can be used to connect to itself via wireless debugging. + binwalk # Can analyze files for other files inside them. + bat # Pretty cat. + bridge-utils # Network bridges. + btop # System monitoring. + chafa # CLI file manager. + coreutils # UNIX Core utilities. + cryptsetup # Filesystem encryption (LUKS). + curl # Http client. + ddrescue # Data rescue extractor. + diffutils # Diff tool. + dnsutils # NS utilities. + exiftool # Image info. + fastfetch # Systeminfo summary. + ffmpeg # Video/audio converter. + file # Get general info about a file. + findutils # Find tool. + gawk # Awk. + gcc # C compiler. + gdu # TUI storage analyzer. + git # Version control system. + gnugrep # Grep. + gnumake # Make. + gnused # Sed. + gnutar # Tar. + gzip # Fast compression. + htop # System monitors. + imagemagick # Image converter and transformation tool. + inetutils # Things like FTP. + iputils # IP tools. + jq # Json parser. + lm_sensors # Hardware sensors, like temperature and fan speeds. + lshw # Detailed hardware info tool. + lsof # Find current file users. + ltex-ls # Latex LSP for neovim spellcheck. + man # App to read manuals. + neovim # Text editor. + nmap # Network scanning. + openssh # Ssh client. + parallel # Run programs in parallel. + parted # CLI disk partition tool. + pv # IO progress bar. + radare2 # Hex editor. + ripgrep # Better grep. + rsync # File copy tool. + smartmontools # S.M.A.R.T. tools. + sqlite # Serverless file-based database engine. + sshfs # Ssh client. + testdisk # Apps to recover data from drives. + tmux # Terminal multiplexor. + tree # Show directory stricture as a tree. + tree-sitter # A parser generator tool and an incremental parsing library. + tun2socks # Use proxy as a vpn. + unzip # Zip archive/unarchive tools. + usbutils # Usb utilities like udiskctl. + utillinux # Common Linux utilities. + ventoy # Boot multiple ISO/images from a single USB stick. + wcurl # CLI http client. + wireguard-tools # Tools to work with Wireguard. + xray # Proxy. + xz # Archive and compression tools. + yazi # File manager. + yt-dlp # Video downloader. + zapret # FRKN. + zip # Zip utility. + zmap # Network analyzer. - # (pkgs.callPackage ./ytdlp {}) # Youtube downloader bin package. - (pkgs.callPackage ./yamusicdownload { }) # Yandex music downloader. - ]; + # (pkgs.callPackage ./ytdlp {}) # Youtube downloader bin package. + (pkgs.callPackage ./yamusicdownload { }) # Yandex music downloader. + ]; - desktop = with pkgs; [ - adwaita-icon-theme # GTK icons. - foot # Terminal emulator. - fuzzel # Application launcher. - grim # Screenshots. - slurp # Screen selection. - wf-recorder # Screen recording. - swappy # Screenshot editing. - mako # Notification system. - networkmanagerapplet # Internet configuration. - pamixer # Sound controls. - pavucontrol # Sound applet. - pulseaudio # Audio. - playerctl # Multimedia controls. - sway # Sway WM. - waybar # Sway bar. + desktop = with pkgs; [ + adwaita-icon-theme # GTK icons. + foot # Terminal emulator. + fuzzel # Application launcher. + grim # Screenshots. + mako # Notification system. + networkmanagerapplet # Internet configuration. + pamixer # Sound controls. + pavucontrol # Sound applet. + playerctl # Multimedia controls. + pulseaudio # Audio. + slurp # Screen selection. + swappy # Screenshot editing. + sway # Sway WM. + waybar # Sway bar. + wf-recorder # Screen recording. - (pkgs.callPackage ./swayscript args) - ]; + (pkgs.callPackage ./swayscript args) + ]; - common = with pkgs; [ - evince # Document viewer. - gimp # Image manipulation program. - gnome-calculator # Calculator. - gparted # GUI disk utility just in case. - jellyfin-media-player # Jellyfin client (self-hosted Netflix). - loupe # Image viewer. - nautilus # File manager. - obs-studio # Streaming/recording app. - onlyoffice-bin # Office documents app suite. + common = with pkgs; [ + evince # Document viewer. + gimp # Image manipulation program. + gnome-calculator # Calculator. + gparted # GUI disk utility just in case. + jellyfin-media-player # Jellyfin client (self-hosted Netflix). + loupe # Image viewer. + nautilus # File manager. + obs-studio # Streaming/recording app. + onlyoffice-bin # Office documents app suite. + upscayl # Image upscaler. - (mpv.override { scripts = [ mpvScripts.mpris ]; }) # Media player. - ]; + (mpv.override { scripts = [ mpvScripts.mpris ]; }) # Media player. + ]; - gaming = with pkgs; [ - scanmem # Memory edit tool. - steam # Gaming platform. - bottles # GUI for Wine. - dxvk # Directx to Vulkan. - gamescope # Compositor for Steam. - mangohud # Realtime stats overlay. - vkd3d # Directx to Vulkan. - wine64 # Run Windows software on Linux. - steam-run # Run games outside of Steam. - ]; + gaming = with pkgs; [ + bottles # GUI for Wine. + dxvk # Directx to Vulkan. + gamescope # Compositor for Steam. + mangohud # Realtime stats overlay. + scanmem # Memory edit tool. + steam # Gaming platform. + steam-run # Run games outside of Steam. + vkd3d # Directx to Vulkan. + wine64 # Run Windows software on Linux. + ]; - creative = with pkgs; [ - libresprite # Pixel Art draw app. - blender-hip # Blender with HiP support. - krita # Draw! - ]; + creative = with pkgs; [ + blender-hip # Blender with HiP support. + krita # Draw! + libresprite # Pixel Art draw app. + ]; - dev = with pkgs; [ - android-studio # I hate you. - jetbrains.idea-community # Okay, but LSP would be better. - ]; + dev = with pkgs; [ + android-studio + jetbrains.idea-community + ]; - extra = with pkgs; [ - anilibria-winmaclinux # Anime! - appimage-run # Tool to run .AppImage files in NixOS. - blanket # Sounds generator. - calibre # Book library manager. - cbonsai # Draw trees. - cmatrix # CLI Screensavers. - cowsay # Cow quotes. - lolcat # CLI funni colors. - gnome-font-viewer # Font viewer. - jamesdsp # Active audio processing. - p7zip # Weird archive tool. - tor-browser # Privacy browser. - universal-android-debloater # Debloat Android devices. - ]; + extra = with pkgs; [ + anilibria-winmaclinux # Anime! + appimage-run # Tool to run .AppImage files in NixOS. + blanket # Sounds generator. + calibre # Book library manager. + cbonsai # Draw trees. + cmatrix # CLI Screensavers. + cowsay # Cow quotes. + gnome-font-viewer # Font viewer. + jamesdsp # Active audio processing. + lolcat # CLI funni colors. + p7zip # Weird archive tool. + tor-browser # Privacy browser. + universal-android-debloater # Debloat Android devices. + ]; } diff --git a/package/homer/Config.nix b/package/homer/Config.nix index f1e76d3..2d1c3f7 100644 --- a/package/homer/Config.nix +++ b/package/homer/Config.nix @@ -1,106 +1,100 @@ -{ pkgs, config, ... }: -let - iconTheme = "fa-solid"; - - links = [ (mkLink "Status" "fa-heartbeat" "https://${config.container.module.status.domain}") ]; - - services = [ - (mkGroup "App" "fa-server" [ - (mkLink "Change" "fa-user-secret" "https://${config.container.module.change.domain}") - (mkLink "Cloud" "fa-cloud" "https://${config.container.module.cloud.domain}") - (mkLink "Download" "fa-download" "https://${config.container.module.download.domain}") - (mkLink "Git" "fab fa-git-alt" "https://${config.container.module.git.domain}") - (mkLink "Iot" "fa-home" "https://${config.container.module.iot.domain}") - (mkLink "Mail" "fa-envelope" "https://${config.container.module.mail.domain}") - (mkLink "Paper" "fa-paperclip" "https://${config.container.module.paper.domain}") - (mkLink "Pass" "fa-key" "https://${config.container.module.pass.domain}") - (mkLink "Paste" "fa-paste" "https://${config.container.module.paste.domain}/s") - (mkLink "Print" "fa-print" "https://${config.container.module.print.domain}") - (mkLink "Read" "fa-book" "https://${config.container.module.read.domain}") - (mkLink "Search" "fa-search" "https://${config.container.module.search.domain}") - (mkLink "Stock" "fa-boxes-stacked" "https://${config.container.module.stock.domain}") - (mkLink "Watch" "fa-film" "https://${config.container.module.watch.domain}") - (mkLink "YouTube" "fab fa-youtube" "https://${config.container.module.yt.domain}") - ]) - (mkGroup "System" "fa-shield" [ - (mkLink "Camera" "fa-camera" "https://camera.${config.container.domain}") - (mkLink "NixOS Search" "fa-snowflake" "https://search.nixos.org") - (mkLink "Printer" "fa-print" "https://printer.${config.container.domain}") - (mkLink "Router" "fa-route" "https://router.${config.container.domain}") - ]) - (mkGroup "Bookmark" "fa-bookmark" [ - (mkLink "2gis" "fa-map-location-dot" "https://2gis.ru") - (mkLink "FontAwesome" "fa-font-awesome" "https://fontawesome.com/search?o=r&m=free") - (mkLink "Flibusta" "fa-book" "https://flibusta.is") - (mkLink "MonkeyType" "fa-keyboard" "https://monkeytype.com") - (mkLink "NerdFonts" "fa-font" "https://www.nerdfonts.com/cheat-sheet") - (mkLink "Reddit" "fab fa-reddit" "https://reddit.com") - (mkLink "Toolbox" "fa-toolbox" "https://it-tools.tech") - (mkLink "Zigbee" "fa-satellite-dish" "https://zigbee.blakadder.com") - ]) - (mkGroup "Pirate" "fa-skull-crossbones" [ - (mkLink "1337x" "fa-skull-crossbones" "https://1337x.to") - (mkLink "Cs.rin.ru" "fa-skull-crossbones" "https://cs.rin.ru/forum/index.php") - (mkLink "DigitalCore" "fa-skull-crossbones" "https://digitalcore.club") - (mkLink "FitGirl" "fa-skull-crossbones" "https://fitgirl-repacks.site") - (mkLink "Hf" "fa-skull-crossbones" "https://happyfappy.org") - (mkLink "Lst" "fa-skull-crossbones" "https://lst.gg") - (mkLink "NnmClub" "fa-skull-crossbones" "https://nnmclub.to") - (mkLink "Rutor" "fa-skull-crossbones" "https://rutor.info") - (mkLink "Rutracker" "fa-skull-crossbones" "https://rutracker.org") - (mkLink "Switch Upd" "fa-skull-crossbones" "https://sigmapatches.su") - (mkLink "Tapochek.net" "fa-skull-crossbones" "https://tapochek.net/index.php") - ]) - ]; - - mkGroup = name: icon: items: { - inherit name items; - icon = "${iconTheme} ${icon}"; - }; - - mkLink = name: icon: url: { - inherit name url; - icon = "${iconTheme} ${icon}"; - target = "_blank"; - }; - - cfg = { - inherit services links; - - title = "Dashboard"; - subtitle = "Home"; - header = false; - footer = false; - connectivityCheck = false; - - theme = "default"; - colors = - let - colors = - let - cfg = config.style.color; - in - { - background = "#${cfg.bg.dark}"; - card-background = "#${cfg.bg.regular}"; - card-shadow = "#${cfg.bg.regular}"; - highlight-hover = "#${cfg.accent}"; - highlight-primary = "#${cfg.fg.regular}"; - highlight-secondary = "#${cfg.bg.dark}"; - link = "#${cfg.fg.regular}"; - link-hover = "#${cfg.accent}"; - text = "#${cfg.fg.regular}"; - text-header = "#${cfg.fg.regular}"; - text-subtitle = "#${cfg.fg.light}"; - text-title = "#${cfg.fg.light}"; - }; - in - { - light = colors; - dark = colors; - }; - }; -in { - file = (pkgs.formats.yaml { }).generate "HomerConfig" cfg; + pkgs, + config, + ... +}: let + iconTheme = "fa-solid"; + links = [ + (mkLink "Status" "fa-heartbeat" "https://${config.container.module.status.domain}") + ]; + services = [ + (mkGroup "App" "fa-server" [ + (mkLink "Change" "fa-user-secret" "https://${config.container.module.change.domain}") + (mkLink "Cloud" "fa-cloud" "https://${config.container.module.cloud.domain}") + (mkLink "Download" "fa-download" "https://${config.container.module.download.domain}") + (mkLink "Git" "fab fa-git-alt" "https://${config.container.module.git.domain}") + (mkLink "Iot" "fa-home" "https://${config.container.module.iot.domain}") + (mkLink "Mail" "fa-envelope" "https://${config.container.module.mail.domain}") + (mkLink "Paper" "fa-paperclip" "https://${config.container.module.paper.domain}") + (mkLink "Pass" "fa-key" "https://${config.container.module.pass.domain}") + (mkLink "Paste" "fa-paste" "https://${config.container.module.paste.domain}/s") + (mkLink "Print" "fa-print" "https://${config.container.module.print.domain}") + (mkLink "Read" "fa-book" "https://${config.container.module.read.domain}") + (mkLink "Search" "fa-search" "https://${config.container.module.search.domain}") + (mkLink "Stock" "fa-boxes-stacked" "https://${config.container.module.stock.domain}") + (mkLink "Watch" "fa-film" "https://${config.container.module.watch.domain}") + (mkLink "YouTube" "fab fa-youtube" "https://${config.container.module.yt.domain}") + ]) + (mkGroup "System" "fa-shield" [ + (mkLink "Camera" "fa-camera" "https://camera.${config.container.domain}") + (mkLink "NixOS Search" "fa-snowflake" "https://search.nixos.org") + (mkLink "Printer" "fa-print" "https://printer.${config.container.domain}") + (mkLink "Router" "fa-route" "https://router.${config.container.domain}") + ]) + (mkGroup "Bookmark" "fa-bookmark" [ + (mkLink "2gis" "fa-map-location-dot" "https://2gis.ru") + (mkLink "Flibusta" "fa-book" "https://flibusta.is") + (mkLink "FontAwesome" "fa-font-awesome" "https://fontawesome.com/search?o=r&m=free") + (mkLink "MonkeyType" "fa-keyboard" "https://monkeytype.com") + (mkLink "NerdFonts" "fa-font" "https://www.nerdfonts.com/cheat-sheet") + (mkLink "Reddit" "fab fa-reddit" "https://reddit.com") + (mkLink "Toolbox" "fa-toolbox" "https://it-tools.tech") + (mkLink "Zigbee" "fa-satellite-dish" "https://zigbee.blakadder.com") + ]) + (mkGroup "Pirate" "fa-skull-crossbones" [ + (mkLink "1337x" "fa-skull-crossbones" "https://1337x.to") + (mkLink "Cs.rin.ru" "fa-skull-crossbones" "https://cs.rin.ru/forum/index.php") + (mkLink "DigitalCore" "fa-skull-crossbones" "https://digitalcore.club") + (mkLink "FitGirl" "fa-skull-crossbones" "https://fitgirl-repacks.site") + (mkLink "Hf" "fa-skull-crossbones" "https://happyfappy.org") + (mkLink "Lst" "fa-skull-crossbones" "https://lst.gg") + (mkLink "NnmClub" "fa-skull-crossbones" "https://nnmclub.to") + (mkLink "Rutor" "fa-skull-crossbones" "https://rutor.info") + (mkLink "Rutracker" "fa-skull-crossbones" "https://rutracker.org") + (mkLink "Switch Upd" "fa-skull-crossbones" "https://sigmapatches.su") + (mkLink "Tapochek.net" "fa-skull-crossbones" "https://tapochek.net/index.php") + ]) + ]; + + mkGroup = name: icon: items: { + inherit name items; + icon = "${iconTheme} ${icon}"; + }; + + mkLink = name: icon: url: { + inherit name url; + icon = "${iconTheme} ${icon}"; + target = "_blank"; + }; + + cfg = { + inherit services links; + connectivityCheck = false; + footer = false; + header = false; + subtitle = "Home"; + theme = "default"; + title = "Dashboard"; + colors = let + style = with config.module.style.color; { + background = "#${bg.dark}"; + card-background = "#${bg.regular}"; + card-shadow = "#${bg.regular}"; + highlight-hover = "#${accent}"; + highlight-primary = "#${fg.regular}"; + highlight-secondary = "#${bg.dark}"; + link = "#${fg.regular}"; + link-hover = "#${accent}"; + text = "#${fg.regular}"; + text-header = "#${fg.regular}"; + text-subtitle = "#${fg.light}"; + text-title = "#${fg.light}"; + }; + in { + dark = style; + light = style; + }; + }; +in { + file = (pkgs.formats.yaml { }).generate "HomerConfig" cfg; } diff --git a/package/homer/default.nix b/package/homer/default.nix index a9f3dec..6638937 100644 --- a/package/homer/default.nix +++ b/package/homer/default.nix @@ -1,33 +1,29 @@ { - stdenv, - pkgs, - config, - ... -}@args: -let - cfg = (import ./Config.nix args).file; -in -stdenv.mkDerivation (finalAttrs: { - pname = "Homer"; - version = "24.05.1"; + config, + pkgs, + stdenv, + ... +} @args: let + cfg = (import ./Config.nix args).file; +in stdenv.mkDerivation (finalAttrs: { + dontUnpack = true; + pname = "Homer"; + version = "24.05.1"; + src = pkgs.fetchurl { + sha256 = "sha256-Ji/7BSKCnnhj4NIdGngTHcGRRbx9UWrx48bBsKkEj34="; + url = "https://github.com/bastienwirtz/homer/releases/download/v${finalAttrs.version}/homer.zip"; + }; + nativeBuildInputs = with pkgs; [ + unzip + ]; + installPhase = '' + runHook preInstall - src = pkgs.fetchurl { - url = "https://github.com/bastienwirtz/homer/releases/download/v${finalAttrs.version}/homer.zip"; - sha256 = "sha256-Ji/7BSKCnnhj4NIdGngTHcGRRbx9UWrx48bBsKkEj34="; - }; + mkdir -p $out/assets + pushd $out + unzip $src + cp ${cfg} $out/assets/config.yml - nativeBuildInputs = with pkgs; [ unzip ]; - - dontUnpack = true; - - installPhase = '' - runHook preInstall - - mkdir -p $out/assets - pushd $out - unzip $src - cp ${cfg} $out/assets/config.yml - - runHook postInstall - ''; + runHook postInstall + ''; }) diff --git a/package/jobber/default.nix b/package/jobber/default.nix index addefe3..3565678 100644 --- a/package/jobber/default.nix +++ b/package/jobber/default.nix @@ -1,5 +1,8 @@ -{ poetry2nix, pkgs, ... }: -let - inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication; +{ + poetry2nix, + pkgs, + ... +}: let + inherit (poetry2nix.lib.mkPoetry2Nix { inherit pkgs; }) mkPoetryApplication; in -mkPoetryApplication { projectDir = ./project; } + mkPoetryApplication { projectDir = ./project; } diff --git a/package/print/default.nix b/package/print/default.nix index c053693..7e96899 100644 --- a/package/print/default.nix +++ b/package/print/default.nix @@ -1,51 +1,43 @@ -# https://github.com/NixOS/nixpkgs/blob/nixos-24.05/pkgs/misc/drivers/pantum-driver/default.nix +# SEE: https://github.com/NixOS/nixpkgs/blob/nixos-24.05/pkgs/misc/drivers/pantum-driver/default.nix { - stdenv, - fetchurl, - pkgs, - ... -}: -let -in -stdenv.mkDerivation rec { - pname = "pantum-driver"; - version = "1.1.106"; + fetchurl, + pkgs, + stdenv, + ... +}: stdenv.mkDerivation rec { + pname = "pantum-driver"; + dontUnpack = true; + version = "1.1.106"; + src = fetchurl { + hash = "sha256-IflzEM2kqqMqOQWZ5Eu906dEa85h+NFRmoR7y7WPX7Q="; + url = "https://cloud.voronind.com/s/k6Ea6QsrsKcAeNg/download/Pantum%20Ubuntu%20Driver%20V1_1_106.zip"; + }; + buildInputs = with pkgs; [ + cups + libjpeg8 + libusb1 + ]; + nativeBuildInputs = with pkgs; [ + autoPatchelfHook + dpkg + unzip + ]; + installPhase = '' + unzip $src + pushd Pantum\ Ubuntu\ Driver\ V1.1.106/ - src = fetchurl { - url = "https://cloud.voronind.com/s/k6Ea6QsrsKcAeNg/download/Pantum%20Ubuntu%20Driver%20V1_1_106.zip"; - # hash = "sha256-vyhQIdiF7CgRg1wPN94Ex8yfLLam6pf5KRGqSCVlQ34="; - hash = "sha256-IflzEM2kqqMqOQWZ5Eu906dEa85h+NFRmoR7y7WPX7Q="; - }; + dpkg-deb -x ./Resources/pantum_${version}-1_amd64.deb . - buildInputs = with pkgs; [ - libusb1 - libjpeg8 - cups - ]; - nativeBuildInputs = with pkgs; [ - unzip - dpkg - autoPatchelfHook - ]; - - dontUnpack = true; - - installPhase = '' - unzip $src - pushd Pantum\ Ubuntu\ Driver\ V1.1.106/ - - dpkg-deb -x ./Resources/pantum_${version}-1_amd64.deb . - - mkdir -p $out $out/lib - cp -r etc $out/ - cp -r usr/lib/cups $out/lib/ - cp -r usr/local/lib/* $out/lib/ - cp -r usr/share $out/ - cp Resources/locale/en_US.UTF-8/* $out/share/doc/pantum/ - ''; - # + '' - # cp -r opt/pantum/* $out/ - # ln -s $out/lib/libqpdf.so* $out/lib/libqpdf.so - # ln -s $out/lib/libqpdf.so $out/lib/libqpdf.so.21 - # ''; + mkdir -p $out $out/lib + cp -r etc $out/ + cp -r usr/lib/cups $out/lib/ + cp -r usr/local/lib/* $out/lib/ + cp -r usr/share $out/ + cp Resources/locale/en_US.UTF-8/* $out/share/doc/pantum/ + ''; + # + '' + # cp -r opt/pantum/* $out/ + # ln -s $out/lib/libqpdf.so* $out/lib/libqpdf.so + # ln -s $out/lib/libqpdf.so $out/lib/libqpdf.so.21 + # ''; } diff --git a/package/privatebin/Config.nix b/package/privatebin/Config.nix index 71fd9a8..46636e5 100644 --- a/package/privatebin/Config.nix +++ b/package/privatebin/Config.nix @@ -1,282 +1,47 @@ -{ config, ... }: { - text = '' - ;project page." - - ; (optional) notice to display - ; notice = "Note: This is a test service: Data may be deleted anytime. Kittens will die if you abuse this service." - - ; by default PrivateBin will guess the visitors language based on the browsers - ; settings. Optionally you can enable the language selection menu, which uses - ; a session cookie to store the choice until the browser is closed. - languageselection = false - - ; set the language your installs defaults to, defaults to English - ; if this is set and language selection is disabled, this will be the only language - ; languagedefault = "en" - - ; (optional) URL shortener address to offer after a new paste is created. - ; It is suggested to only use this with self-hosted shorteners as this will leak - ; the pastes encryption key. - ; urlshortener = "https://shortener.example.com/api?link=" - - ; (optional) Let users create a QR code for sharing the paste URL with one click. - ; It works both when a new paste is created and when you view a paste. - ; qrcode = true - - ; (optional) Let users send an email sharing the paste URL with one click. - ; It works both when a new paste is created and when you view a paste. - ; email = true - - ; (optional) IP based icons are a weak mechanism to detect if a comment was from - ; a different user when the same username was used in a comment. It might get - ; used to get the IP of a comment poster if the server salt is leaked and a - ; SHA512 HMAC rainbow table is generated for all (relevant) IPs. - ; Can be set to one these values: - ; "none" / "identicon" (default) / "jdenticon" / "vizhash". - ; icon = "none" - - ; Content Security Policy headers allow a website to restrict what sources are - ; allowed to be accessed in its context. You need to change this if you added - ; custom scripts from third-party domains to your templates, e.g. tracking - ; scripts or run your site behind certain DDoS-protection services. - ; Check the documentation at https://content-security-policy.com/ - ; Notes: - ; - If you use any bootstrap theme, you can remove the allow-popups from the - ; sandbox restrictions. - ; - If you use the bootstrap5 theme, you must change default-src to 'self' to - ; enable display of the svg icons - ; - By default this disallows to load images from third-party servers, e.g. when - ; they are embedded in pastes. If you wish to allow that, you can adjust the - ; policy here. See https://github.com/PrivateBin/PrivateBin/wiki/FAQ#why-does-not-it-load-embedded-images - ; for details. - ; - The 'unsafe-eval' is used in two cases; to check if the browser supports - ; async functions and display an error if not and for Chrome to enable - ; webassembly support (used for zlib compression). You can remove it if Chrome - ; doesn't need to be supported and old browsers don't need to be warned. - ; cspheader = "default-src 'none'; base-uri 'self'; form-action 'none'; manifest-src 'self'; connect-src * blob:; script-src 'self' 'unsafe-eval'; style-src 'self'; font-src 'self'; frame-ancestors 'none'; img-src 'self' data: blob:; media-src blob:; object-src blob:; sandbox allow-same-origin allow-scripts allow-forms allow-popups allow-modals allow-downloads" - - ; stay compatible with PrivateBin Alpha 0.19, less secure - ; if enabled will use base64.js version 1.7 instead of 2.1.9 and sha1 instead of - ; sha256 in HMAC for the deletion token - ; zerobincompatibility = false - - ; Enable or disable the warning message when the site is served over an insecure - ; connection (insecure HTTP instead of HTTPS), defaults to true. - ; Secure transport methods like Tor and I2P domains are automatically whitelisted. - ; It is **strongly discouraged** to disable this. - ; See https://github.com/PrivateBin/PrivateBin/wiki/FAQ#why-does-it-show-me-an-error-about-an-insecure-connection for more information. - ; httpwarning = true - - ; Pick compression algorithm or disable it. Only applies to pastes/comments - ; created after changing the setting. - ; Can be set to one these values: "none" / "zlib" (default). - compression = "none" - - [expire] - ; expire value that is selected per default - ; make sure the value exists in [expire_options] - default = "1week" - - [expire_options] - ; Set each one of these to the number of seconds in the expiration period, - ; or 0 if it should never expire - 5min = 300 - 10min = 600 - 1hour = 3600 - 1day = 86400 - 1week = 604800 - ; Well this is not *exactly* one month, it's 30 days: - 1month = 2592000 - 1year = 31536000 - never = 0 - - [formatter_options] - ; Set available formatters, their order and their labels - plaintext = "Plain Text" - syntaxhighlighting = "Source Code" - markdown = "Markdown" - - [traffic] - ; time limit between calls from the same IP address in seconds - ; Set this to 0 to disable rate limiting. - limit = 10 - - ; (optional) Set IPs addresses (v4 or v6) or subnets (CIDR) which are exempted - ; from the rate-limit. Invalid IPs will be ignored. If multiple values are to - ; be exempted, the list needs to be comma separated. Leave unset to disable - ; exemptions. - ; exempted = "1.2.3.4,10.10.10/24" - - ; (optional) If you want only some source IP addresses (v4 or v6) or subnets - ; (CIDR) to be allowed to create pastes, set these here. Invalid IPs will be - ; ignored. If multiple values are to be exempted, the list needs to be comma - ; separated. Leave unset to allow anyone to create pastes. - ; creators = "1.2.3.4,10.10.10/24" - - ; (optional) if your website runs behind a reverse proxy or load balancer, - ; set the HTTP header containing the visitors IP address, i.e. X_FORWARDED_FOR - ; header = "X_FORWARDED_FOR" - - [purge] - ; minimum time limit between two purgings of expired pastes, it is only - ; triggered when pastes are created - ; Set this to 0 to run a purge every time a paste is created. - limit = 300 - - ; maximum amount of expired pastes to delete in one purge - ; Set this to 0 to disable purging. Set it higher, if you are running a large - ; site - batchsize = 10 - - ;[model] - ; name of data model class to load and directory for storage - ; the default model "Filesystem" stores everything in the filesystem - ;class = Filesystem - ;[model_options] - ;dir = PATH "data" - - ;[model] - ; example of a Google Cloud Storage configuration - ;class = GoogleCloudStorage - ;[model_options] - ;bucket = "my-private-bin" - ;prefix = "pastes" - ;uniformacl = false - - ;[model] - ; example of DB configuration for MySQL - ;class = Database - ;[model_options] - ;dsn = "mysql:host=localhost;dbname=privatebin;charset=UTF8" - ;tbl = "privatebin_" ; table prefix - ;usr = "privatebin" - ;pwd = "Z3r0P4ss" - ;opt[12] = true ; PDO::ATTR_PERSISTENT - - ;[model] - ; example of DB configuration for SQLite - ;class = Database - ;[model_options] - ;dsn = "sqlite:" PATH "data/db.sq3" - ;usr = null - ;pwd = null - ;opt[12] = true ; PDO::ATTR_PERSISTENT - - [model] - ; example of DB configuration for PostgreSQL - class = Database - [model_options] - dsn = "pgsql:host=${config.container.module.postgres.address};dbname=privatebin" - tbl = "privatebin_" ; table prefix - usr = "privatebin" - pwd = "privatebin" - opt[12] = true ; PDO::ATTR_PERSISTENT - - ;[model] - ; example of S3 configuration for Rados gateway / CEPH - ;class = S3Storage - ;[model_options] - ;region = "" - ;version = "2006-03-01" - ;endpoint = "https://s3.my-ceph.invalid" - ;use_path_style_endpoint = true - ;bucket = "my-bucket" - ;accesskey = "my-rados-user" - ;secretkey = "my-rados-pass" - - ;[model] - ; example of S3 configuration for AWS - ;class = S3Storage - ;[model_options] - ;region = "eu-central-1" - ;version = "latest" - ;bucket = "my-bucket" - ;accesskey = "access key id" - ;secretkey = "secret access key" - - ;[model] - ; example of S3 configuration for AWS using its SDK default credential provider chain - ; if relying on environment variables, the AWS SDK will look for the following: - ; - AWS_ACCESS_KEY_ID - ; - AWS_SECRET_ACCESS_KEY - ; - AWS_SESSION_TOKEN (if needed) - ; for more details, see https://docs.aws.amazon.com/sdk-for-php/v3/developer-guide/guide_credentials.html#default-credential-chain - ;class = S3Storage - ;[model_options] - ;region = "eu-central-1" - ;version = "latest" - ;bucket = "my-bucket" - - [yourls] - ; When using YOURLS as a "urlshortener" config item: - ; - By default, "urlshortener" will point to the YOURLS API URL, with or without - ; credentials, and will be visible in public on the PrivateBin web page. - ; Only use this if you allow short URL creation without credentials. - ; - Alternatively, using the parameters in this section ("signature" and - ; "apiurl"), "urlshortener" needs to point to the base URL of your PrivateBin - ; instance with "?shortenviayourls&link=" appended. For example: - ; urlshortener = "''${basepath}?shortenviayourls&link=" - ; This URL will in turn call YOURLS on the server side, using the URL from - ; "apiurl" and the "access signature" from the "signature" parameters below. - - ; (optional) the "signature" (access key) issued by YOURLS for the using account - ; signature = "" - ; (optional) the URL of the YOURLS API, called to shorten a PrivateBin URL - ; apiurl = "https://yourls.example.com/yourls-api.php" - ''; + config, + pkgs, + util, + ... +}: { + file = (pkgs.formats.ini { }).generate "PrivateBinConfig" { + main = { + compression = "none"; + defaultformatter = "plaintext"; + discussion = false; + email = true; + fileupload = false; + languageselection = false; + name = "voronind pastebin"; + password = true; + qrcode = true; + sizelimit = 10 * 1000 * 1000; + template = "bootstrap-dark-compact"; + }; + expire = { + default = "1week"; + }; + formatter_options = { + markdown = "Markdown"; + plaintext = "Plain Text"; + syntaxhighlighting = "Source Code"; + }; + traffic = { + limit = 10; + }; + purge = { + limit = 0; + batchsize = 10; + }; + model = { + class = "Database"; + }; + model_options = { + "opt[12]" = true; + dsn = "pgsql:host=${config.container.module.postgres.address};dbname=privatebin"; + pwd = "privatebin"; + tbl = "privatebin_"; + usr = "privatebin"; + }; + }; } diff --git a/package/privatebin/default.nix b/package/privatebin/default.nix index b00bbef..ce06904 100644 --- a/package/privatebin/default.nix +++ b/package/privatebin/default.nix @@ -1,43 +1,36 @@ { - php, - pkgs, - util, - config, - ... -}@args: -let - cfg = pkgs.writeText "PrivateBinConfig" (import ./Config.nix args).text; -in -php.buildComposerProject (finalAttrs: { - pname = "PrivateBin"; - version = "1.7.4"; + config, + php, + pkgs, + ... +} @args: let + cfg = (import ./Config.nix args).file; +in php.buildComposerProject (finalAttrs: { + pname = "PrivateBin"; + vendorHash = "sha256-JGuO8kXLLXqq76EccdNSoHwYO5OuJT3Au1O2O2szAHI="; + version = "1.7.4"; + src = pkgs.fetchFromGitHub { + hash = "sha256-RFP6rhzfBzTmqs4eJXv7LqdniWoeBJpQQ6fLdoGd5Fk="; + owner = "PrivateBin"; + repo = "PrivateBin"; + rev = finalAttrs.version; + }; + installPhase = '' + runHook preInstall - src = pkgs.fetchFromGitHub { - owner = "PrivateBin"; - repo = "PrivateBin"; - rev = finalAttrs.version; - hash = "sha256-RFP6rhzfBzTmqs4eJXv7LqdniWoeBJpQQ6fLdoGd5Fk="; - }; + mv $out/share/php/PrivateBin/* $out + rm -r $out/share - vendorHash = "sha256-JGuO8kXLLXqq76EccdNSoHwYO5OuJT3Au1O2O2szAHI="; + cp ${cfg} $out/cfg/conf.php - installPhase = '' - runHook preInstall + touch $out/.env + pushd $out - mv $out/share/php/PrivateBin/* $out - rm -r $out/share - - cp ${cfg} $out/cfg/conf.php - - touch $out/.env - pushd $out - - runHook postInstall - ''; - - postFixup = '' - substituteInPlace $out/index.php --replace-fail \ - "define('PATH', ''')" \ - "define('PATH', '$out/')" - ''; + runHook postInstall + ''; + postFixup = '' + substituteInPlace $out/index.php --replace-fail \ + "define('PATH', ''')" \ + "define('PATH', '$out/')" + ''; }) diff --git a/package/swayscript/default.nix b/package/swayscript/default.nix index 51a7ef0..76c3fb6 100644 --- a/package/swayscript/default.nix +++ b/package/swayscript/default.nix @@ -1,2 +1,6 @@ -{ pkgs, util, ... }@args: -pkgs.writeShellScriptBin "swayscript" (util.catText (util.ls ./script) args + "\${@}") +{ + pkgs, + util, + ... +} @args: + pkgs.writeShellScriptBin "swayscript" (util.catText (util.ls ./script) args + "\${@}") diff --git a/package/swayscript/script/DisplayWidget.nix b/package/swayscript/script/DisplayWidget.nix index 051c737..b65683d 100644 --- a/package/swayscript/script/DisplayWidget.nix +++ b/package/swayscript/script/DisplayWidget.nix @@ -1,121 +1,120 @@ -{ ... }: -{ - text = '' - function monitor() { - toggle() { - local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') - local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power') +{ ... }: { + text = '' + function monitor() { + toggle() { + local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') + local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .power') - if ''${state}; then - swaymsg "output \"''${output}\" power off" - else - swaymsg "output \"''${output}\" power on" - fi + if ''${state}; then + swaymsg "output \"''${output}\" power off" + else + swaymsg "output \"''${output}\" power on" + fi - pkill -RTMIN+4 waybar - } - _sway_iterate_sockets toggle - } + pkill -RTMIN+4 waybar + } + _sway_iterate_sockets toggle + } - function monitorreset() { - swaymsg 'output * power on' - pkill -RTMIN+4 waybar - } + function monitorreset() { + swaymsg 'output * power on' + pkill -RTMIN+4 waybar + } - function gaming() { - toggle() { - local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') - local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status') + function gaming() { + toggle() { + local output=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .name') + local state=$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .adaptive_sync_status') - if [[ "''${state}" = "disabled" ]]; then - swaymsg "output \"''${output}\" adaptive_sync on" - else - swaymsg "output \"''${output}\" adaptive_sync off" - fi + if [[ "''${state}" = "disabled" ]]; then + swaymsg "output \"''${output}\" adaptive_sync on" + else + swaymsg "output \"''${output}\" adaptive_sync off" + fi - pkill -RTMIN+4 waybar - } - _sway_iterate_sockets toggle - } + pkill -RTMIN+4 waybar + } + _sway_iterate_sockets toggle + } - function gamingreset() { - swaymsg 'output * adaptive_sync off' - pkill -RTMIN+4 waybar - } + function gamingreset() { + swaymsg 'output * adaptive_sync off' + pkill -RTMIN+4 waybar + } - function dnd() { - toggle() { - local state=$(makoctl mode) + function dnd() { + toggle() { + local state=$(makoctl mode) - if [[ "''${state}" = "dnd" ]]; then - makoctl mode -s default - else - makoctl mode -s dnd - fi + if [[ "''${state}" = "dnd" ]]; then + makoctl mode -s default + else + makoctl mode -s dnd + fi - pkill -RTMIN+4 waybar - } - _sway_iterate_sockets toggle - } + pkill -RTMIN+4 waybar + } + _sway_iterate_sockets toggle + } - # Reset the state of everything. - function displayreset() { - [[ "''$(monitorstate)" = "Y" ]] && monitorreset - [[ "''$(gamingstate)" = "Y" ]] && gamingreset - [[ "''$(recordingstate)" = "Y" ]] && pkill wf-recorder - [[ "''$(dndstate)" = "Y" ]] && dnd - true - } + # Reset the state of everything. + function displayreset() { + [[ "''$(monitorstate)" = "Y" ]] && monitorreset + [[ "''$(gamingstate)" = "Y" ]] && gamingreset + [[ "''$(recordingstate)" = "Y" ]] && pkill wf-recorder + [[ "''$(dndstate)" = "Y" ]] && dnd + true + } - # Waybar output. - function displaywidget() { - local _monitorstate=$(monitorstate) - local _gamingstate=$(gamingstate) - local _recordingstate=$(recordingstate) - local _dndstate=$(dndstate) - local class="" + # Waybar output. + function displaywidget() { + local _monitorstate=$(monitorstate) + local _gamingstate=$(gamingstate) + local _recordingstate=$(recordingstate) + local _dndstate=$(dndstate) + local class="" - if [[ "''${_monitorstate}" = "Y" ]] || [[ "''${_gamingstate}" = "Y" ]] || [[ "''${_recordingstate}" = "Y" ]] || [[ "''${_dndstate}" = "Y" ]]; then - class="modified" - fi + if [[ "''${_monitorstate}" = "Y" ]] || [[ "''${_gamingstate}" = "Y" ]] || [[ "''${_recordingstate}" = "Y" ]] || [[ "''${_dndstate}" = "Y" ]]; then + class="modified" + fi - printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${_dndstate} / Monitor: ''${_monitorstate} / Gaming: ''${_gamingstate} / Recording: ''${_recordingstate}\", \"class\": \"''${class}\"}\n" - } + printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${_dndstate} / Monitor: ''${_monitorstate} / Gaming: ''${_gamingstate} / Recording: ''${_recordingstate}\", \"class\": \"''${class}\"}\n" + } - function monitorstate() { - local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power')) + function monitorstate() { + local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power')) - for state in "''${outputs[@]}"; do - ''${state} || { - printf Y - return 1 - } - done + for state in "''${outputs[@]}"; do + ''${state} || { + printf Y + return 1 + } + done - printf n - return 0 - } + printf n + return 0 + } - function recordingstate() { - [[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y - } + function recordingstate() { + [[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y + } - function dndstate() { - [[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n - } + function dndstate() { + [[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n + } - function gamingstate() { - local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status')) + function gamingstate() { + local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status')) - for state in "''${outputs[@]}"; do - [[ "''${state}" = "disabled" ]] || { - printf Y - return 1 - } - done + for state in "''${outputs[@]}"; do + [[ "''${state}" = "disabled" ]] || { + printf Y + return 1 + } + done - printf n - return 0 - } - ''; + printf n + return 0 + } + ''; } diff --git a/package/swayscript/script/Reload.nix b/package/swayscript/script/Reload.nix index 7621838..6348f9b 100644 --- a/package/swayscript/script/Reload.nix +++ b/package/swayscript/script/Reload.nix @@ -1,30 +1,29 @@ -{ ... }: -{ - text = '' - # Reload. - function reload() { - re() { - # Sway. - swaymsg reload +{ ... }: { + text = '' + # Reload. + function reload() { + re() { + # Sway. + swaymsg reload - # Waybar. - pkill waybar - swaymsg exec waybar + # Waybar. + pkill waybar + swaymsg exec waybar - # Tmux. - tmux source-file ~/.config/tmux/tmux.conf + # Tmux. + tmux source-file ~/.config/tmux/tmux.conf - # Bash. - pkill -SIGUSR1 bash + # Bash. + pkill -SIGUSR1 bash - # Notifications. - makoctl reload + # Notifications. + makoctl reload - # Reset displays. - displayreset - } + # Reset displays. + displayreset + } - _sway_iterate_sockets re - } - ''; + _sway_iterate_sockets re + } + ''; } diff --git a/package/swayscript/script/Scratchpad.nix b/package/swayscript/script/Scratchpad.nix index 1e34911..d8ae345 100644 --- a/package/swayscript/script/Scratchpad.nix +++ b/package/swayscript/script/Scratchpad.nix @@ -1,14 +1,13 @@ -{ ... }: -{ - text = '' - # Kill all windows in Sway scratchpad. - function scratchpad_kill() { - kill() { - for window in $(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?) | select(.name == "__i3_scratch").floating_nodes[].id'); do - swaymsg [ con_id="$window" ] kill - done - } - _sway_iterate_sockets kill - } - ''; +{ ... }: { + text = '' + # Kill all windows in Sway scratchpad. + function scratchpad_kill() { + kill() { + for window in $(swaymsg -t get_tree | jq -r 'recurse(.nodes[]?) | select(.name == "__i3_scratch").floating_nodes[].id'); do + swaymsg [ con_id="$window" ] kill + done + } + _sway_iterate_sockets kill + } + ''; } diff --git a/package/swayscript/script/Sound.nix b/package/swayscript/script/Sound.nix index cd51530..fa864ef 100644 --- a/package/swayscript/script/Sound.nix +++ b/package/swayscript/script/Sound.nix @@ -1,17 +1,16 @@ -{ ... }: -{ - text = '' - function sound_output_cycle() { - local IFS=$'\n' - local current=$(pactl get-default-sink) - local all=($(pactl list short sinks | cut -f2)) - local i_current=$(_index_of ''${current} ''${all[@]}) - local i_total=''${#all[@]}; ((i_total--)) - local i_target=0 +{ ... }: { + text = '' + function sound_output_cycle() { + local IFS=$'\n' + local current=$(pactl get-default-sink) + local all=($(pactl list short sinks | cut -f2)) + local i_current=$(_index_of ''${current} ''${all[@]}) + local i_total=''${#all[@]}; ((i_total--)) + local i_target=0 - [[ "''${i_current}" -lt "''${i_total}" ]] && i_target=$((i_current+1)) + [[ "''${i_current}" -lt "''${i_total}" ]] && i_target=$((i_current+1)) - pactl set-default-sink ''${all[''${i_target}]} - } - ''; + pactl set-default-sink ''${all[''${i_target}]} + } + ''; } diff --git a/package/swayscript/script/Util.nix b/package/swayscript/script/Util.nix index 114a634..991d41e 100644 --- a/package/swayscript/script/Util.nix +++ b/package/swayscript/script/Util.nix @@ -1,16 +1,15 @@ -{ ... }: -{ - text = '' - # Find currently active SWAYSOCK paths. - function _sway_find_sockets() { - ls /run/user/''${UID}/sway-ipc.''${UID}.*.sock - } +{ ... }: { + text = '' + # Find currently active SWAYSOCK paths. + function _sway_find_sockets() { + ls /run/user/''${UID}/sway-ipc.''${UID}.*.sock + } - function _sway_iterate_sockets() { - local IFS=$'\n' - for socket in $(_sway_find_sockets); do - SWAYSOCK="''${socket}" ''${1} - done - } - ''; + function _sway_iterate_sockets() { + local IFS=$'\n' + for socket in $(_sway_find_sockets); do + SWAYSOCK="''${socket}" ''${1} + done + } + ''; } diff --git a/package/swayscript/script/Vpn.nix b/package/swayscript/script/Vpn.nix index 701d72c..3b7adf2 100644 --- a/package/swayscript/script/Vpn.nix +++ b/package/swayscript/script/Vpn.nix @@ -1,18 +1,17 @@ -{ ... }: -{ - text = '' - # Toggle vpn. - function vpn() { - if [[ "$(_vpn)" = "on" ]]; then - nmcli connection down vpn - else - nmcli connection up vpn - fi - } +{ ... }: { + text = '' + # Toggle vpn. + function vpn() { + if [[ "$(_vpn)" = "on" ]]; then + nmcli connection down vpn + else + nmcli connection up vpn + fi + } - function _vpn() { - local state=$(nmcli connection show vpn | rg -i state.*activated) - [ "''${state}" != "" ] && printf on || printf off - } - ''; + function _vpn() { + local state=$(nmcli connection show vpn | rg -i state.*activated) + [ "''${state}" != "" ] && printf on || printf off + } + ''; } diff --git a/package/yamusicdownload/default.nix b/package/yamusicdownload/default.nix index 5d8aacb..c4292de 100644 --- a/package/yamusicdownload/default.nix +++ b/package/yamusicdownload/default.nix @@ -1,24 +1,22 @@ -{ pkgs, ... }: -with pkgs.python3Packages; -buildPythonPackage { - version = "1.0.0"; - pname = "yandex-music-downloader"; - format = "pyproject"; - - propagatedBuildInputs = [ - setuptools - setuptools-git - requests - eyed3 - browser-cookie3 - ]; - - src = pkgs.fetchFromGitHub { - owner = "llistochek"; - repo = "yandex-music-downloader"; - rev = "08ea384869cbc31efb1e78b831e2356882219951"; - hash = "sha256-WOFesD7HjskyqHaXZAPy3pgSPaEO+tOyQ+5MV3ZO7XU="; - }; - - meta.mainProgram = "yandex-music-downloader"; +{ + pkgs, + ... +}: with pkgs.python3Packages; buildPythonPackage { + format = "pyproject"; + meta.mainProgram = "yandex-music-downloader"; + pname = "yandex-music-downloader"; + version = "1.0.0"; + propagatedBuildInputs = [ + browser-cookie3 + eyed3 + requests + setuptools + setuptools-git + ]; + src = pkgs.fetchFromGitHub { + hash = "sha256-WOFesD7HjskyqHaXZAPy3pgSPaEO+tOyQ+5MV3ZO7XU="; + owner = "llistochek"; + repo = "yandex-music-downloader"; + rev = "08ea384869cbc31efb1e78b831e2356882219951"; + }; } diff --git a/package/ytdlp/default.nix b/package/ytdlp/default.nix index c943d2a..62a74c4 100644 --- a/package/ytdlp/default.nix +++ b/package/ytdlp/default.nix @@ -1,37 +1,31 @@ { - lib, - stdenv, - fetchurl, - autoPatchelfHook, -}: -let - version = "2024.05.27"; - hash = "sha256-rwVwteYBlqF4WhLn9I/Hy3tXRbC7mHDKL+btkN3YC0Y="; -in -stdenv.mkDerivation { - name = "ytdlp"; - - dontUnpack = true; - - # https://github.com/yt-dlp/yt-dlp - src = fetchurl { - url = "https://github.com/yt-dlp/yt-dlp/releases/download/${version}/yt-dlp_linux"; - sha256 = "${hash}"; - }; - - nativeBuildInputs = [ autoPatchelfHook ]; - - installPhase = '' - mkdir -p $out/bin - cp $src $out/bin/yt-dlp - chmod +x $out/bin/yt-dlp - ''; - - meta = with lib; { - description = "Youtube Downloader."; - homepage = "https://github.com/yt-dlp/yt-dlp"; - license = licenses.unlicense; - meta.platforms = platforms.all; - mainProgram = "yt-dlp"; - }; + autoPatchelfHook, + fetchurl, + lib, + stdenv, +}: let + hash = "sha256-rwVwteYBlqF4WhLn9I/Hy3tXRbC7mHDKL+btkN3YC0Y="; + version = "2024.05.27"; +in stdenv.mkDerivation { + dontUnpack = true; + name = "ytdlp"; + src = fetchurl { + sha256 = "${hash}"; + url = "https://github.com/yt-dlp/yt-dlp/releases/download/${version}/yt-dlp_linux"; + }; + nativeBuildInputs = [ + autoPatchelfHook + ]; + installPhase = '' + mkdir -p $out/bin + cp $src $out/bin/yt-dlp + chmod +x $out/bin/yt-dlp + ''; + meta = with lib; { + description = "Youtube Downloader."; + homepage = "https://github.com/yt-dlp/yt-dlp"; + license = licenses.unlicense; + mainProgram = "yt-dlp"; + meta.platforms = platforms.all; + }; } diff --git a/secret/default.nix b/secret/default.nix index 5d50691..905f4c9 100644 --- a/secret/default.nix +++ b/secret/default.nix @@ -1,79 +1,75 @@ -{ ... }: -{ - # Password used for root user. - hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; # Use `mkpasswd -s`. +{ ... }: { + # Password used for root user. + hashedPassword = "$y$j9T$oqCB16i5E2t1t/HAWaFd5.$tTaHtAcifXaDVpTcRv.yH2/eWKxKE9xM8KcqXHfHrD7"; # Use `mkpasswd -s`. - ssh = { - # Keys that are allowed to connect via SSH. - trustedKeys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJTI4IUkHH0JSzWDKOAMbzEDbyBXOrmTHRy+tpqJ8twx nix-on-droid@nothing2" - (builtins.readFile ./Ssh.key) - ]; + ssh = { + # Keys that are allowed to connect via SSH. + trustedKeys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJTI4IUkHH0JSzWDKOAMbzEDbyBXOrmTHRy+tpqJ8twx nix-on-droid@nothing2" + (builtins.readFile ./Ssh.key) + ]; - # Keys that are allowd to connect via SSH to nixbuild user for Nix remote builds. - builderKey = "nixbuilder-1:Skghjixd8lPzNe2ZEgYLM9Pu/wF9wiZtZGsdm3bo9h0="; - buildKeys = [ - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuuw5ek5wGB9KdBhCTxjV+CBpPU6RIOynHkFYC4dau3 root@dasha" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGIf192IxsksM6u8UY+eqpHopebgV+NNq2G03ssdXIgz root@desktop" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJSWdbkYsRiDlKu8iT/k+JN4KY08iX9qh4VyqxlpEZcE root@home" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFgiYKFkMfiGOZCZIk+O7LtaoF6A3cHEFCqaPwXOM4rR root@work" - "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPnQ9axOX01pq4EANGOR+5+MMm+pV9GpAAKPc5+fnoBQ root@laptop" - ]; - }; + # Keys that are allowd to connect via SSH to nixbuild user for Nix remote builds. + builderKey = "nixbuilder-1:Skghjixd8lPzNe2ZEgYLM9Pu/wF9wiZtZGsdm3bo9h0="; + buildKeys = [ + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIEuuw5ek5wGB9KdBhCTxjV+CBpPU6RIOynHkFYC4dau3 root@dasha" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIGIf192IxsksM6u8UY+eqpHopebgV+NNq2G03ssdXIgz root@desktop" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJSWdbkYsRiDlKu8iT/k+JN4KY08iX9qh4VyqxlpEZcE root@home" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIFgiYKFkMfiGOZCZIk+O7LtaoF6A3cHEFCqaPwXOM4rR root@work" + "ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIPnQ9axOX01pq4EANGOR+5+MMm+pV9GpAAKPc5+fnoBQ root@laptop" + ]; + }; - crypto = { - # Git commit signing. - sign.git = { - format = "ssh"; - key = ./Ssh.key; - allowed = ./Signers.key; - }; + crypto = { + # Git commit signing. + sign.git = { + allowed = ./Signers.key; + format = "ssh"; + key = ./Ssh.key; + }; - # List of accepted public keys. - publicKeys = [ - { - source = ./Gpg.key; - trust = 5; - } - ]; - }; + # List of accepted public keys. + publicKeys = [ + { + source = ./Gpg.key; + trust = 5; + } + ]; + }; - tg = { - # Ob fs lo l. - bt = - "ht" - + "tp" - + "s://ap" - + "i.tel" - + "egra" - + "m.or" - + "g/bo" - + "t2046" - + "84944" - + "1:A" - + "AHQpjRK" - + "4xpL" - + "8tEUyN" - + "4JTSD" - + "UUze" - + "4J0wSI" - + "y4/" - + "sen" - + "dMes" - + "sage"; - dt = - dn: - "{\\\"cha" - + "t_i" - + "d\\\":\\\"155" - + "8973" - + "58\\\",\\\"te" - + "xt\\\":\\\"$" - + "1\\\",\\\"di" - + "sabl" - + "e_no" - + "tific" - + "atio" - + "n\\\":\\\"${dn}\\\"}"; - }; + tg = { + # Ob fs lo l. + bt = "ht" + + "tp" + + "s://ap" + + "i.tel" + + "egra" + + "m.or" + + "g/bo" + + "t2046" + + "84944" + + "1:A" + + "AHQpjRK" + + "4xpL" + + "8tEUyN" + + "4JTSD" + + "UUze" + + "4J0wSI" + + "y4/" + + "sen" + + "dMes" + + "sage"; + dt = dn: "{\\\"cha" + + "t_i" + + "d\\\":\\\"155" + + "8973" + + "58\\\",\\\"te" + + "xt\\\":\\\"$" + + "1\\\",\\\"di" + + "sabl" + + "e_no" + + "tific" + + "atio" + + "n\\\":\\\"${dn}\\\"}"; + }; } diff --git a/system/Bootloader.nix b/system/Bootloader.nix index c115393..38c94bc 100644 --- a/system/Bootloader.nix +++ b/system/Bootloader.nix @@ -1,42 +1,32 @@ -{ ... }: -{ - # Enable non-free firmware. - hardware.enableRedistributableFirmware = true; +{ ... }: { + # Enable non-free firmware. + hardware.enableRedistributableFirmware = true; - # Configure bootloader. - boot = { - loader = { - efi.canTouchEfiVariables = true; - - # Use systemd to boot. - systemd-boot = { - enable = true; - - # Limit the amound of generations availabe for rollback. - # This helps to save storage space. - configurationLimit = 10; - }; - }; - - # Mount /tmp on tmpfs. - tmp.useTmpfs = true; - - initrd = { - # Don't really know if I need it. Kept from hardware-configuration. - kernelModules = [ "dm-snapshot" ]; - - # Kernel modules available for all the hosts. - availableKernelModules = [ - "ahci" - "ata_piix" - "mptspi" - "nvme" - "sd_mod" - "sr_mod" - "usb_storage" - "usbhid" - "xhci_pci" - ]; - }; - }; + # Configure bootloader. + boot = { + tmp.useTmpfs = true; + loader = { + efi.canTouchEfiVariables = true; + systemd-boot = { + enable = true; + configurationLimit = 10; + }; + }; + initrd = { + kernelModules = [ + "dm-snapshot" + ]; + availableKernelModules = [ + "ahci" + "ata_piix" + "mptspi" + "nvme" + "sd_mod" + "sr_mod" + "usb_storage" + "usbhid" + "xhci_pci" + ]; + }; + }; } diff --git a/system/Crypto.nix b/system/Crypto.nix index bd22ab6..b881f70 100644 --- a/system/Crypto.nix +++ b/system/Crypto.nix @@ -1,29 +1,33 @@ -{ pkgs, ... }: { - # GPG. - services.udev.packages = [ pkgs.yubikey-personalization ]; + pkgs, + ... +}: { + # GPG. + services.udev.packages = [ + pkgs.yubikey-personalization + ]; - programs.gnupg.agent = { - enable = true; - enableSSHSupport = true; - pinentryPackage = pkgs.pinentry-tty; - }; + programs.gnupg.agent = { + enable = true; + enableSSHSupport = true; + pinentryPackage = pkgs.pinentry-tty; + }; - # PCSC. - services.pcscd.enable = true; + # PCSC. + services.pcscd.enable = true; - # Yubikey touch notification. - # ISSUE: Not working on Sway with Mako for some reason. - programs.yubikey-touch-detector.enable = true; + # Yubikey touch notification. + # ISSUE: Not working on Sway with Mako for some reason. + programs.yubikey-touch-detector.enable = true; - environment.systemPackages = with pkgs; [ - libfido2 - yubikey-manager - # yubioath-desktop # OTP. - ]; + environment.systemPackages = with pkgs; [ + libfido2 + yubikey-manager + # yubioath-desktop # OTP. + ]; - # Store GPG data on tmpfs. - # environment.variables = { - # GNUPGHOME = "$(mktemp -d -t gnupg-$(date +%Y-%m-%d)-XXXXXXXXXX)"; - # }; + # Store GPG data on tmpfs. + # environment.variables = { + # GNUPGHOME = "$(mktemp -d -t gnupg-$(date +%Y-%m-%d)-XXXXXXXXXX)"; + # }; } diff --git a/system/Dbus.nix b/system/Dbus.nix index 822f5ab..11c4da2 100644 --- a/system/Dbus.nix +++ b/system/Dbus.nix @@ -1,4 +1,3 @@ -{ ... }: -{ - services.dbus.implementation = "broker"; +{ ... }: { + services.dbus.implementation = "broker"; } diff --git a/system/Filesystem.nix b/system/Filesystem.nix index c46594c..3ca566b 100644 --- a/system/Filesystem.nix +++ b/system/Filesystem.nix @@ -1,24 +1,17 @@ # I use the same layout on all hosts with GPT labels. # This way I can configure system's FS in one place here. -{ ... }: -{ - fileSystems."/" = { - device = "/dev/disk/by-partlabel/NIXROOT"; - fsType = "ext4"; - options = [ "noatime" ]; - }; - - fileSystems."/boot" = { - device = "/dev/disk/by-partlabel/NIXBOOT"; - fsType = "vfat"; - }; - - # /etc overlay. - # ISSUE: Should be fixed when you read this. Try it! - # boot.initrd.systemd.enable = true; - # systemd.sysusers.enable = true; - # system.etc.overlay = { - # enable = true; - # mutable = false; - # }; +{ ... }: { + fileSystems = { + "/" = { + device = "/dev/disk/by-partlabel/NIXROOT"; + fsType = "ext4"; + options = [ + "noatime" + ]; + }; + "/boot" = { + device = "/dev/disk/by-partlabel/NIXBOOT"; + fsType = "vfat"; + }; + }; } diff --git a/system/Firewall.nix b/system/Firewall.nix index fb2b763..5c9a0aa 100644 --- a/system/Firewall.nix +++ b/system/Firewall.nix @@ -1,4 +1,3 @@ -{ ... }: -{ - networking.firewall.enable = true; +{ ... }: { + networking.firewall.enable = true; } diff --git a/system/Font.nix b/system/Font.nix index cd18899..f52a9d6 100644 --- a/system/Font.nix +++ b/system/Font.nix @@ -1,16 +1,12 @@ -{ pkgs, __findFile, ... }: { - fonts.packages = with pkgs; [ - # Use Apple fonts for system and text. - (pkgs.callPackage { }) - - # Use Nerd version of Terminus for monospaced fonts. - (nerdfonts.override { fonts = [ "Terminus" ]; }) - - # I don't use FA, but add it for compatibility. - font-awesome - - # Minecraft font. - minecraftia - ]; + __findFile, + pkgs, + ... +}: { + fonts.packages = with pkgs; [ + (nerdfonts.override { fonts = [ "Terminus" ]; }) + (pkgs.callPackage { }) + font-awesome + minecraftia + ]; } diff --git a/system/Fstrim.nix b/system/Fstrim.nix index c7d1151..7b47580 100644 --- a/system/Fstrim.nix +++ b/system/Fstrim.nix @@ -1,4 +1,3 @@ -{ ... }: -{ - services.fstrim.enable = true; +{ ... }: { + services.fstrim.enable = true; } diff --git a/system/Locale.nix b/system/Locale.nix index 87355b0..74c95dd 100644 --- a/system/Locale.nix +++ b/system/Locale.nix @@ -1,18 +1,20 @@ -{ const, ... }: { - time.timeZone = const.timeZone; - i18n.defaultLocale = "en_US.UTF-8"; - - # You can customize your Locale in detail like that. - i18n.extraLocaleSettings = { - LC_ADDRESS = "ru_RU.UTF-8"; - LC_IDENTIFICATION = "ru_RU.UTF-8"; - LC_MEASUREMENT = "ru_RU.UTF-8"; - LC_MONETARY = "ru_RU.UTF-8"; - LC_NAME = "ru_RU.UTF-8"; - LC_NUMERIC = "en_GB.UTF-8"; - LC_PAPER = "ru_RU.UTF-8"; - LC_TELEPHONE = "ru_RU.UTF-8"; - LC_TIME = "en_GB.UTF-8"; - }; + const, + ... +}: { + time.timeZone = const.timeZone; + i18n = { + defaultLocale = "en_US.UTF-8"; + extraLocaleSettings = { + LC_ADDRESS = "ru_RU.UTF-8"; + LC_IDENTIFICATION = "ru_RU.UTF-8"; + LC_MEASUREMENT = "ru_RU.UTF-8"; + LC_MONETARY = "ru_RU.UTF-8"; + LC_NAME = "ru_RU.UTF-8"; + LC_NUMERIC = "en_GB.UTF-8"; + LC_PAPER = "ru_RU.UTF-8"; + LC_TELEPHONE = "ru_RU.UTF-8"; + LC_TIME = "en_GB.UTF-8"; + }; + }; } diff --git a/system/Network.nix b/system/Network.nix index 1704b66..aed97f6 100644 --- a/system/Network.nix +++ b/system/Network.nix @@ -1,7 +1,9 @@ -{ lib, ... }: { - networking = { - useDHCP = lib.mkDefault true; - networkmanager.enable = true; - }; + lib, + ... +}: { + networking = { + useDHCP = lib.mkDefault true; + networkmanager.enable = true; + }; } diff --git a/system/Nix.nix b/system/Nix.nix index d32932c..3a4d4fe 100644 --- a/system/Nix.nix +++ b/system/Nix.nix @@ -1,37 +1,13 @@ -{ ... }: -{ - # Allow installation of proprietary software. - nixpkgs.config.allowUnfree = true; - - nix.settings = { - # Deduplicate store automatically. Slows down switches a bit, but saves space. - auto-optimise-store = true; - - # Allow use of flakes. - experimental-features = [ - "nix-command " - "flakes" - ]; - - # When running GC, keep .drv files. - keep-derivations = true; - - # When running GC, keep build dependencies. - keep-outputs = true; - - # Run GC automatically when there's a less free space than specified. - min-free = 1 * 1000 * 1000 * 1000; - }; - - # NOTE: Currently I run GC completely, but this setting (put above near min-free) - # can stop GC when you hit 101 GB of free space available. - # max-free = ${toString 101 * 1024 * 1024 * 1024} - - # NOTE: Enable this if you want to run GC on schedule. I instead use `min-free`. - # nix.gc = { - # automatic = true; - # dates = "weekly"; - # options = "--delete-older-than 30d"; - # persistent = true; - # }; +{ ... }: { + nixpkgs.config.allowUnfree = true; + nix.settings = { + auto-optimise-store = true; + keep-derivations = true; + keep-outputs = true; + min-free = 1 * 1000 * 1000 * 1000; + experimental-features = [ + "flakes" + "nix-command " + ]; + }; } diff --git a/system/Shell.nix b/system/Shell.nix index 85a6338..e6fec60 100644 --- a/system/Shell.nix +++ b/system/Shell.nix @@ -1,5 +1,7 @@ -{ lib, ... }: { - # Remove default aliases for `l`, `ll` etc as they break my function definitions. - environment.shellAliases = lib.mkForce { }; + lib, + ... +}: { + # Remove default aliases for `l`, `ll` etc as they break my function definitions. + environment.shellAliases = lib.mkForce { }; } diff --git a/system/Sshd.nix b/system/Sshd.nix index fadfb1c..27f3352 100644 --- a/system/Sshd.nix +++ b/system/Sshd.nix @@ -1,39 +1,36 @@ -{ secret, ... }: { - users.users.root.openssh.authorizedKeys.keys = secret.ssh.trustedKeys; - - services.openssh = { - enable = true; - allowSFTP = true; - # openFirewall = false; - ports = [ 22143 ]; - listenAddresses = [ - { - addr = "0.0.0.0"; - port = 22143; - } - ]; - settings = { - AllowUsers = [ - "root" - "nixbuilder" - ]; - LoginGraceTime = "1m"; - # MaxAuthTries = 1; - MaxSessions = 10; - PermitRootLogin = "prohibit-password"; - StrictModes = false; - - UseDns = false; - UsePAM = true; - - GSSAPIAuthentication = false; - HostbasedAuthentication = false; - KbdInteractiveAuthentication = false; - KerberosAuthentication = false; - PasswordAuthentication = false; - PermitEmptyPasswords = false; - PubkeyAuthentication = true; - }; - }; + secret, + ... +}: { + users.users.root.openssh.authorizedKeys.keys = secret.ssh.trustedKeys; + services.openssh = { + enable = true; + allowSFTP = true; + ports = [ + 22143 + ]; + listenAddresses = [{ + addr = "0.0.0.0"; + port = 22143; + }]; + settings = { + GSSAPIAuthentication = false; + HostbasedAuthentication = false; + KbdInteractiveAuthentication = false; + KerberosAuthentication = false; + LoginGraceTime = "1m"; + MaxSessions = 10; + PasswordAuthentication = false; + PermitEmptyPasswords = false; + PermitRootLogin = "prohibit-password"; + PubkeyAuthentication = true; + StrictModes = false; + UseDns = false; + UsePAM = true; + AllowUsers = [ + "root" + "nixbuilder" + ]; + }; + }; } diff --git a/system/Stylix.nix b/system/Stylix.nix new file mode 100644 index 0000000..0e2db63 --- /dev/null +++ b/system/Stylix.nix @@ -0,0 +1,33 @@ +{ + config, + ... +}: let + style = config.module.style; + wallpaper = config.module.wallpaper; +in { + stylix = { + inherit (config.module.style) cursor; + enable = true; + autoEnable = true; + image = wallpaper.path; + polarity = "dark"; + fonts = with style.font; { + inherit emoji monospace sansSerif serif; + sizes = with size; { + inherit desktop terminal; + applications = application; + popups = popup; + }; + }; + opacity = with style.opacity; { + inherit desktop terminal; + applications = application; + popups = popups; + }; + override = if wallpaper.forceContrastText then { + base04 = "000000"; + base05 = "ffffff"; + base06 = "ffffff"; + } else { }; + }; +} diff --git a/system/Systemd.nix b/system/Systemd.nix index 47cc1e9..101454c 100644 --- a/system/Systemd.nix +++ b/system/Systemd.nix @@ -1,20 +1,21 @@ -{ ... }: -{ - # HACK: Fix for broken tmpfiles setup for some services like PowerLimit. - systemd.timers.tmpfilesfix = { - timerConfig = { - OnBootSec = 5; - Unit = "systemd-tmpfiles-resetup.service"; - }; - wantedBy = [ "timers.target" ]; - }; +{ ... }: { + # HACK: Fix for broken tmpfiles setup for some services like PowerLimit. + systemd.timers.tmpfilesfix = { + timerConfig = { + OnBootSec = 5; + Unit = "systemd-tmpfiles-resetup.service"; + }; + wantedBy = [ + "timers.target" + ]; + }; - # Systemd custom target for Sway. - systemd.user.targets.gui-session = { - after = [ "graphical-session-pre.target" ]; - bindsTo = [ "graphical-session.target" ]; - description = "GUI session."; - documentation = [ "man:systemd.special(7)" ]; - wants = [ "graphical-session-pre.target" ]; - }; + # Systemd custom target for Sway. + systemd.user.targets.gui-session = { + after = [ "graphical-session-pre.target" ]; + bindsTo = [ "graphical-session.target" ]; + description = "GUI session."; + documentation = [ "man:systemd.special(7)" ]; + wants = [ "graphical-session-pre.target" ]; + }; } diff --git a/system/Users.nix b/system/Users.nix index 53edb55..fd731c0 100644 --- a/system/Users.nix +++ b/system/Users.nix @@ -1,8 +1,7 @@ -{ ... }: -{ - # Default UMASK. - # security.loginDefs.settings.UMASK = "077"; +{ ... }: { + # Default UMASK. + # security.loginDefs.settings.UMASK = "077"; - # Disallow users modification outside of this config. - users.mutableUsers = false; + # Disallow users modification outside of this config. + users.mutableUsers = false; } diff --git a/system/Vm.nix b/system/Vm.nix index d369b2f..83028c2 100644 --- a/system/Vm.nix +++ b/system/Vm.nix @@ -1,27 +1,29 @@ -{ lib, ... }: { - # SEE: https://github.com/name-snrl/nixos-configuration/blob/e7f6b0f664dbee82e3bf3e85a98cdc3088abe602/modules/nixos/profiles/system/vm-config.nix#L1 - virtualisation.vmVariant = { - module = { - autoupdate.enable = lib.mkForce false; - builder.client.enable = lib.mkForce false; - keyd.enable = lib.mkForce false; - }; - virtualisation = { - cores = 4; - diskImage = null; - diskSize = 20 * 1024; - memorySize = 4 * 1024; - msize = 1024 * 1024; - restrictNetwork = false; - resolution = { - x = 1280; - y = 720; - }; - sharedDirectories.experiments = { - source = "$HOME"; - target = "/mnt/home"; - }; - }; - }; + lib, + ... +}: { + # SEE: https://github.com/name-snrl/nixos-configuration/blob/e7f6b0f664dbee82e3bf3e85a98cdc3088abe602/modules/nixos/profiles/system/vm-config.nix#L1 + virtualisation.vmVariant = { + module = { + autoupdate.enable = lib.mkForce false; + builder.client.enable = lib.mkForce false; + keyd.enable = lib.mkForce false; + }; + virtualisation = { + cores = 4; + diskImage = null; + diskSize = 20 * 1024; + memorySize = 4 * 1024; + msize = 1024 * 1024; + restrictNetwork = false; + resolution = { + x = 1280; + y = 720; + }; + sharedDirectories.experiments = { + source = "$HOME"; + target = "/mnt/home"; + }; + }; + }; } diff --git a/system/Zram.nix b/system/Zram.nix index 511f113..24b1318 100644 --- a/system/Zram.nix +++ b/system/Zram.nix @@ -1,4 +1,3 @@ -{ ... }: -{ - zramSwap.enable = true; +{ ... }: { + zramSwap.enable = true; } diff --git a/user/Dasha.nix b/user/Dasha.nix index eb1af8d..5f0156f 100644 --- a/user/Dasha.nix +++ b/user/Dasha.nix @@ -1,35 +1,32 @@ -{ lib, config, ... }: -with lib; -let - cfg = config.user.dasha; -in { - options = { - user.dasha = { - enable = mkEnableOption "dasha"; - }; - }; + lib, + config, + ... +}: let + cfg = config.user.dasha; +in { + options.user.dasha = { + enable = lib.mkEnableOption "dasha"; + }; - config = mkIf cfg.enable { - home.nixos.users = [ - { - username = "dasha"; - homeDirectory = "/home/dasha"; - } - ]; - users.users.dasha = { - createHome = true; - description = "Daria Dranchak"; - hashedPassword = "$y$j9T$WGMPv/bRhGBUidcZLZ7CE/$raZhwFFdI/XvegVZVHLILJLMiBkOxSErc6gao/Cxt33"; - isNormalUser = true; - uid = 1001; - extraGroups = [ - "input" - "keyd" - "libvirtd" - "networkmanager" - "video" - ]; - }; - }; + config = lib.mkIf cfg.enable { + home.nixos.users = [{ + homeDirectory = "/home/dasha"; + username = "dasha"; + }]; + users.users.dasha = { + createHome = true; + description = "Daria Dranchak"; + hashedPassword = "$y$j9T$WGMPv/bRhGBUidcZLZ7CE/$raZhwFFdI/XvegVZVHLILJLMiBkOxSErc6gao/Cxt33"; + isNormalUser = true; + uid = 1001; + extraGroups = [ + "input" + "keyd" + "libvirtd" + "networkmanager" + "video" + ]; + }; + }; } diff --git a/user/Root.nix b/user/Root.nix index 8e2d0ea..821f036 100644 --- a/user/Root.nix +++ b/user/Root.nix @@ -1,33 +1,27 @@ { - lib, - config, - secret, - ... -}: -with lib; -let - cfg = config.user.root; -in -{ - options = { - user.root = { - enable = mkEnableOption "root"; - }; - }; + config, + lib, + secret, + util, + ... +}: let + cfg = config.user.root; +in { + options.user.root = { + enable = lib.mkEnableOption "root"; + }; - config = mkIf cfg.enable { - home.nixos.users = [ - { - username = "root"; - homeDirectory = "/root"; - } - ]; - users.users.root.hashedPassword = secret.hashedPassword; - security.sudo = { - enable = false; - extraConfig = '' - Defaults rootpw - ''; - }; - }; + config = lib.mkIf cfg.enable { + users.users.root.hashedPassword = secret.hashedPassword; + home.nixos.users = [{ + homeDirectory = "/root"; + username = "root"; + }]; + security.sudo = { + enable = false; + extraConfig = util.trimTabs '' + Defaults rootpw + ''; + }; + }; } diff --git a/user/Voronind.nix b/user/Voronind.nix index f572129..e394fb7 100644 --- a/user/Voronind.nix +++ b/user/Voronind.nix @@ -1,40 +1,33 @@ { - lib, - config, - secret, - ... -}: -with lib; -let - cfg = config.user.voronind; -in -{ - options = { - user.voronind = { - enable = mkEnableOption "voronind"; - }; - }; + config, + lib, + secret, + ... +}: let + cfg = config.user.voronind; +in { + options.user.voronind = { + enable = lib.mkEnableOption "voronind"; + }; - config = mkIf cfg.enable { - home.nixos.users = [ - { - username = "voronind"; - homeDirectory = "/home/voronind"; - } - ]; - users.users.voronind = { - createHome = true; - description = "Dmitry Voronin"; - hashedPassword = secret.hashedPassword; - isNormalUser = true; - uid = 1000; - extraGroups = [ - "input" - "keyd" - "libvirtd" - "networkmanager" - "video" - ]; - }; - }; + config = lib.mkIf cfg.enable { + home.nixos.users = [{ + homeDirectory = "/home/voronind"; + username = "voronind"; + }]; + users.users.voronind = { + createHome = true; + description = "Dmitry Voronin"; + hashedPassword = secret.hashedPassword; + isNormalUser = true; + uid = 1000; + extraGroups = [ + "input" + "keyd" + "libvirtd" + "networkmanager" + "video" + ]; + }; + }; }