diff --git a/.editorconfig b/.editorconfig index 5fc8085..2b92926 100644 --- a/.editorconfig +++ b/.editorconfig @@ -2,22 +2,12 @@ end_of_line = lf charset = utf-8 indent_style = tab -indent_size = 2 insert_final_newline = true trim_trailing_whitespace = true -[*.{nix,js}] -indent_size = 2 - -[*.lua] -indent_size = 4 - -[*.sh] -indent_size = 8 - -[Makefile] -indent_size = 2 +[*.nix] +indent_style = space +indent_size = 2 [*.md] -indent_size = 8 trim_trailing_whitespace = false diff --git a/.treefmt.toml b/.treefmt.toml new file mode 100644 index 0000000..c1b1831 --- /dev/null +++ b/.treefmt.toml @@ -0,0 +1,15 @@ +# 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" +includes = [ "*.nix" ] diff --git a/Makefile b/Makefile index 500724f..c20387c 100644 --- a/Makefile +++ b/Makefile @@ -26,6 +26,9 @@ check: fix-ulimit: ulimit -n 999999999 +format: + treefmt --no-cache --on-unmatched=info + gc: nix-collect-garbage -d # nix-store --gc diff --git a/config/Setting.nix b/config/Setting.nix index 2ad2da3..2ad400f 100644 --- a/config/Setting.nix +++ b/config/Setting.nix @@ -1,67 +1,68 @@ # 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; - }; - }; - }; - }; +{ 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; - }; + # 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; - }; - }; - }; - }; + # 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; - }; - }; - }; - }; - }; - }; - }; - }; + # 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 index 99df513..4fa4ae9 100644 --- a/config/Style.nix +++ b/config/Style.nix @@ -1,108 +1,117 @@ -{ lib, config, pkgs, __findFile, ... }: with lib; let - cfg = config.style; +{ + 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"; + 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; + 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; + 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; + 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; + 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; + 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; + 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; - }; + 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"; - }; - }; + 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"; - }; + 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 "Adwaita"; + package = mkPkgOption pkgs.adwaita-icon-theme; + size = mkIntOption 14; + }; - window = { - gap = mkIntOption 8; - border = mkIntOption 4; - }; - }; + window = { + gap = mkIntOption 8; + border = mkIntOption 4; + }; + }; } diff --git a/config/Stylix.nix b/config/Stylix.nix index d55486b..cd03e95 100644 --- a/config/Stylix.nix +++ b/config/Stylix.nix @@ -1,27 +1,42 @@ -{ 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 {}; - }; +{ + 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 index 2e4a046..b7d2a89 100644 --- a/config/Wallpaper.nix +++ b/config/Wallpaper.nix @@ -1,18 +1,21 @@ -{ pkgs, lib, ... }: with lib; let - url = "https://i.imgur.com/gYy0mzG.jpeg"; - sha256 = "0pwnq84mdbv8nrarhnbkq77iabwgh7znr0yig3fnshamxl2a3k7k"; - forceContrastText = true; -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; - }; - }; - }; +{ pkgs, lib, ... }: +with lib; +let + url = "https://i.imgur.com/gYy0mzG.jpeg"; + sha256 = "0pwnq84mdbv8nrarhnbkq77iabwgh7znr0yig3fnshamxl2a3k7k"; + forceContrastText = true; +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 06ec9a2..2c22527 100644 --- a/container/Change.nix +++ b/container/Change.nix @@ -1,49 +1,59 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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/Cloud.nix b/container/Cloud.nix index 84db157..e29401b 100644 --- a/container/Cloud.nix +++ b/container/Cloud.nix @@ -1,73 +1,87 @@ -{ container, pkgs, lib, config, ... } @args: with lib; let - cfg = config.container.module.cloud; +{ + container, + pkgs, + lib, + config, + ... +}@args: +with lib; +let + cfg = config.container.module.cloud; - 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; - }; - }; - }; + 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 = 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"}"; + 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; - }; - }; - }; - }; - }; + 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; + }; + }; + }; + }; + }; } diff --git a/container/Ddns.nix b/container/Ddns.nix index 7937926..1be06e7 100644 --- a/container/Ddns.nix +++ b/container/Ddns.nix @@ -1,54 +1,67 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 f0eb584..3822f5b 100644 --- a/container/Dns.nix +++ b/container/Dns.nix @@ -1,128 +1,141 @@ -{ container, pkgs, lib, config, util, ... } @args: with lib; let - cfg = config.container.module.dns; -in { - options = { - container.module.dns = { - enable = mkEnableOption "Dns server."; - address = mkOption { - default = "10.1.0.6"; - type = types.str; - }; - port = mkOption { - default = 53; - type = types.int; - }; - }; - }; +{ + container, + pkgs, + lib, + config, + util, + ... +}@args: +with lib; +let + cfg = config.container.module.dns; +in +{ + options = { + container.module.dns = { + enable = mkEnableOption "Dns server."; + address = mkOption { + default = "10.1.0.6"; + type = types.str; + }; + port = mkOption { + default = 53; + type = types.int; + }; + }; + }; - config = mkIf cfg.enable { - containers.dns = container.mkContainer cfg { - config = { ... }: container.mkContainerConfig cfg { - environment.systemPackages = [ - pkgs.cloudflared - ]; + config = 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 = "${getExe pkgs.cloudflared} proxy-dns --port 5054"; - }; - }; + systemd.services.cloudflared = { + description = "Cloudflare DoH server."; + enable = true; + wantedBy = [ "multi-user.target" ]; + serviceConfig = { + Type = "simple"; + ExecStart = "${getExe pkgs.cloudflared} proxy-dns --port 5054"; + }; + }; - services.blocky = { - enable = true; - settings = { - upstream = { - default = [ - "0.0.0.0:5054" - "0.0.0.0:5054" - ]; - }; - blocking = { - blackLists = { - suspicious = [ - "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" - "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt" - "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts" - "https://v.firebog.net/hosts/static/w3kbl.txt" - ]; - ads = [ - "https://easylist-downloads.adblockplus.org/bitblock.txt" - "https://adaway.org/hosts.txt" - "https://v.firebog.net/hosts/AdguardDNS.txt" - "https://v.firebog.net/hosts/Admiral.txt" - "https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt" - "https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt" - "https://v.firebog.net/hosts/Easylist.txt" - "https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" - "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts" - "https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts" - "https://github.com/easylist/ruadlist/blob/master/advblock/adservers.txt" - ]; - tracking = [ - "https://v.firebog.net/hosts/Easyprivacy.txt" - "https://v.firebog.net/hosts/Prigent-Ads.txt" - "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts" - "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt" - "https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt" - ]; - malicious = [ - "https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt" - "https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt" - "https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt" - "https://v.firebog.net/hosts/Prigent-Crypto.txt" - "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts" - "https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt" - "https://phishing.army/download/phishing_army_blocklist_extended.txt" - "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt" - "https://v.firebog.net/hosts/RPiList-Malware.txt" - "https://v.firebog.net/hosts/RPiList-Phishing.txt" - "https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt" - "https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts" - "https://urlhaus.abuse.ch/downloads/hostfile/" - ]; - other = [ - "https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser" - ]; - }; - # whiteLists = { - # other = [ - # "/.*.vk.com/" - # ]; - # }; - clientGroupsBlock = { - default = [ - "suspicious" - "ads" - "tracking" - "malicious" - "other" - ]; - }; - }; - customDNS = { - mapping = let - block = "0.0.0.0"; - in { - # All subdomains to current host. - # ${config.container.domain} = config.container.host; - "voronind.com" = "10.0.0.1"; + services.blocky = { + enable = true; + settings = { + upstream = { + default = [ + "0.0.0.0:5054" + "0.0.0.0:5054" + ]; + }; + blocking = { + blackLists = { + suspicious = [ + "https://raw.githubusercontent.com/StevenBlack/hosts/master/hosts" + "https://raw.githubusercontent.com/PolishFiltersTeam/KADhosts/master/KADhosts.txt" + "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Spam/hosts" + "https://v.firebog.net/hosts/static/w3kbl.txt" + ]; + ads = [ + "https://easylist-downloads.adblockplus.org/bitblock.txt" + "https://adaway.org/hosts.txt" + "https://v.firebog.net/hosts/AdguardDNS.txt" + "https://v.firebog.net/hosts/Admiral.txt" + "https://raw.githubusercontent.com/anudeepND/blacklist/master/adservers.txt" + "https://s3.amazonaws.com/lists.disconnect.me/simple_ad.txt" + "https://v.firebog.net/hosts/Easylist.txt" + "https://pgl.yoyo.org/adservers/serverlist.php?hostformat=hosts&showintro=0&mimetype=plaintext" + "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/UncheckyAds/hosts" + "https://raw.githubusercontent.com/bigdargon/hostsVN/master/hosts" + "https://github.com/easylist/ruadlist/blob/master/advblock/adservers.txt" + ]; + tracking = [ + "https://v.firebog.net/hosts/Easyprivacy.txt" + "https://v.firebog.net/hosts/Prigent-Ads.txt" + "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.2o7Net/hosts" + "https://raw.githubusercontent.com/crazy-max/WindowsSpyBlocker/master/data/hosts/spy.txt" + "https://hostfiles.frogeye.fr/firstparty-trackers-hosts.txt" + ]; + malicious = [ + "https://raw.githubusercontent.com/DandelionSprout/adfilt/master/Alternate%20versions%20Anti-Malware%20List/AntiMalwareHosts.txt" + "https://osint.digitalside.it/Threat-Intel/lists/latestdomains.txt" + "https://s3.amazonaws.com/lists.disconnect.me/simple_malvertising.txt" + "https://v.firebog.net/hosts/Prigent-Crypto.txt" + "https://raw.githubusercontent.com/FadeMind/hosts.extras/master/add.Risk/hosts" + "https://bitbucket.org/ethanr/dns-blacklists/raw/8575c9f96e5b4a1308f2f12394abd86d0927a4a0/bad_lists/Mandiant_APT1_Report_Appendix_D.txt" + "https://phishing.army/download/phishing_army_blocklist_extended.txt" + "https://gitlab.com/quidsup/notrack-blocklists/raw/master/notrack-malware.txt" + "https://v.firebog.net/hosts/RPiList-Malware.txt" + "https://v.firebog.net/hosts/RPiList-Phishing.txt" + "https://raw.githubusercontent.com/Spam404/lists/master/main-blacklist.txt" + "https://raw.githubusercontent.com/AssoEchap/stalkerware-indicators/master/generated/hosts" + "https://urlhaus.abuse.ch/downloads/hostfile/" + ]; + other = [ + "https://zerodot1.gitlab.io/CoinBlockerLists/hosts_browser" + ]; + }; + # whiteLists = { + # other = [ + # "/.*.vk.com/" + # ]; + # }; + clientGroupsBlock = { + default = [ + "suspicious" + "ads" + "tracking" + "malicious" + "other" + ]; + }; + }; + customDNS = { + mapping = + let + block = "0.0.0.0"; + in + { + # All subdomains to current host. + # ${config.container.domain} = config.container.host; + "voronind.com" = "10.0.0.1"; - # Blocklist. - "gosuslugi.ru" = block; - "rutube.ru" = block; - "vk.com" = block; - }; - }; - port = cfg.port; - # httpPort = "80"; - }; - }; - }; - }; - }; + # Blocklist. + "gosuslugi.ru" = block; + "rutube.ru" = block; + "vk.com" = block; + }; + }; + port = cfg.port; + # httpPort = "80"; + }; + }; + }; + }; + }; } - diff --git a/container/Download.nix b/container/Download.nix index a29b6ae..86ec040 100644 --- a/container/Download.nix +++ b/container/Download.nix @@ -1,60 +1,70 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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; - }; + 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 = "1d"; - }; - }; - }; - }; + systemd.services.deluged.serviceConfig = { + MemoryLimit = cfg.memLimit; + Restart = lib.mkForce "always"; + RuntimeMaxSec = "1d"; + }; + }; + }; + }; } diff --git a/container/Frkn.nix b/container/Frkn.nix index 50f9123..9c10e9b 100644 --- a/container/Frkn.nix +++ b/container/Frkn.nix @@ -1,118 +1,132 @@ # 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; - }; - }; - }; +{ + 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; + }; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 { + boot.kernel.sysctl = { + "net.ipv4.conf.all.src_valid_mark" = 1; + "net.ipv4.ip_forward" = 1; + }; - imports = [ ]; - module.zapret = { - enable = true; - params = config.module.zapret.params; - }; + imports = [ ]; + module.zapret = { + enable = true; + params = config.module.zapret.params; + }; - services = { - microsocks = { - enable = true; - ip = cfg.address; - port = cfg.port; - disableLogging = true; - #authUsername - #outgoingBindIp - #authOnce - }; + services = { + microsocks = { + enable = true; + ip = cfg.address; + port = cfg.port; + disableLogging = true; + #authUsername + #outgoingBindIp + #authOnce + }; - 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" - ]; - }; + 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" + ]; + }; - client = { - enable = true; - #dns.enable = true; - socksListenAddress = { - IsolateDestAddr = true; - addr = cfg.address; - port = cfg.torport; - }; - }; - }; + client = { + enable = true; + #dns.enable = true; + socksListenAddress = { + IsolateDestAddr = true; + addr = cfg.address; + port = cfg.torport; + }; + }; + }; - xray = { - enable = true; - settingsFile = "/data/Client.json"; - }; - }; + xray = { + enable = true; + settingsFile = "/data/Client.json"; + }; + }; - systemd = { - services.tor.wantedBy = lib.mkForce []; + systemd = { + services.tor.wantedBy = lib.mkForce [ ]; - timers.tor = { - timerConfig = { - OnBootSec = 5; - Unit = "tor.service"; - }; - wantedBy = [ "timers.target" ]; - }; - }; - }; - }; - }; + timers.tor = { + timerConfig = { + OnBootSec = 5; + Unit = "tor.service"; + }; + wantedBy = [ "timers.target" ]; + }; + }; + }; + }; + }; } diff --git a/container/Git.nix b/container/Git.nix index eb1ff8c..7e5c3f1 100644 --- a/container/Git.nix +++ b/container/Git.nix @@ -1,108 +1,123 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 + { + type = "postgres"; + host = postgre.address; + port = postgre.port; + user = "forgejo"; + name = "forgejo"; + createDatabase = false; + }; - 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}"; + 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; - }; - }; - }; - }; - }; + 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; + }; + }; + }; + }; + }; } diff --git a/container/Hdd.nix b/container/Hdd.nix index accb5eb..23d0899 100644 --- a/container/Hdd.nix +++ b/container/Hdd.nix @@ -1,70 +1,81 @@ # 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; - }; - }; - }; +{ + 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" - ]; + 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"; - # }; + 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"; - # } - # ]; + # allowedDevices = [ + # { + # modifier = "rwm"; + # node = "/dev/sda"; + # } + # ]; - # additionalCapabilities = [ "CAP_SYS_ADMIN" ]; + # additionalCapabilities = [ "CAP_SYS_ADMIN" ]; - config = { ... }: container.mkContainerConfig cfg { - environment.systemPackages = with pkgs; [ smartmontools ]; + config = + { ... }: + container.mkContainerConfig cfg { + environment.systemPackages = with pkgs; [ smartmontools ]; - services.scrutiny = { - enable = true; - settings.web = { - listen = { - host = cfg.address; - port = cfg.port; - }; - }; - }; - }; - }; - }; + services.scrutiny = { + enable = true; + settings.web = { + listen = { + host = cfg.address; + port = cfg.port; + }; + }; + }; + }; + }; + }; } diff --git a/container/Home.nix b/container/Home.nix index b0d97a1..9b26b8e 100644 --- a/container/Home.nix +++ b/container/Home.nix @@ -1,45 +1,58 @@ -{ 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; - }; - }; - }; +{ + 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; + }; + }; + }; - config = mkIf cfg.enable { - containers.home = container.mkContainer cfg { - config = { ... }: container.mkContainerConfig cfg { - environment.systemPackages = [ package ]; - systemd.packages = [ package ]; + config = 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}"; + services.nginx = { + enable = true; + virtualHosts.${cfg.domain} = container.mkServer { + default = true; + root = "${package}"; - locations = { - "/".extraConfig = '' - try_files $uri $uri/index.html; - ''; - }; - }; - }; - }; - }; - }; + locations = { + "/".extraConfig = '' + try_files $uri $uri/index.html; + ''; + }; + }; + }; + }; + }; + }; } diff --git a/container/Iot.nix b/container/Iot.nix index 79cb6b7..66a039b 100644 --- a/container/Iot.nix +++ b/container/Iot.nix @@ -1,110 +1,125 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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; + 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; + }; - # 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 = mkForce [ ]; + timers.fixsystemd = { + timerConfig = { + OnBootSec = 15; + Unit = "home-assistant.service"; + }; + wantedBy = [ "timers.target" ]; + }; + }; + }; + }; + }; } diff --git a/container/Jobber.nix b/container/Jobber.nix index e7d6e94..6cf6e04 100644 --- a/container/Jobber.nix +++ b/container/Jobber.nix @@ -1,66 +1,85 @@ -{ 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; - }; - }; - }; +{ + 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; + }; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 = + { lib, ... }: + 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; + wantedBy = [ "multi-user.target" ]; + path = packages; + environment = { + PYTHONUNBUFFERED = "1"; + PYTHONDONTWRITEBYTECODE = "1"; + }; + serviceConfig = { + Type = "simple"; + ExecStart = "${script}/bin/jobber -u"; + Restart = "on-failure"; + }; + }; + }; + }; + }; } diff --git a/container/Mail.nix b/container/Mail.nix index ae63079..8337d18 100644 --- a/container/Mail.nix +++ b/container/Mail.nix @@ -1,228 +1,246 @@ # 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - # "data/indices" - # "data/vmail" - # "data/sieve" - # "data/dkim" - ]; + config = mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + # "data/indices" + # "data/vmail" + # "data/sieve" + # "data/dkim" + ]; - 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 { + url = "https://gitlab.com/simple-nixos-mailserver/nixos-mailserver/-/archive/nixos-${const.stateVersion}/nixos-mailserver-nixos-${const.stateVersion}.tar.gz"; + sha256 = "sha256:0clvw4622mqzk1aqw1qn6shl9pai097q62mq1ibzscnjayhp278b"; + }) + ]; - 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}" = { + 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; + }; + }; - 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"; + certificateScheme = "manual"; + keyFile = "/acme/live/${domain}/privkey.pem"; + certificateFile = "/acme/live/${domain}/cert.pem"; - indexDir = "/var/lib/dovecot/indices"; - mailDirectory = "/var/vmail"; - sieveDirectory = "/var/sieve"; - dkimKeyDirectory = "/var/dkim"; + indexDir = "/var/lib/dovecot/indices"; + mailDirectory = "/var/vmail"; + sieveDirectory = "/var/sieve"; + dkimKeyDirectory = "/var/dkim"; - 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 = { + 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"; + }; + }; - 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; + 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"; + ''; + }; - nginx = { - virtualHosts.${cfg.domain} = { - forceSSL = false; - enableACME = false; - }; - }; - }; + nginx = { + virtualHosts.${cfg.domain} = { + forceSSL = false; + enableACME = 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 = '' + 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 0f9f3a0..90858a2 100644 --- a/container/Office.nix +++ b/container/Office.nix @@ -2,93 +2,107 @@ # 1. You need to change PSQL tables owner from root to onlyoffice, too. They don't do that automatically for some reason. # 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 = { - 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"; - }; - }; - }; + # 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 576d6da..e19a963 100644 --- a/container/Paper.nix +++ b/container/Paper.nix @@ -1,96 +1,108 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 = "${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 = + { 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}"; + }; + }; - # 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 = 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" ]; + }; + }; + }; + }; + }; } diff --git a/container/Pass.nix b/container/Pass.nix index 2c631d6..c68e864 100644 --- a/container/Pass.nix +++ b/container/Pass.nix @@ -1,57 +1,67 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 = { + # 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; + }; + }; + }; + }; + }; } diff --git a/container/Paste.nix b/container/Paste.nix index 8863201..a167a8f 100644 --- a/container/Paste.nix +++ b/container/Paste.nix @@ -1,126 +1,138 @@ -{ pkgs, util, 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; - }; - }; - }; +{ + 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; + }; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - "tmp" - "nginxtmp" - "config" - ]; + config = mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + "tmp" + "nginxtmp" + "config" + ]; - 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 = { + user = "paste"; + group = "nginx"; - phpPackage = pkgs.php; + phpPackage = pkgs.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"; - }; + 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"; + }; - phpEnv = { - # CONFIG_PATH = "${package}/cfg"; - }; - }; + phpEnv = { + # CONFIG_PATH = "${package}/cfg"; + }; + }; - services.nginx = { - enable = true; - virtualHosts.${cfg.domain} = container.mkServer { - default = true; - root = "${package}"; + services.nginx = { + enable = true; + virtualHosts.${cfg.domain} = container.mkServer { + default = true; + root = "${package}"; - locations = { - "/".extraConfig = '' - rewrite ^ /index.php; - ''; + locations = { + "/".extraConfig = '' + rewrite ^ /index.php; + ''; - "~ \\.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; - ''; + "~ \\.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 = util.trimTabs '' - 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; - ''; - }; + "~ \\.(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 = util.trimTabs '' - try_files $uri /index.php; - ''; - }; - }; - }; - }; - }; + extraConfig = '' + try_files $uri /index.php; + ''; + }; + }; + }; + }; + }; } diff --git a/container/Postgres.nix b/container/Postgres.nix index 13a81f7..55ecfb4 100644 --- a/container/Postgres.nix +++ b/container/Postgres.nix @@ -1,86 +1,105 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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; - 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; + 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 = builtins.foldl' (acc: item: acc + "${item}\n") "" ( + mapAttrsToList (db: cfg: "host ${db} ${db} ${cfg.address}/32 trust") access + ); - ensureDatabases = [ "root" ] ++ mapAttrsToList (name: _: name) configurations; + ensureDatabases = [ "root" ] ++ 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; + ensureClauses = + if name == "root" then + { + superuser = true; + createrole = true; + createdb = true; + } + else + { }; + ensureDBOwnership = true; + }) ensureDatabases; + in + { + inherit authentication ensureDatabases ensureUsers; - enable = true; - package = pkgs.postgresql_14; - dataDir = "/var/lib/postgresql/data/14"; - enableTCPIP = true; + enable = true; + package = pkgs.postgresql_14; + dataDir = "/var/lib/postgresql/data/14"; + enableTCPIP = true; - # 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 6539a31..422472c 100644 --- a/container/Print.nix +++ b/container/Print.nix @@ -2,66 +2,79 @@ # 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; - }; - }; - }; +{ + 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; + }; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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"; + 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 2d810f9..8ceaae9 100644 --- a/container/Proxy.nix +++ b/container/Proxy.nix @@ -9,107 +9,119 @@ # ssl_ciphers "ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384"; # ``` # 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "challenge" - "letsencrypt" - ]; + config = 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; - recommendedOptimisation = true; - recommendedProxySettings = true; - clientMaxBodySize = "4096m"; - appendConfig = util.trimTabs '' - worker_processes 4; - ''; - eventsConfig = util.trimTabs '' - worker_connections 4096; - ''; - # TODO: Fix 80 redirect and 403 default. - 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; + ''; + # TODO: Fix 80 redirect and 403 default. + appendHttpConfig = '' + proxy_max_temp_file_size 0; + proxy_buffering off; - server { - server_name default_server; - listen 80; + server { + server_name default_server; + listen 80; - location / { - return 301 https://$host$request_uri; - } - } + location / { + return 301 https://$host$request_uri; + } + } - map $http_accept_language $resume { - default https://git.${config.container.domain}/voronind/resume/releases/download/latest/VoronindEn.pdf; - ~ru https://git.${config.container.domain}/voronind/resume/releases/download/latest/VoronindRu.pdf; - } + map $http_accept_language $resume { + default https://git.${config.container.domain}/voronind/resume/releases/download/latest/VoronindEn.pdf; + ~ru https://git.${config.container.domain}/voronind/resume/releases/download/latest/VoronindRu.pdf; + } - server { - server_name ${config.container.domain}; - listen 443 ssl; + server { + server_name ${config.container.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; - return 301 $resume; - } + return 301 $resume; + } - 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 4b43651..d8f3f17 100644 --- a/container/Rabbitmq.nix +++ b/container/Rabbitmq.nix @@ -1,48 +1,60 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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; + listenAddress = cfg.address; + port = cfg.port; + dataDir = "/var/lib/rabbitmq"; + configItems = { + "loopback_users" = "none"; + }; + }; + }; + }; + }; } diff --git a/container/Read.nix b/container/Read.nix index ad9634d..f59a3f4 100644 --- a/container/Read.nix +++ b/container/Read.nix @@ -1,55 +1,63 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 4a11e53..4fe74f3 100644 --- a/container/Redis.nix +++ b/container/Redis.nix @@ -1,31 +1,42 @@ -{ 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; - }; - }; - }; +{ + 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 = 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 = 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 92af1bf..a48e0d9 100644 --- a/container/Search.nix +++ b/container/Search.nix @@ -1,43 +1,54 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - containers.search = container.mkContainer cfg { - config = { ... }: container.mkContainerConfig cfg { - services.searx = { - enable = true; - package = pkgs.searxng; - settings = { - server = { - bind_address = cfg.address; - port = cfg.port; - secret_key = "searxxx"; - }; - }; - }; - }; - }; - }; + config = mkIf cfg.enable { + containers.search = container.mkContainer cfg { + config = + { ... }: + container.mkContainerConfig cfg { + services.searx = { + enable = true; + package = pkgs.searxng; + settings = { + server = { + bind_address = cfg.address; + port = cfg.port; + secret_key = "searxxx"; + }; + }; + }; + }; + }; + }; } diff --git a/container/Status.nix b/container/Status.nix index c1a8858..7362416 100644 --- a/container/Status.nix +++ b/container/Status.nix @@ -1,62 +1,71 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 = + { lib, ... }: + container.mkContainerConfig cfg { + networking = { + nameservers = 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 = mkForce false; + }; + }; + }; + }; } - diff --git a/container/Stock.nix b/container/Stock.nix index d57f6a3..c018341 100644 --- a/container/Stock.nix +++ b/container/Stock.nix @@ -1,57 +1,67 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - ]; + config = 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 c4ecdc8..b448a64 100644 --- a/container/Vpn.nix +++ b/container/Vpn.nix @@ -1,88 +1,100 @@ -{ container, pkgs, lib, config, ... }: with lib; let - cfg = config.container.module.vpn; +{ + container, + pkgs, + lib, + config, + ... +}: +with lib; +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 = 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; + }; + }; + }; - config = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - "data/preshared" - ]; + config = 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 { + boot.kernel.sysctl = { + "net.ipv4.conf.all.src_valid_mark" = 1; + "net.ipv4.ip_forward" = 1; + }; - 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; - }; - }; + 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 = { + IPv4Forwarding = "yes"; + IPMasquerade = "ipv4"; + }; + }; + }; + }; + }; + }; } - diff --git a/container/Watch.nix b/container/Watch.nix index cd48d13..c80d038 100644 --- a/container/Watch.nix +++ b/container/Watch.nix @@ -1,86 +1,96 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable { - systemd.tmpfiles.rules = container.mkContainerDir cfg [ - "data" - "cache" - ]; + config = mkIf cfg.enable { + systemd.tmpfiles.rules = container.mkContainerDir cfg [ + "data" + "cache" + ]; - 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" - # ]; + config = + { ... }: + container.mkContainerConfig cfg { + # users.users.jellyfin.extraGroups = [ + # "video" + # "render" + # ]; - services.jellyfin = { - enable = true; - cacheDir = "/var/cache/jellyfin"; - dataDir = "/var/lib/jellyfin"; - }; + services.jellyfin = { + enable = true; + cacheDir = "/var/cache/jellyfin"; + dataDir = "/var/lib/jellyfin"; + }; - systemd.services.jellyfin.serviceConfig.MemoryLimit = cfg.memLimit; - }; - }; - }; + systemd.services.jellyfin.serviceConfig.MemoryLimit = cfg.memLimit; + }; + }; + }; } diff --git a/container/Yt.nix b/container/Yt.nix index 3871221..3b69355 100644 --- a/container/Yt.nix +++ b/container/Yt.nix @@ -1,52 +1,64 @@ -{ 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; - }; - }; - }; +{ + 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; + }; + }; + }; - 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 = 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; + }; + }; + }; + }; + }; } diff --git a/container/default.nix b/container/default.nix index e859cd6..e2b9b1c 100644 --- a/container/default.nix +++ b/container/default.nix @@ -1,58 +1,61 @@ -{ lib, config, ... }: with lib; let - cfg = config.container; -in { - options = { - container = { - enable = mkEnableOption "Containers!!"; +{ lib, config, ... }: +with lib; +let + cfg = config.container; +in +{ + options = { + container = { + enable = mkEnableOption "Containers!!"; - autoStart = mkOption { - default = false; - type = types.bool; - }; + autoStart = mkOption { + default = false; + type = types.bool; + }; - host = mkOption { - default = "0.0.0.0"; - type = types.str; - }; + host = mkOption { + default = "0.0.0.0"; + type = types.str; + }; - localAccess = 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; - }; + storage = mkOption { + default = "/tmp/container"; + type = types.str; + }; - domain = mkOption { - default = "local"; - type = types.str; - }; + domain = mkOption { + default = "local"; + type = types.str; + }; - interface = mkOption { - default = "lo"; - type = types.str; - }; + interface = mkOption { + default = "lo"; + type = types.str; + }; - media = mkOption { - default = {}; - type = types.attrs; - }; - }; - }; + 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 = 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-*" ]; + }; + }; } diff --git a/container/proxy/host/Camera.nix b/container/proxy/host/Camera.nix index 17a2a6a..e0c7aa2 100644 --- a/container/proxy/host/Camera.nix +++ b/container/proxy/host/Camera.nix @@ -1,25 +1,31 @@ -{ util, config, lib, container, ... }: let - domain = "camera.${config.container.domain}"; - address = "192.168.2.249"; - port = 554; -in { - ${domain} = container.mkServer { - extraConfig = util.trimTabs '' - listen 443 ssl; +{ + config, + container, + ... +}: +let + domain = "camera.${config.container.domain}"; + address = "192.168.2.249"; + port = 554; +in +{ + ${domain} = container.mkServer { + extraConfig = '' + 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 24cc349..0915cb2 100644 --- a/container/proxy/host/Change.nix +++ b/container/proxy/host/Change.nix @@ -1,28 +1,30 @@ -{ util, config, container, ... }: 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}; +{ 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}; - 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/Cloud.nix b/container/proxy/host/Cloud.nix index 5c37f2b..e660113 100644 --- a/container/proxy/host/Cloud.nix +++ b/container/proxy/host/Cloud.nix @@ -1,30 +1,31 @@ -{ util, config, container, ... }: 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}; +{ 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}; - 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 6749def..70c70e1 100644 --- a/container/proxy/host/Download.nix +++ b/container/proxy/host/Download.nix @@ -1,25 +1,27 @@ -{ util, config, container, ... }: 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}; +{ 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}; - 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 00df02d..a754936 100644 --- a/container/proxy/host/Git.nix +++ b/container/proxy/host/Git.nix @@ -1,33 +1,35 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 / { - # 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/Hdd.nix b/container/proxy/host/Hdd.nix index 6f26ad3..fc628c3 100644 --- a/container/proxy/host/Hdd.nix +++ b/container/proxy/host/Hdd.nix @@ -1,25 +1,31 @@ -{ util, container, config, ... }: let - cfg = config.container.module.hdd; - name = "hdd"; -in { - ${cfg.domain} = container.mkServer { - extraConfig = util.trimTabs '' - listen 443 ssl; - set ''$${name} ${cfg.address}:${toString cfg.port}; +{ + 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; - } + 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/Home.nix b/container/proxy/host/Home.nix index 06d3106..566306e 100644 --- a/container/proxy/host/Home.nix +++ b/container/proxy/host/Home.nix @@ -1,25 +1,31 @@ -{ util, config, container, ... }: 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}; +{ + 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}; - 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 189f93b..afb5c05 100644 --- a/container/proxy/host/Iot.nix +++ b/container/proxy/host/Iot.nix @@ -1,32 +1,38 @@ -{ util, container, config, ... }: 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}; +{ + 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}; - 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 4484abf..11ab27d 100644 --- a/container/proxy/host/Mail.nix +++ b/container/proxy/host/Mail.nix @@ -1,25 +1,27 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 ea4530a..089b226 100644 --- a/container/proxy/host/Office.nix +++ b/container/proxy/host/Office.nix @@ -1,26 +1,28 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 3043d02..c79ad93 100644 --- a/container/proxy/host/Paper.nix +++ b/container/proxy/host/Paper.nix @@ -1,25 +1,27 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 7c42af5..0d6ede0 100644 --- a/container/proxy/host/Pass.nix +++ b/container/proxy/host/Pass.nix @@ -1,25 +1,27 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 4fc0ba5..ec0c65a 100644 --- a/container/proxy/host/Paste.nix +++ b/container/proxy/host/Paste.nix @@ -1,24 +1,26 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 8274f0a..8848366 100644 --- a/container/proxy/host/Print.nix +++ b/container/proxy/host/Print.nix @@ -1,30 +1,32 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 b37359c..56d2e04 100644 --- a/container/proxy/host/Printer.nix +++ b/container/proxy/host/Printer.nix @@ -1,27 +1,29 @@ -{ util, container, config, ... }: let - address = "192.168.2.237"; - domain = "printer.${config.container.domain}"; - port = 80; - name = "printer"; -in { - ${domain} = container.mkServer { - extraConfig = util.trimTabs '' - listen 443 ssl; - set ''$${name} ${address}:${toString port}; +{ 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}; - 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 8a3768a..ff18c43 100644 --- a/container/proxy/host/Read.nix +++ b/container/proxy/host/Read.nix @@ -1,25 +1,27 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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/Router.nix b/container/proxy/host/Router.nix index 07b4ffb..83e16e4 100644 --- a/container/proxy/host/Router.nix +++ b/container/proxy/host/Router.nix @@ -1,28 +1,29 @@ -{ util, container, config, ... }: let - address = "10.0.0.2"; - domain = "router.${config.container.domain}"; - port = 80; - name = "router"; -in { - ${domain} = container.mkServer { - extraConfig = util.trimTabs '' - listen 443 ssl; - set ''$${name} ${address}:${toString port}; +{ 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}; - 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 0be1f2c..45d2e5f 100644 --- a/container/proxy/host/Search.nix +++ b/container/proxy/host/Search.nix @@ -1,25 +1,31 @@ -{ util, container, config, ... }: 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}; +{ + 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}; - 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 f093096..a4a0d6f 100644 --- a/container/proxy/host/Status.nix +++ b/container/proxy/host/Status.nix @@ -1,32 +1,34 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 b38ab67..0151865 100644 --- a/container/proxy/host/Stock.nix +++ b/container/proxy/host/Stock.nix @@ -1,25 +1,27 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 b19a049..fd1e36d 100644 --- a/container/proxy/host/Watch.nix +++ b/container/proxy/host/Watch.nix @@ -1,25 +1,27 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 26822b0..be119a0 100644 --- a/container/proxy/host/Yt.nix +++ b/container/proxy/host/Yt.nix @@ -1,35 +1,37 @@ -{ util, container, config, ... }: 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}; +{ 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}; - 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 a6ec922..8ddbbb7 100644 --- a/flake.nix +++ b/flake.nix @@ -1,328 +1,373 @@ # 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"; - nixpkgsStable.url = "github:nixos/nixpkgs/nixos-24.05"; - nixpkgsMaster.url = "github:nixos/nixpkgs/master"; + # 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"; + 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"; + # 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"; - # This means that home-manager and our Flake both depend on the same nixpkgs version. - inputs.nixpkgs.follows = "nixpkgs"; - }; + # This means that home-manager and our Flake both depend on the same nixpkgs version. + inputs.nixpkgs.follows = "nixpkgs"; + }; - # 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"; + # 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"; - # 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"; + # 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 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"; - }; + # 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"; + }; - # 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; - }; - 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; - }; - nvimOllama = { - url = "github:nomnivore/ollama.nvim"; - 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; - }; - }; + # 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; + }; + 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; + }; + nvimOllama = { + url = "github:nomnivore/ollama.nvim"; + 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; + }; + }; - # 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, 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"; - }; + # 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, + 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"; + }; - # Hack to use in other files. - # Need to add __findFile to args tho. - __findFile = _: p: ./${p}; + # Hack to use in other files. + # Need to add __findFile to args tho. + __findFile = _: p: ./${p}; - # 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) - ) - ); + # 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) + ) + ); - # 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 - ]; - # 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}"; + }; + }; - # 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; + # 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; - # 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; } + # 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; } - # Specify current release version. - { system.stateVersion = self.const.stateVersion; } + # Specify current release version. + { system.stateVersion = self.const.stateVersion; } - # Add Home Manager module. - home-manager.nixosModules.home-manager + # Add Home Manager module. + home-manager.nixosModules.home-manager - # Add Stylix module. - stylix.nixosModules.stylix + # Add Stylix module. + stylix.nixosModules.stylix - # 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); + # 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; + # 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; - pkgsMaster = nixpkgsMaster.legacyPackages.${system}.pkgs; + pkgsJobber = nixpkgsJobber.legacyPackages.${system}.pkgs; + pkgsStable = nixpkgsStable.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. + 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; - }; - }; + # 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)) - ); + 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; }; - # 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: homeDirectory: system: modules: + let + pkgs = nixpkgs.legacyPackages.${system}; + pkgsStable = nixpkgsStable.legacyPackages.${system}; + pkgsMaster = nixpkgsMaster.legacyPackages.${system}; + in + { + ${username} = home-manager.lib.homeManagerConfiguration { + inherit pkgs; - mkCommonHome = username: homeDirectory: system: modules: let - pkgs = nixpkgs.legacyPackages.${system}; - pkgsStable = nixpkgsStable.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 homeDirectory; + enable = true; + package = { + core.enable = true; + }; + }; + } - extraSpecialArgs = { - inherit self inputs secret util pkgs pkgsStable pkgsMaster; - inherit (self) const __findFile; - }; - modules = [ - ./home/HomeManager.nix - { - home.hm = { - inherit username homeDirectory; - enable = true; - package = { - core.enable = true; - }; - }; - } + { nixpkgs.config.allowUnfree = true; } + { nixpkgs.config.allowUnfreePredicate = (pkg: true); } + { nix.package = pkgs.nix; } + { + nix.settings.experimental-features = [ + "nix-command " + "flakes" + ]; + } - { nixpkgs.config.allowUnfree = true; } - { nixpkgs.config.allowUnfreePredicate = (pkg: true); } - { nix.package = pkgs.nix; } - { nix.settings.experimental-features = [ "nix-command " "flakes" ]; } + inputs.stylix.homeManagerModules.stylix + ] ++ modules ++ (self.findFiles ./config); + }; + }; - inputs.stylix.homeManagerModules.stylix - ] - ++ modules - ++ (self.findFiles ./config); - }; - }; + x86LinuxHome = username: modules: mkCommonHome username "/home/${username}" "x86_64-linux" modules; + x86LinuxRoot = mkCommonHome "root" "/root" "x86_64-linux" [ ]; + in + nixpkgs.lib.foldl' (acc: h: acc // h) { } [ + x86LinuxRoot + (x86LinuxHome "voronind" [ + { + home.hm.package = { + common.enable = true; + }; + } + ]) + ]; - x86LinuxHome = username: modules: mkCommonHome username "/home/${username}" "x86_64-linux" modules; - x86LinuxRoot = mkCommonHome "root" "/root" "x86_64-linux" []; - in nixpkgs.lib.foldl' (acc: h: acc // h) {} [ - x86LinuxRoot - (x86LinuxHome "voronind" [ - { - home.hm.package = { - common.enable = true; - }; - } - ]) - ]; + # Android. + nixOnDroidConfigurations.default = + let + config = self.nixOnDroidConfigurations.default.config; + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages."aarch64-linux".pkgs; + in + nix-on-droid.lib.nixOnDroidConfiguration { + modules = [ + # Android release version. + { system.stateVersion = self.const.droidStateVersion; } - # Android. - nixOnDroidConfigurations.default = let - config = self.nixOnDroidConfigurations.default.config; - lib = nixpkgs.lib; - pkgs = nixpkgs.legacyPackages."aarch64-linux".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; } - # 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; } - # { 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; + }) + ]; - # 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; - # 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. - }; - }; - }; + secret = import ./secret { }; # Secrets (public keys). + util = import ./lib/Util.nix { inherit lib; }; # Util functions. + }; + }; + }; } # That's it! diff --git a/home/Android.nix b/home/Android.nix index e1e1123..20e1426 100644 --- a/home/Android.nix +++ b/home/Android.nix @@ -1,40 +1,45 @@ # 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; - # homePath = "/data/data/com.termux.nix/files/home"; -in { - options = { - home.android = { - enable = mkEnableOption "Android HM config."; - }; - }; +{ + 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; +in +# homePath = "/data/data/com.termux.nix/files/home"; +{ + options = { + home.android = { + enable = mkEnableOption "Android HM config."; + }; + }; - config = mkIf cfg.enable { - time.timeZone = const.timeZone; - environment.packages = package.core; - home-manager.config = stylix // { - imports = [ inputs.stylix.homeManagerModules.stylix ]; - home = { - stateVersion = const.droidStateVersion; - sessionVariables = import ./variable args; - file = (import ./config args) // { - ".termux/_font.ttf".source = android.font; - ".termux/_colors.properties".text = android.colors; - }; - }; - programs = import ./program args; - }; - }; + config = mkIf cfg.enable { + time.timeZone = const.timeZone; + environment.packages = package.core; + home-manager.config = stylix // { + imports = [ inputs.stylix.homeManagerModules.stylix ]; + home = { + stateVersion = const.droidStateVersion; + sessionVariables = import ./variable args; + file = (import ./config args) // { + ".termux/_font.ttf".source = android.font; + ".termux/_colors.properties".text = android.colors; + }; + }; + programs = import ./program args; + }; + }; } diff --git a/home/HomeManager.nix b/home/HomeManager.nix index 27b7b4f..2537cea 100644 --- a/home/HomeManager.nix +++ b/home/HomeManager.nix @@ -1,59 +1,64 @@ # This is a common user configuration. -{ const -, util -, config -, lib -, __findFile -, ... } @args: with lib; let - cfg = config.home.hm; - package = import 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."; - }; - }; - }; - }; - }; +{ + const, + util, + config, + lib, + __findFile, + ... +}@args: +with lib; +let + cfg = config.home.hm; + package = import 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 = import ./program args; - 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; }) - (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; }) - ]); + 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 = import ./program args; + 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; }) + (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 94d65a3..2c63fe9 100644 --- a/home/NixOs.nix +++ b/home/NixOs.nix @@ -1,44 +1,53 @@ # This is a common user configuration. -{ const -, config -, util -, lib -, pkgs -, ... } @args: with lib; let - cfg = config.home.nixos; -in { - imports = (util.ls ./user); +{ + const, + config, + util, + lib, + pkgs, + ... +}@args: +with lib; +let + cfg = config.home.nixos; +in +{ + imports = (util.ls ./user); - options = { - home.nixos = { - enable = mkEnableOption "NixOS user setup."; - users = mkOption { - default = []; - type = types.listOf types.attrs; - }; - }; - }; + options = { + home.nixos = { + enable = mkEnableOption "NixOS user setup."; + users = mkOption { + default = [ ]; + type = types.listOf types.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 = 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; - # ISSUE: https://github.com/nix-community/home-manager/issues/5589 - extraActivationPath = with pkgs; [ openssh ]; - }; - xdg = import ./xdg { inherit (user) homeDirectory; }; - programs = import ./program args; - dconf.settings = util.catSet (util.ls ./config/dconf) args; - }; - }) {} cfg.users; + # ISSUE: https://github.com/nix-community/home-manager/issues/5589 + extraActivationPath = with pkgs; [ openssh ]; + }; + xdg = import ./xdg { inherit (user) homeDirectory; }; + programs = import ./program args; + dconf.settings = util.catSet (util.ls ./config/dconf) args; + }; + } + ) { } cfg.users; - backupFileExtension = "old"; - }; - }; + backupFileExtension = "old"; + }; + }; } diff --git a/home/android/default.nix b/home/android/default.nix index 1950353..d99a137 100644 --- a/home/android/default.nix +++ b/home/android/default.nix @@ -1,10 +1,13 @@ -{ pkgs, util, config, ... }: { - font = pkgs.runCommandNoCC "font" {} '' - cp ${pkgs.nerdfonts.override { fonts = [ "Terminus" ]; }}/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out - ''; +{ pkgs, config, ... }: +{ + font = pkgs.runCommandNoCC "font" { } '' + cp ${ + pkgs.nerdfonts.override { fonts = [ "Terminus" ]; } + }/share/fonts/truetype/NerdFonts/TerminessNerdFontMono-Regular.ttf $out + ''; - colors = util.trimTabs '' - background=#${config.style.color.bg.dark} - foreground=#${config.style.color.fg.light} - ''; + colors = '' + background=#${config.style.color.bg.dark} + foreground=#${config.style.color.fg.light} + ''; } diff --git a/home/config/btop/default.nix b/home/config/btop/default.nix index ceae331..1385fc0 100644 --- a/home/config/btop/default.nix +++ b/home/config/btop/default.nix @@ -1,249 +1,250 @@ -{ config, util, ... }: { - text = util.trimTabs '' - #? Config file for btop v. 1.3.0 +{ ... }: +{ + 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" + #* 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 + #* 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 + #* 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 + #* 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 = "" + #* 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 + #* 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 + #* 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" + #* 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 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 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_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_net = "default" - # Graph symbol to use for graphs in cpu box, "default", "braille", "block" or "tty". - graph_symbol_proc = "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" + #* 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 + #* 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" + #* 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 + #* Reverse sorting order, True or False. + proc_reversed = False - #* Show processes as a tree. - proc_tree = False + #* Show processes as a tree. + proc_tree = False - #* Use the cpu graph colors in the process list. - proc_colors = True + #* Use the cpu graph colors in the process list. + proc_colors = True - #* Use a darkening gradient in the process list. - proc_gradient = 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 + #* 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 process memory as bytes instead of percent. + proc_mem_bytes = True - #* Show cpu graph for each process. - proc_cpu_graphs = 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 + #* 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 + #* 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 + #* (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 + #* 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 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" + #* 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" + #* 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 + #* 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 + #* 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 + #* Show cpu box at bottom of screen instead of top. + cpu_bottom = False - #* Shows the system uptime in the CPU box. - show_uptime = True + #* Shows the system uptime in the CPU box. + show_uptime = True - #* Show cpu temperature. - check_temp = 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" + #* 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 + #* 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 = "" + #* 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" + #* 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 + #* Use base 10 for bits/bytes sizes, KB = 1000 instead of KiB = 1024. + base_10_sizes = True - #* Show CPU frequency. - show_cpu_freq = 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" + #* 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 + #* 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 = "" + #* 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" + #* 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 graphs instead of meters for memory values. + mem_graphs = True - #* Show mem box below net box instead of above. - mem_below_net = False + #* 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 + #* Count ZFS ARC in cached and available memory. + zfs_arc_cached = True - #* If swap memory should be shown in memory box. - show_swap = 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 + #* 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 + #* 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 + #* 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 + #* 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 + #* 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 + #* 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 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 + #* 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 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 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 + #* 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 + 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 + #* 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 + #* 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 = "" + #* Starts with the Network Interface specified here. + net_iface = "" - #* Show battery stats in top right if battery is present. - show_battery = True + #* 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" + #* 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" + #* 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 + #* 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 + #* Horizontally mirror the GPU graph. + gpu_mirror_graph = True - #* Custom gpu0 model name, empty string to disable. - custom_gpu_name0 = "" + #* Custom gpu0 model name, empty string to disable. + custom_gpu_name0 = "" - #* Custom gpu1 model name, empty string to disable. - custom_gpu_name1 = "" + #* Custom gpu1 model name, empty string to disable. + custom_gpu_name1 = "" - #* Custom gpu2 model name, empty string to disable. - custom_gpu_name2 = "" + #* Custom gpu2 model name, empty string to disable. + custom_gpu_name2 = "" - #* Custom gpu3 model name, empty string to disable. - custom_gpu_name3 = "" + #* Custom gpu3 model name, empty string to disable. + custom_gpu_name3 = "" - #* Custom gpu4 model name, empty string to disable. - custom_gpu_name4 = "" + #* Custom gpu4 model name, empty string to disable. + custom_gpu_name4 = "" - #* Custom gpu5 model name, empty string to disable. - custom_gpu_name5 = "" - ''; + #* Custom gpu5 model name, empty string to disable. + custom_gpu_name5 = "" + ''; } diff --git a/home/config/dconf/Accessibility.nix b/home/config/dconf/Accessibility.nix index 52d86f4..ed4c2db 100644 --- a/home/config/dconf/Accessibility.nix +++ b/home/config/dconf/Accessibility.nix @@ -1,5 +1,6 @@ -{ ... }: { - "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 d35fb66..9afa88a 100644 --- a/home/config/dconf/Gtk.nix +++ b/home/config/dconf/Gtk.nix @@ -1,27 +1,28 @@ -{ ... }: { - "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 bbd30e6..9fe5000 100644 --- a/home/config/dconf/Input.nix +++ b/home/config/dconf/Input.nix @@ -1,21 +1,40 @@ -{ 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; { + 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 ]; + }; - "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 ebbf4c3..ad37863 100644 --- a/home/config/dconf/Interface.nix +++ b/home/config/dconf/Interface.nix @@ -1,11 +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 86af119..1c57e7b 100644 --- a/home/config/dconf/Key.nix +++ b/home/config/dconf/Key.nix @@ -1,132 +1,134 @@ -{ 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 = [ "" ]; - }; +{ 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 = [ "" ]; + }; - "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 01e67e1..fef8d15 100644 --- a/home/config/dconf/Media.nix +++ b/home/config/dconf/Media.nix @@ -1,7 +1,8 @@ -{ ... }: { - "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 e20a08e..253a8aa 100644 --- a/home/config/dconf/Nautilus.nix +++ b/home/config/dconf/Nautilus.nix @@ -1,21 +1,22 @@ -{ ... }: { - "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 06ff8c1..01c55d6 100644 --- a/home/config/dconf/Power.nix +++ b/home/config/dconf/Power.nix @@ -1,10 +1,11 @@ -{ ... }: { - "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 cac090e..f45daf3 100644 --- a/home/config/dconf/Privacy.nix +++ b/home/config/dconf/Privacy.nix @@ -1,15 +1,16 @@ -{ 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 507de9a..7e4b7c7 100644 --- a/home/config/dconf/Session.nix +++ b/home/config/dconf/Session.nix @@ -1,5 +1,6 @@ -{ 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 88cec98..9a867f8 100644 --- a/home/config/dconf/Shell.nix +++ b/home/config/dconf/Shell.nix @@ -1,14 +1,15 @@ -{ ... }: { - "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 11303f2..2c38d0e 100644 --- a/home/config/dconf/Software.nix +++ b/home/config/dconf/Software.nix @@ -1,8 +1,9 @@ -{ ... }: { - "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 743e038..8a42caa 100644 --- a/home/config/dconf/Sound.nix +++ b/home/config/dconf/Sound.nix @@ -1,7 +1,8 @@ -{ ... }: { - "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 84c7a14..64c3ba4 100644 --- a/home/config/dconf/Wm.nix +++ b/home/config/dconf/Wm.nix @@ -1,32 +1,33 @@ -{ 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"; + focus-mode = "click"; # `click` or `sloppy`. + button-layout = "appmenu:close"; + }; - "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 46ac7f7..8b83579 100644 --- a/home/config/default.nix +++ b/home/config/default.nix @@ -1,50 +1,57 @@ -{ self, inputs, config, ... } @args: let - btop = import ./btop 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/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; - # TODO: Add after migrating to stable. - # ".nixpkgs_unstable".source = inputs.nixpkgs; - # ".nixpkgs_master".source = inputs.nixpkgs; - ".parallel/will-cite".text = ""; - ".ssh/config".text = ssh.text; - ".template".source = ./template; +{ + self, + inputs, + config, + ... +}@args: +let + btop = import ./btop 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/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; + # TODO: Add after migrating to stable. + # ".nixpkgs_unstable".source = inputs.nixpkgs; + # ".nixpkgs_master".source = inputs.nixpkgs; + ".parallel/will-cite".text = ""; + ".ssh/config".text = ssh.text; + ".template".source = ./template; } diff --git a/home/config/editorconfig/default.nix b/home/config/editorconfig/default.nix index 4c373ef..72018b6 100644 --- a/home/config/editorconfig/default.nix +++ b/home/config/editorconfig/default.nix @@ -1,32 +1,34 @@ -{ pkgs, ... }: { - file = (pkgs.formats.iniWithGlobalSection {}).generate "EditorconfigConfig" { - globalSection.root = true; +{ 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 = "true"; - trim_trailing_whitespace = "true"; - }; + sections = { + "*" = { + end_of_line = "lf"; + charset = "utf-8"; + indent_style = "tab"; + indent_size = 2; + insert_final_newline = "true"; + trim_trailing_whitespace = "true"; + }; - Makefile = { - indent_size = 2; - }; + "Makefile" = { + indent_size = 4; + }; - "*.{nix,js}" = { - indent_size = 2; - }; + "*.nix" = { + indent_style = "space"; + indent_size = 2; + }; - "*.{lua,kt,kts,rs,py}" = { - indent_size = 4; - }; + "*.{lua,kt,kts,rs,py}" = { + indent_size = 4; + }; - "*.{sh,md}" = { - indent_size = 8; - }; - }; - }; + "*.{sh,md}" = { + indent_size = 8; + }; + }; + }; } diff --git a/home/config/foot/default.nix b/home/config/foot/default.nix index efdac17..bd34307 100644 --- a/home/config/foot/default.nix +++ b/home/config/foot/default.nix @@ -1,28 +1,30 @@ -{ 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"; - }; +{ 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"; - }; - }; - }; + 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"; + }; + }; + }; } diff --git a/home/config/fuzzel/default.nix b/home/config/fuzzel/default.nix index 5493078..783bcbb 100644 --- a/home/config/fuzzel/default.nix +++ b/home/config/fuzzel/default.nix @@ -1,36 +1,40 @@ -{ 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.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; + }; + }; } diff --git a/home/config/git/default.nix b/home/config/git/default.nix index d94308a..e28551d 100644 --- a/home/config/git/default.nix +++ b/home/config/git/default.nix @@ -1,13 +1,14 @@ -{ 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" { + # 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; + }; } diff --git a/home/config/gtk/3/default.nix b/home/config/gtk/3/default.nix index 703de73..ca1944a 100644 --- a/home/config/gtk/3/default.nix +++ b/home/config/gtk/3/default.nix @@ -1,9 +1,10 @@ -{ util, ... }:{ - bookmarks = util.trimTabs '' - 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 - ''; +{ ... }: +{ + 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 3d09a44..7d6fbf8 100644 --- a/home/config/jetbrains/default.nix +++ b/home/config/jetbrains/default.nix @@ -1,26 +1,27 @@ -{ util, ... }: { - ideavimrc = util.trimTabs '' - " Plugins. - Plug 'tpope/vim-commentary' - Plug 'machakann/vim-highlightedyank' - " Plug 'junegunn/vim-easy-align' +{ ... }: +{ + ideavimrc = '' + " 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 cb964d1..2e1c2ad 100644 --- a/home/config/keyd/default.nix +++ b/home/config/keyd/default.nix @@ -1,3 +1,4 @@ -{ 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/DRG.nix b/home/config/keyd/module/DRG.nix index b29bc7b..5bd9689 100644 --- a/home/config/keyd/module/DRG.nix +++ b/home/config/keyd/module/DRG.nix @@ -1,32 +1,33 @@ -{ 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/Firefox.nix b/home/config/keyd/module/Firefox.nix index 26d9a17..edb8217 100644 --- a/home/config/keyd/module/Firefox.nix +++ b/home/config/keyd/module/Firefox.nix @@ -1,24 +1,25 @@ -{ 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.p" = "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.p" = "C-S-l"; # Fill password. + }; + }; } diff --git a/home/config/keyd/module/Jetbrains.nix b/home/config/keyd/module/Jetbrains.nix index 28daba8..dea8f52 100644 --- a/home/config/keyd/module/Jetbrains.nix +++ b/home/config/keyd/module/Jetbrains.nix @@ -1,28 +1,29 @@ -{ pkgs, ... }: { - file = (pkgs.formats.ini {}).generate "KeydJetbrainsConfig" { - "jetbrains-*" = { - "alt./" = "C-/"; # Toggle comment. - "alt.." = "C-f8"; # Toggle line breakpoint. - "alt.=" = "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.=" = "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 80b9d7f..01bd7fb 100644 --- a/home/config/keyd/module/Nautilus.nix +++ b/home/config/keyd/module/Nautilus.nix @@ -1,26 +1,27 @@ -{ 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 899de1f..9daa7ce 100644 --- a/home/config/mako/default.nix +++ b/home/config/mako/default.nix @@ -1,24 +1,26 @@ -{ pkgs, config, ... }: let - alpha = config.style.opacity.hex; -in { - file = (pkgs.formats.iniWithGlobalSection {}).generate "MakoConfig" { - globalSection = { - anchor = "top-center"; - background-color = "#${config.style.color.bg.dark}${alpha}"; - border-color = "#${config.style.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; - }; +{ pkgs, config, ... }: +let + alpha = config.style.opacity.hex; +in +{ + file = (pkgs.formats.iniWithGlobalSection { }).generate "MakoConfig" { + globalSection = { + anchor = "top-center"; + background-color = "#${config.style.color.bg.dark}${alpha}"; + border-color = "#${config.style.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; - }; - }; - }; + sections = { + "mode=dnd" = { + invisible = 1; + }; + }; + }; } diff --git a/home/config/mangohud/default.nix b/home/config/mangohud/default.nix index ef36f3d..e1a52ee 100644 --- a/home/config/mangohud/default.nix +++ b/home/config/mangohud/default.nix @@ -1,44 +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; - }; + 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 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; - }; - }; + "preset 2" = { + full = 1; + }; + }; } diff --git a/home/config/nvim/default.nix b/home/config/nvim/default.nix index b5156ea..9b3d56e 100644 --- a/home/config/nvim/default.nix +++ b/home/config/nvim/default.nix @@ -1,83 +1,91 @@ -{ inputs, pkgs, util, ... } @args: let - # Create Neovim configuration. - nvimRc = { runtimes, configs }: let - # Plugin paths to install. - runtimeRc = util.trimTabs (builtins.foldl' (acc: r: - acc + "set runtimepath+=${r}\n" - ) "" runtimes); +{ + 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; - # 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.nvimGitsigns}" - "${inputs.nvimGruvboxMaterial}" - "${inputs.nvimIndentoMatic}" - "${inputs.nvimLspconfig}" - "${inputs.nvimOllama}" - "${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.nvimGitsigns}" + "${inputs.nvimGruvboxMaterial}" + "${inputs.nvimIndentoMatic}" + "${inputs.nvimLspconfig}" + "${inputs.nvimOllama}" + "${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/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/Ollama.nix - ./module/plugin/Colorizer.nix - ./module/plugin/lsp/Haskell.nix - ./module/plugin/lsp/Rust.nix - ./module/plugin/lsp/Tex.nix - ./module/plugin/lsp/Nix.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/Ollama.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/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/Ollama.nix + ./module/plugin/Colorizer.nix + ./module/plugin/lsp/Haskell.nix + ./module/plugin/lsp/Rust.nix + ./module/plugin/lsp/Tex.nix + ./module/plugin/lsp/Nix.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/Ollama.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 d62589e..54c04f8 100644 --- a/home/config/nvim/module/config/Autoread.nix +++ b/home/config/nvim/module/config/Autoread.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 22e6192..679f3fa 100644 --- a/home/config/nvim/module/config/Etc.nix +++ b/home/config/nvim/module/config/Etc.nix @@ -1,36 +1,37 @@ -{ ... }: { - 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 dd2202d..2eaecab 100644 --- a/home/config/nvim/module/config/Highlight.nix +++ b/home/config/nvim/module/config/Highlight.nix @@ -1,27 +1,44 @@ -{ config, lib, ... }: let - color = config.style.color; +{ 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})''; + 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"; }; -in { - text = '' - vim.api.nvim_create_autocmd({"ColorScheme", "VimEnter"}, { - group = vim.api.nvim_create_augroup('Color', {}), - pattern = "*", - callback = function () - -- Backgrounds. - ${mkHighlight "CursorLine" bg} - ${mkHighlight "TelescopeSelection" bg} + bg = { + bg = "#${color.bg.regular}"; + }; + selection = { + bg = "#${color.selection}"; + fg = "#${color.fg.dark}"; + bold = true; + }; + transparent = { + bg = lib.generators.mkLuaInline "clear"; + }; +in +{ + text = '' + vim.api.nvim_create_autocmd({"ColorScheme", "VimEnter"}, { + group = vim.api.nvim_create_augroup('Color', {}), + pattern = "*", + callback = function () + -- Backgrounds. + ${mkHighlight "CursorLine" bg} + ${mkHighlight "TelescopeSelection" bg} - -- Selection. - ${mkHighlight "Visual" selection} + -- Selection. + ${mkHighlight "Visual" selection} - -- Transparent. - ${mkHighlight "NormalFloat" transparent} - end - }) - ''; + -- Transparent. + ${mkHighlight "NormalFloat" transparent} + end + }) + ''; } diff --git a/home/config/nvim/module/config/Search.nix b/home/config/nvim/module/config/Search.nix index 5731e34..21842a3 100644 --- a/home/config/nvim/module/config/Search.nix +++ b/home/config/nvim/module/config/Search.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 1dfaffb..4db277c 100644 --- a/home/config/nvim/module/config/Tab.nix +++ b/home/config/nvim/module/config/Tab.nix @@ -1,15 +1,17 @@ -{ ... }: 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 2ca8502..9765db1 100644 --- a/home/config/nvim/module/key/Autocomplete.nix +++ b/home/config/nvim/module/key/Autocomplete.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 7c29a87..4e468a8 100644 --- a/home/config/nvim/module/key/Buffer.nix +++ b/home/config/nvim/module/key/Buffer.nix @@ -1,16 +1,17 @@ -{ ... }: { - 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 01138e0..acc11f0 100644 --- a/home/config/nvim/module/key/Cmd.nix +++ b/home/config/nvim/module/key/Cmd.nix @@ -1,11 +1,12 @@ -{ ... }: { - 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 3f92dda..98e76bb 100644 --- a/home/config/nvim/module/key/Colorscheme.nix +++ b/home/config/nvim/module/key/Colorscheme.nix @@ -1,26 +1,27 @@ -{ ... }: { - 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 d13ffa7..0c5c4a6 100644 --- a/home/config/nvim/module/key/Comment.nix +++ b/home/config/nvim/module/key/Comment.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 a9847d8..f0cb68a 100644 --- a/home/config/nvim/module/key/Filetree.nix +++ b/home/config/nvim/module/key/Filetree.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 d6192e3..bbd4190 100644 --- a/home/config/nvim/module/key/Gitsigns.nix +++ b/home/config/nvim/module/key/Gitsigns.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 625e37c..50b832f 100644 --- a/home/config/nvim/module/key/Leader.nix +++ b/home/config/nvim/module/key/Leader.nix @@ -1,11 +1,12 @@ -{ ... }: { - 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 a2d381d..f8ffc90 100644 --- a/home/config/nvim/module/key/Navigation.nix +++ b/home/config/nvim/module/key/Navigation.nix @@ -1,36 +1,38 @@ -{ ... }: 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 + stepVertical = 2; + stepHorizontal = 4; +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/Ollama.nix b/home/config/nvim/module/key/Ollama.nix index 692abeb..13c9b34 100644 --- a/home/config/nvim/module/key/Ollama.nix +++ b/home/config/nvim/module/key/Ollama.nix @@ -1,6 +1,7 @@ -{ ... }: { - text = '' - rekey_normal("p", ":lua require('ollama').prompt()") - rekey_visual("p", ":lua require('ollama').prompt()") - ''; +{ ... }: +{ + text = '' + rekey_normal("p", ":lua require('ollama').prompt()") + rekey_visual("p", ":lua require('ollama').prompt()") + ''; } diff --git a/home/config/nvim/module/key/Rekey.nix b/home/config/nvim/module/key/Rekey.nix index 00e052a..a12a2fe 100644 --- a/home/config/nvim/module/key/Rekey.nix +++ b/home/config/nvim/module/key/Rekey.nix @@ -1,53 +1,54 @@ -{ ... }: { - 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 c7d3cba..be1b72d 100644 --- a/home/config/nvim/module/key/Save.nix +++ b/home/config/nvim/module/key/Save.nix @@ -1,19 +1,20 @@ -{ ... }: { - 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 d73396d..59e496a 100644 --- a/home/config/nvim/module/key/Sort.nix +++ b/home/config/nvim/module/key/Sort.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 741760a..6037dcb 100644 --- a/home/config/nvim/module/key/TabWidth.nix +++ b/home/config/nvim/module/key/TabWidth.nix @@ -1,21 +1,22 @@ -{ ... }: { - 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 8c51331..17f5c84 100644 --- a/home/config/nvim/module/key/Telescope.nix +++ b/home/config/nvim/module/key/Telescope.nix @@ -1,12 +1,14 @@ -{ ... }: 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 319fdd0..f41ba73 100644 --- a/home/config/nvim/module/key/Terminal.nix +++ b/home/config/nvim/module/key/Terminal.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 5b1bd2d..06eb18c 100644 --- a/home/config/nvim/module/key/Trouble.nix +++ b/home/config/nvim/module/key/Trouble.nix @@ -1,11 +1,13 @@ -{ ... }: 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 76bc586..c23fd6c 100644 --- a/home/config/nvim/module/plugin/Align.nix +++ b/home/config/nvim/module/plugin/Align.nix @@ -1,10 +1,11 @@ -{ ... }: { - 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 d50e9f4..c2c6487 100644 --- a/home/config/nvim/module/plugin/Autoclose.nix +++ b/home/config/nvim/module/plugin/Autoclose.nix @@ -1,17 +1,18 @@ -{ ... }: { - 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 13bb09a..0339f53 100644 --- a/home/config/nvim/module/plugin/Bufferline.nix +++ b/home/config/nvim/module/plugin/Bufferline.nix @@ -1,5 +1,6 @@ -{ ... }: { - 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 3aa1f0a..6736b05 100644 --- a/home/config/nvim/module/plugin/Closebuffers.nix +++ b/home/config/nvim/module/plugin/Closebuffers.nix @@ -1,11 +1,12 @@ -{ ... }: { - 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 1554f84..33c47e8 100644 --- a/home/config/nvim/module/plugin/Colorizer.nix +++ b/home/config/nvim/module/plugin/Colorizer.nix @@ -1,8 +1,9 @@ -{ ... }: { - 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/Filetree.nix b/home/config/nvim/module/plugin/Filetree.nix index 7acbc96..20c99b9 100644 --- a/home/config/nvim/module/plugin/Filetree.nix +++ b/home/config/nvim/module/plugin/Filetree.nix @@ -1,40 +1,41 @@ -{ ... }: { - 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 b67202c..e10ae3c 100644 --- a/home/config/nvim/module/plugin/Fold.nix +++ b/home/config/nvim/module/plugin/Fold.nix @@ -1,7 +1,8 @@ -{ ... }: { - 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/Gitsigns.nix b/home/config/nvim/module/plugin/Gitsigns.nix index dfa413f..ed357c7 100644 --- a/home/config/nvim/module/plugin/Gitsigns.nix +++ b/home/config/nvim/module/plugin/Gitsigns.nix @@ -1,44 +1,45 @@ -{ ... }: { - 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 84b62d7..bf315f4 100644 --- a/home/config/nvim/module/plugin/Gruvbox.nix +++ b/home/config/nvim/module/plugin/Gruvbox.nix @@ -1,19 +1,20 @@ -{ ... }: { - 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 = "hard" - 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 = "hard" + 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 58280ca..e944139 100644 --- a/home/config/nvim/module/plugin/Indent.nix +++ b/home/config/nvim/module/plugin/Indent.nix @@ -1,10 +1,11 @@ -{ ... }: { - 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 b85ed58..74d8e33 100644 --- a/home/config/nvim/module/plugin/Init.nix +++ b/home/config/nvim/module/plugin/Init.nix @@ -1,53 +1,54 @@ -{ ... }: { - 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/Ollama.nix b/home/config/nvim/module/plugin/Ollama.nix index 1932ddf..01503fe 100644 --- a/home/config/nvim/module/plugin/Ollama.nix +++ b/home/config/nvim/module/plugin/Ollama.nix @@ -1,17 +1,18 @@ -{ config, ... }: { - text = '' - require("ollama").setup { - model = "${config.setting.ollama.primaryModel}", - url = "http://127.0.0.1:11434", - -- View the actual default prompts in ./lua/ollama/prompts.lua - prompts = { - -- Sample_Prompt = { - -- prompt = "This is a sample prompt that receives $input and $sel(ection), among others.", - -- input_label = "> ", - -- model = "mistral", - -- action = "display", - -- } - } - } - ''; +{ config, ... }: +{ + text = '' + require("ollama").setup { + model = "${config.setting.ollama.primaryModel}", + url = "http://127.0.0.1:11434", + -- View the actual default prompts in ./lua/ollama/prompts.lua + prompts = { + -- Sample_Prompt = { + -- prompt = "This is a sample prompt that receives $input and $sel(ection), among others.", + -- input_label = "> ", + -- model = "mistral", + -- action = "display", + -- } + } + } + ''; } diff --git a/home/config/nvim/module/plugin/Telescope.nix b/home/config/nvim/module/plugin/Telescope.nix index f022420..3d0106a 100644 --- a/home/config/nvim/module/plugin/Telescope.nix +++ b/home/config/nvim/module/plugin/Telescope.nix @@ -1,15 +1,16 @@ -{ ... }: { - text = '' - require("telescope").setup{ - defaults = { - mappings = { - i = { - [""] = "which_key", - } - } - }, - extensions = { }, - pickers = { }, - } - ''; +{ ... }: +{ + text = '' + require("telescope").setup{ + defaults = { + mappings = { + i = { + [""] = "which_key", + } + } + }, + extensions = { }, + pickers = { }, + } + ''; } diff --git a/home/config/nvim/module/plugin/Todo.nix b/home/config/nvim/module/plugin/Todo.nix index 39a0004..a7e00fe 100644 --- a/home/config/nvim/module/plugin/Todo.nix +++ b/home/config/nvim/module/plugin/Todo.nix @@ -1,54 +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" } }, - }, - 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" } }, + }, + 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 c711d7c..4655911 100644 --- a/home/config/nvim/module/plugin/Treesitter.nix +++ b/home/config/nvim/module/plugin/Treesitter.nix @@ -1,25 +1,26 @@ -{ ... }: { - 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 73da358..f2f04fc 100644 --- a/home/config/nvim/module/plugin/Trouble.nix +++ b/home/config/nvim/module/plugin/Trouble.nix @@ -1,5 +1,6 @@ -{ ... }: { - text = '' - require("trouble").setup() - ''; +{ ... }: +{ + text = '' + require("trouble").setup() + ''; } diff --git a/home/config/nvim/module/plugin/lsp/Haskell.nix b/home/config/nvim/module/plugin/lsp/Haskell.nix index 676fbcd..fb312fc 100644 --- a/home/config/nvim/module/plugin/lsp/Haskell.nix +++ b/home/config/nvim/module/plugin/lsp/Haskell.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 5c71fbe..089145c 100644 --- a/home/config/nvim/module/plugin/lsp/Kotlin.nix +++ b/home/config/nvim/module/plugin/lsp/Kotlin.nix @@ -1,7 +1,8 @@ -{ ... }: { - 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/Nix.nix b/home/config/nvim/module/plugin/lsp/Nix.nix index de8d4ce..9a12516 100644 --- a/home/config/nvim/module/plugin/lsp/Nix.nix +++ b/home/config/nvim/module/plugin/lsp/Nix.nix @@ -1,17 +1,18 @@ -{ ... }: { - 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 7019fbc..650f444 100644 --- a/home/config/nvim/module/plugin/lsp/Python.nix +++ b/home/config/nvim/module/plugin/lsp/Python.nix @@ -1,7 +1,8 @@ -{ ... }: { - 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 f9cc4c6..141cac1 100644 --- a/home/config/nvim/module/plugin/lsp/Rust.nix +++ b/home/config/nvim/module/plugin/lsp/Rust.nix @@ -1,20 +1,21 @@ -{ ... }: { - 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 783eefd..8cef79d 100644 --- a/home/config/nvim/module/plugin/lsp/Tex.nix +++ b/home/config/nvim/module/plugin/lsp/Tex.nix @@ -1,64 +1,65 @@ -{ ... }: { - 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 4b163c8..86c74c1 100644 --- a/home/config/ssh/default.nix +++ b/home/config/ssh/default.nix @@ -1,26 +1,31 @@ # SSH client configuration. -{ util, ... }: let - mkHost = name: address: port: user: extra: util.trimTabs ('' - Host ${name} - HostName ${address} - User ${user} - Port ${toString port} - '') + extra; -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" "" - ; +{ ... }: +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" ""; } diff --git a/home/config/swappy/default.nix b/home/config/swappy/default.nix index 327c375..80652e7 100644 --- a/home/config/swappy/default.nix +++ b/home/config/swappy/default.nix @@ -1,13 +1,14 @@ -{ pkgs, config, ... }: { - config = (pkgs.formats.ini {}).generate "SwappyConfig" { - Default = { - 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 = { + 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; + }; + }; } diff --git a/home/config/sway/default.nix b/home/config/sway/default.nix index 5476ee2..d60d2f1 100644 --- a/home/config/sway/default.nix +++ b/home/config/sway/default.nix @@ -1,32 +1,36 @@ -{ pkgs, 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 = (util.trimTabs '' - # Read `man 5 sway` for a complete reference. - include /etc/sway/config.d/* - '') + swayRc + config.module.desktop.sway.extraConfig or ""; +{ 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 ""; } - diff --git a/home/config/sway/module/Display.nix b/home/config/sway/module/Display.nix index 405067b..94f33b7 100644 --- a/home/config/sway/module/Display.nix +++ b/home/config/sway/module/Display.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 dbd1bff..fae64f0 100644 --- a/home/config/sway/module/Font.nix +++ b/home/config/sway/module/Font.nix @@ -1,8 +1,10 @@ -{ config, ... }: let - fontName = config.style.font.sansSerif.name; - # fontSize = toString config.style.font.size.desktop; -in { - text = '' - font "${fontName} Medium 0.01" - ''; +{ config, ... }: +let + fontName = config.style.font.sansSerif.name; +in +# fontSize = toString config.style.font.size.desktop; +{ + text = '' + font "${fontName} Medium 0.01" + ''; } diff --git a/home/config/sway/module/Input.nix b/home/config/sway/module/Input.nix index 0bb991c..85ba0bf 100644 --- a/home/config/sway/module/Input.nix +++ b/home/config/sway/module/Input.nix @@ -1,46 +1,47 @@ -{ 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.setting.keyboard.layouts} + xkb_options ${config.setting.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 6975b56..7429d2e 100644 --- a/home/config/sway/module/Keyd.nix +++ b/home/config/sway/module/Keyd.nix @@ -1,5 +1,6 @@ -{ ... }: { - 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 43807a5..6a3f0de 100644 --- a/home/config/sway/module/Launcher.nix +++ b/home/config/sway/module/Launcher.nix @@ -1,18 +1,20 @@ -{ config, ... }: let - fontName = config.style.font.serif.name; - fontSize = toString config.style.font.size.desktop; +{ config, ... }: +let + fontName = config.style.font.serif.name; + fontSize = toString config.style.font.size.desktop; - accent = config.style.color.accent; - bg = config.style.color.bg.dark; - fg = config.style.color.fg.light; -in { - 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 _dmenu_path_wrapped | wmenu -b -p 'Run:' -i -f "${fontName} ${fontSize}" -M ${bg}D9 -S ${bg}D9 -N ${bg}D9 -m ${accent} -s ${accent} -n ${fg} | xargs swaymsg exec -- - set $menu fuzzel + accent = config.style.color.accent; + bg = config.style.color.bg.dark; + fg = config.style.color.fg.light; +in +{ + 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 _dmenu_path_wrapped | wmenu -b -p 'Run:' -i -f "${fontName} ${fontSize}" -M ${bg}D9 -S ${bg}D9 -N ${bg}D9 -m ${accent} -s ${accent} -n ${fg} | xargs swaymsg exec -- + 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 82e040f..0022441 100644 --- a/home/config/sway/module/Mod.nix +++ b/home/config/sway/module/Mod.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 b846df2..cb5c66f 100644 --- a/home/config/sway/module/Mouse.nix +++ b/home/config/sway/module/Mouse.nix @@ -1,7 +1,8 @@ -{ ... }: { - 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 8eeb99e..361eb27 100644 --- a/home/config/sway/module/Navigation.nix +++ b/home/config/sway/module/Navigation.nix @@ -1,18 +1,19 @@ -{ ... }: { - 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 28e21b1..928e8fd 100644 --- a/home/config/sway/module/Notification.nix +++ b/home/config/sway/module/Notification.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 1758cc0..e826fd4 100644 --- a/home/config/sway/module/Resize.nix +++ b/home/config/sway/module/Resize.nix @@ -1,11 +1,13 @@ -{ ... }: 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 + 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 + ''; } diff --git a/home/config/sway/module/ScratchPad.nix b/home/config/sway/module/ScratchPad.nix index b19fd9e..2997483 100644 --- a/home/config/sway/module/ScratchPad.nix +++ b/home/config/sway/module/ScratchPad.nix @@ -1,48 +1,49 @@ -{ ... }: { - 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 + } + ''; } diff --git a/home/config/sway/module/Screenshot.nix b/home/config/sway/module/Screenshot.nix index e7af8fc..8509dfa 100644 --- a/home/config/sway/module/Screenshot.nix +++ b/home/config/sway/module/Screenshot.nix @@ -1,144 +1,153 @@ -{ 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, + 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''; - 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: '' + # 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: '' + scrLatest="''${scrPath}/Latest.${ext}" + rm "''${scrLatest}" + ln -s "''${scrLatestRef}" "''${scrLatest}" + ''; - getSelection = '' - scrSelection=$(${selection}) - [[ -n "''${scrSelection}" ]] || exit - ''; + getSelection = '' + scrSelection=$(${selection}) + [[ -n "''${scrSelection}" ]] || exit + ''; - getTransform = '' - scrTransform="$(swaymsg -t get_outputs | jq -r '.[] | select(.focused) | .transform')" - [[ "''${scrTransform}" = "normal" ]] && scrTransform="" - ''; + getTransform = '' + 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 = '' + 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 = '' + 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 = '' + 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" '' + ${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" '' + ${vidStop} || { + ${getTransform} + ${vidPrepFile} + ${updateWaybar} + ${vidStart} ${vidFull} + ${vidMuxAudio} + ${vidTransform} + ${vidRefLatestFile} + ${updateWaybar} + }; + ''; - FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" '' - ${picPrepFile} + FullscreenScreenshot = pkgs.writeShellScriptBin "FullscreenScreenshot" '' + ${picPrepFile} - ${screenshot} ${picFull} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile} - ''; + ${screenshot} ${picFull} | ${picToFile} | ${picToBuffer} && ${picRefLatestFile} + ''; - SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" '' - ${getSelection} - ${picPrepFile} + SelectScreenshot = pkgs.writeShellScriptBin "SelectScreenshot" '' + ${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 46a5009..170c640 100644 --- a/home/config/sway/module/Session.nix +++ b/home/config/sway/module/Session.nix @@ -1,8 +1,10 @@ -{ 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.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' + ''; } diff --git a/home/config/sway/module/Sound.nix b/home/config/sway/module/Sound.nix index 5fb90b4..eb6e9a9 100644 --- a/home/config/sway/module/Sound.nix +++ b/home/config/sway/module/Sound.nix @@ -1,20 +1,22 @@ -{ ... }: 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_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' - 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 11404ba..d77e05b 100644 --- a/home/config/sway/module/Style.nix +++ b/home/config/sway/module/Style.nix @@ -1,16 +1,18 @@ -{ 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 + 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}" + ''; } diff --git a/home/config/sway/module/System.nix b/home/config/sway/module/System.nix index 44c77d1..cffd5cc 100644 --- a/home/config/sway/module/System.nix +++ b/home/config/sway/module/System.nix @@ -1,23 +1,25 @@ -{ ... }: 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 + 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' - 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 57214ed..c7cd357 100644 --- a/home/config/sway/module/Terminal.nix +++ b/home/config/sway/module/Terminal.nix @@ -1,7 +1,8 @@ -{ ... }: { - 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 5aabfdb..d8699d9 100644 --- a/home/config/sway/module/Tiling.nix +++ b/home/config/sway/module/Tiling.nix @@ -1,35 +1,36 @@ -{ 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.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 c019d41..792f113 100644 --- a/home/config/sway/module/TitleBar.nix +++ b/home/config/sway/module/TitleBar.nix @@ -1,11 +1,13 @@ -{ 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.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 d846516..dfacb5a 100644 --- a/home/config/sway/module/Waybar.nix +++ b/home/config/sway/module/Waybar.nix @@ -1,8 +1,9 @@ -{ ... }: { - 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 7e9930a..da9e393 100644 --- a/home/config/sway/module/Workspace.nix +++ b/home/config/sway/module/Workspace.nix @@ -1,37 +1,38 @@ -{ ... }: { - 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 ac9c859..08e62ec 100644 --- a/home/config/template/Android.nix +++ b/home/config/template/Android.nix @@ -1,60 +1,66 @@ { - 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 + 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; [ ]; - 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}"; - }; - }; - }; + 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}"; + }; + }; + }; } diff --git a/home/config/template/DevShell.nix b/home/config/template/DevShell.nix index 19d7e7a..65a4884 100644 --- a/home/config/template/DevShell.nix +++ b/home/config/template/DevShell.nix @@ -1,23 +1,26 @@ { - 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 + system = "x86_64-linux"; + lib = nixpkgs.lib; + pkgs = nixpkgs.legacyPackages.${system}; + 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 92f3809..07a079e 100644 --- a/home/config/template/FHSEnv.nix +++ b/home/config/template/FHSEnv.nix @@ -1,20 +1,25 @@ { - 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 + 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; + }; + }; } diff --git a/home/config/template/Latex.nix b/home/config/template/Latex.nix index 51ad2ec..9702feb 100644 --- a/home/config/template/Latex.nix +++ b/home/config/template/Latex.nix @@ -1,54 +1,61 @@ { - 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 + 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 + ; - #(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 4374b7a..8122364 100644 --- a/home/config/template/Rust.nix +++ b/home/config/template/Rust.nix @@ -1,38 +1,41 @@ { - 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 + 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}"; - }; - }; + 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}"; + }; + }; } diff --git a/home/config/tmux/default.nix b/home/config/tmux/default.nix index c0d1f9d..7f756ad 100644 --- a/home/config/tmux/default.nix +++ b/home/config/tmux/default.nix @@ -1,3 +1,4 @@ -{ 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 20f30e2..4b7d83f 100644 --- a/home/config/tmux/module/Config.nix +++ b/home/config/tmux/module/Config.nix @@ -1,6 +1,7 @@ -{ ... }: { - text = '' - unbind-key C-b - bind -n M-r source-file ~/.config/tmux/tmux.conf - ''; +{ ... }: +{ + text = '' + unbind-key C-b + 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 cd135b2..1d8b041 100644 --- a/home/config/tmux/module/Copy.nix +++ b/home/config/tmux/module/Copy.nix @@ -1,14 +1,16 @@ -{ 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.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" - 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 4e7ea75..513710e 100644 --- a/home/config/tmux/module/Env.nix +++ b/home/config/tmux/module/Env.nix @@ -1,10 +1,11 @@ -{ ... }: { - 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 7c7f362..cf8a145 100644 --- a/home/config/tmux/module/Scroll.nix +++ b/home/config/tmux/module/Scroll.nix @@ -1,6 +1,7 @@ -{ ... }: { - 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 248c468..4cf290b 100644 --- a/home/config/tmux/module/Session.nix +++ b/home/config/tmux/module/Session.nix @@ -1,12 +1,13 @@ -{ ... }: { - 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 e08b13b..40abf81 100644 --- a/home/config/tmux/module/Split.nix +++ b/home/config/tmux/module/Split.nix @@ -1,37 +1,39 @@ -{ config, ... }: let - accent = config.style.color.accent; - bg = config.style.color.bg.regular; - # fg = style.color.fg.light; +{ 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-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 % + 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-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-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 + 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 - bind -n M-c kill-pane - bind -n M-C kill-pane -a + 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}" - ''; + 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 fa6daea..7f8e709 100644 --- a/home/config/tmux/module/Status.nix +++ b/home/config/tmux/module/Status.nix @@ -1,27 +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.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}" - 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 f8721c8..5adfeb2 100644 --- a/home/config/tmux/module/Window.nix +++ b/home/config/tmux/module/Window.nix @@ -1,15 +1,16 @@ -{ ... }: { - 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 502fcee..7b21ab7 100644 --- a/home/config/waybar/config/default.nix +++ b/home/config/waybar/config/default.nix @@ -1,163 +1,184 @@ -{ 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-right = "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 gaming"; - return-type = "json"; - signal = 4; - }; - }; +{ 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-right = "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 gaming"; + return-type = "json"; + signal = 4; + }; + }; } diff --git a/home/config/waybar/default.nix b/home/config/waybar/default.nix index 5db28fb..d314fbe 100644 --- a/home/config/waybar/default.nix +++ b/home/config/waybar/default.nix @@ -1,4 +1,5 @@ -{ 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 881d636..56480e9 100644 --- a/home/config/waybar/style/Common.nix +++ b/home/config/waybar/style/Common.nix @@ -1,9 +1,10 @@ -{ 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.style.font.serif.name}", "Terminess Nerd Font Propo"; + font-size: ${toString config.style.font.size.desktop}px; + color: #${config.style.color.fg.light}; + } + ''; } diff --git a/home/config/waybar/style/Plugin.nix b/home/config/waybar/style/Plugin.nix index dbb3ab8..ecef8d2 100644 --- a/home/config/waybar/style/Plugin.nix +++ b/home/config/waybar/style/Plugin.nix @@ -1,77 +1,79 @@ -{ 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 + 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; + } - #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.style.window.border}px solid transparent; + border-bottom: ${toString config.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.style.color.border-r},${config.style.color.border-g},${config.style.color.border-b},${toString config.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.style.window.border}px solid #${config.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.style.window.border}px solid transparent; + border-bottom: ${toString config.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.style.window.border}px solid #${config.style.color.accent}; + } + ''; } diff --git a/home/config/waybar/style/Window.nix b/home/config/waybar/style/Window.nix index 7f577ec..a60af16 100644 --- a/home/config/waybar/style/Window.nix +++ b/home/config/waybar/style/Window.nix @@ -1,16 +1,17 @@ -{ 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.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}); + } - .modules-left > widget:first-child > #workspaces { - margin-left: ${toString config.style.window.border}px; - } + .modules-left > widget:first-child > #workspaces { + margin-left: ${toString config.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.style.window.border}px; + } + ''; } diff --git a/home/config/yazi/default.nix b/home/config/yazi/default.nix index 45bf9a4..4355133 100644 --- a/home/config/yazi/default.nix +++ b/home/config/yazi/default.nix @@ -1,6 +1,12 @@ -{ 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; +{ + 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; } diff --git a/home/config/yazi/module/Init.nix b/home/config/yazi/module/Init.nix index 196e0c0..8e745c9 100644 --- a/home/config/yazi/module/Init.nix +++ b/home/config/yazi/module/Init.nix @@ -1,10 +1,11 @@ -{ util, pkgs, ... }: { - file = pkgs.writeText "YaziInitConfig" (util.trimTabs '' - -- 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 d8b17b7..0fd9387 100644 --- a/home/config/yazi/module/Keymap.nix +++ b/home/config/yazi/module/Keymap.nix @@ -1,33 +1,34 @@ -{ pkgs, ... }: { - file = (pkgs.formats.toml {}).generate "YaziKeymapConfig" { - manager = { - prepend_keymap = [ - { - on = "d"; - run = "remove --permanently"; - desc = "Dangerous life."; - } - { - on = "D"; - run = "remove --permanently --force"; - desc = "Dangerous life."; - } - { - on = "a"; - run = "create --dir"; - desc = "Who wants files anyway?"; - } - { - on = "A"; - run = "create --force"; - desc = "I want, sometimes."; - } - { - on = ""; - run = ''shell "SHELL_NAME=yazi $SHELL" --block --confirm''; - desc = "Spawn shell here."; - } - ]; - }; - }; +{ pkgs, ... }: +{ + file = (pkgs.formats.toml { }).generate "YaziKeymapConfig" { + manager = { + prepend_keymap = [ + { + on = "d"; + run = "remove --permanently"; + desc = "Dangerous life."; + } + { + on = "D"; + run = "remove --permanently --force"; + desc = "Dangerous life."; + } + { + on = "a"; + run = "create --dir"; + desc = "Who wants files anyway?"; + } + { + on = "A"; + run = "create --force"; + desc = "I want, sometimes."; + } + { + on = ""; + run = ''shell "SHELL_NAME=yazi $SHELL" --block --confirm''; + desc = "Spawn shell here."; + } + ]; + }; + }; } diff --git a/home/config/yazi/module/Theme.nix b/home/config/yazi/module/Theme.nix index 4b4df3c..93c0855 100644 --- a/home/config/yazi/module/Theme.nix +++ b/home/config/yazi/module/Theme.nix @@ -1,83 +1,93 @@ -{ pkgs, config, ... }: let - border = { - fg = "#${config.style.color.border}"; - }; - borderLight = { - fg = "#${config.style.color.accent}"; - }; -in { - file = (pkgs.formats.toml {}).generate "YaziThemeConfig" { - manager = { - border_style = border; - border_symbol = " "; - cwd = { - fg = "#${config.style.color.fg.light}"; - # bg = "#${style.color.bg.regular}"; - }; - hovered = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.bg.regular}"; - }; - preview_hovered = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.bg.regular}"; - }; - tab_active = { - bg = "#${config.style.color.accent}"; - }; - }; - select = { border = borderLight; }; - input = { border = borderLight; }; - completion = { border = borderLight; }; - tasks = { border = borderLight; }; +{ pkgs, config, ... }: +let + border = { + fg = "#${config.style.color.border}"; + }; + borderLight = { + fg = "#${config.style.color.accent}"; + }; +in +{ + file = (pkgs.formats.toml { }).generate "YaziThemeConfig" { + manager = { + border_style = border; + border_symbol = " "; + cwd = { + fg = "#${config.style.color.fg.light}"; + # bg = "#${style.color.bg.regular}"; + }; + hovered = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.bg.regular}"; + }; + preview_hovered = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.bg.regular}"; + }; + tab_active = { + bg = "#${config.style.color.accent}"; + }; + }; + select = { + border = borderLight; + }; + input = { + border = borderLight; + }; + completion = { + border = borderLight; + }; + tasks = { + border = borderLight; + }; - status = { - separator_open = ""; - separator_close = ""; - # 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_normal = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.bg.regular}"; - }; - mode_select = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.selection}"; - }; - mode_unset = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.neutral}"; - }; - progress_label = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.bg.regular}"; - }; - progress_normal = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.bg.regular}"; - }; - progress_error = { - fg = "#${config.style.color.fg.light}"; - bg = "#${config.style.color.negative}"; - }; - permissions_t = { - fg = "#${config.style.color.fg.light}"; - }; - permissions_r = { - fg = "#${config.style.color.fg.light}"; - }; - permissions_w = { - fg = "#${config.style.color.fg.light}"; - }; - permissions_x = { - fg = "#${config.style.color.fg.light}"; - }; - permissions_s = { - fg = "#${config.style.color.fg.light}"; - }; - }; - }; + status = { + separator_open = ""; + separator_close = ""; + # 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_normal = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.bg.regular}"; + }; + mode_select = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.selection}"; + }; + mode_unset = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.neutral}"; + }; + progress_label = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.bg.regular}"; + }; + progress_normal = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.bg.regular}"; + }; + progress_error = { + fg = "#${config.style.color.fg.light}"; + bg = "#${config.style.color.negative}"; + }; + permissions_t = { + fg = "#${config.style.color.fg.light}"; + }; + permissions_r = { + fg = "#${config.style.color.fg.light}"; + }; + permissions_w = { + fg = "#${config.style.color.fg.light}"; + }; + permissions_x = { + fg = "#${config.style.color.fg.light}"; + }; + permissions_s = { + fg = "#${config.style.color.fg.light}"; + }; + }; + }; } diff --git a/home/config/yazi/module/Yazi.nix b/home/config/yazi/module/Yazi.nix index f169e00..50e74e4 100644 --- a/home/config/yazi/module/Yazi.nix +++ b/home/config/yazi/module/Yazi.nix @@ -1,116 +1,163 @@ -{ pkgs, config, ... }: { - 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, config, ... }: +{ + 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 "unpack"; - }]; - 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"; - }]; - }; + opener = + let + openWith = app: "${app} \"$@\""; + in + { + default = [ + { + desc = "Default"; + orphan = true; + run = openWith "xdg-open"; + } + ]; + archive = [ + { + desc = "Archive"; + run = openWith "unpack"; + } + ]; + 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"; + } + ]; + }; - open = { - rules = let - defaultUse = [ "text" "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" [ "archive" ]) - (mkMime "application/x-tar" [ "archive" ]) - (mkMime "application/x-xz" [ "archive" ]) - (mkMime "application/zip" [ "archive" ]) - (mkMime "application/x-7z-compressed" [ "archive" ]) - (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" + "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" [ "archive" ]) + (mkMime "application/x-tar" [ "archive" ]) + (mkMime "application/x-xz" [ "archive" ]) + (mkMime "application/zip" [ "archive" ]) + (mkMime "application/x-7z-compressed" [ "archive" ]) + (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 "*" [ ]) + ]; + }; + }; } diff --git a/home/program/bash/default.nix b/home/program/bash/default.nix index 40467e1..9bc695c 100644 --- a/home/program/bash/default.nix +++ b/home/program/bash/default.nix @@ -1,38 +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 + util.trimTabs '' - # 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 = util.trimTabs '' - # # 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 = util.trimTabs '' - # # 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/Android.nix b/home/program/bash/module/Android.nix index f7a6f13..5ac5e21 100644 --- a/home/program/bash/module/Android.nix +++ b/home/program/bash/module/Android.nix @@ -1,20 +1,21 @@ -{ ... }: { - text = '' - # Start an Android emulator. - # Default name is `main`. - # Usage: emulator [NAME] - function emulator() { - local name="$1" +{ ... }: +{ + text = '' + # Start an Android emulator. + # Default name is `main`. + # Usage: emulator [NAME] + function emulator() { + local name="$1" - [[ "$name" = "" ]] && name="main" + [[ "$name" = "" ]] && name="main" - steam-run ~/.android/sdk/emulator/emulator -avd "$name" &> /dev/null & disown - } + steam-run ~/.android/sdk/emulator/emulator -avd "$name" &> /dev/null & disown + } - function _android_emulators() { - _autocomplete_first $(ls --classify ~/.android/avd/ | grep \/$ | sed -e "s/.avd\/$//") - } + function _android_emulators() { + _autocomplete_first $(ls --classify ~/.android/avd/ | grep \/$ | sed -e "s/.avd\/$//") + } - complete -F _android_emulators emulator - ''; + complete -F _android_emulators emulator + ''; } diff --git a/home/program/bash/module/Archive.nix b/home/program/bash/module/Archive.nix index 65e3a4c..1916809 100644 --- a/home/program/bash/module/Archive.nix +++ b/home/program/bash/module/Archive.nix @@ -1,421 +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 out=$(echo "''${*}" | 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 out=$(echo "''${*}" | 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 5e8136c..d1a9fe7 100644 --- a/home/program/bash/module/Ask.nix +++ b/home/program/bash/module/Ask.nix @@ -1,26 +1,27 @@ -{ ... }: { - text = '' - # Ask general AI. - # Usage: ask - function ask() { - curl http://localhost:11434/api/generate -d "{ - \"model\": \"''${OLLAMA_MODEL}\", - \"prompt\":\"''${*}\" - }" 2> /dev/null | parallel -j1 -- "echo {} | jq -r .response | tr -d '\n'" - echo - } +{ ... }: +{ + text = '' + # Ask general AI. + # Usage: ask + function ask() { + curl http://localhost:11434/api/generate -d "{ + \"model\": \"''${OLLAMA_MODEL}\", + \"prompt\":\"''${*}\" + }" 2> /dev/null | parallel -j1 -- "echo {} | jq -r .response | tr -d '\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 ecf1b12..ed62b82 100644 --- a/home/program/bash/module/Autocomplete.nix +++ b/home/program/bash/module/Autocomplete.nix @@ -1,87 +1,88 @@ -{ ... }: { - 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 4013582..3ca1c89 100644 --- a/home/program/bash/module/Battery.nix +++ b/home/program/bash/module/Battery.nix @@ -1,16 +1,17 @@ -{ ... }: { - 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 e681f27..eb45300 100644 --- a/home/program/bash/module/Brightness.nix +++ b/home/program/bash/module/Brightness.nix @@ -1,22 +1,23 @@ -{ ... }: { - 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/Calc.nix b/home/program/bash/module/Calc.nix index f5286a1..d1e230b 100644 --- a/home/program/bash/module/Calc.nix +++ b/home/program/bash/module/Calc.nix @@ -1,8 +1,9 @@ -{ ... }: { - text = '' - # Launch calculator app. - function calc() { - gnome-calculator - } - ''; +{ ... }: +{ + text = '' + # Launch calculator app. + function calc() { + gnome-calculator + } + ''; } diff --git a/home/program/bash/module/Cd.nix b/home/program/bash/module/Cd.nix index e390d8b..e4ef4a5 100644 --- a/home/program/bash/module/Cd.nix +++ b/home/program/bash/module/Cd.nix @@ -1,73 +1,74 @@ -{ ... }: { - 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/Checksum.nix b/home/program/bash/module/Checksum.nix index 9b31962..2e1dcc7 100644 --- a/home/program/bash/module/Checksum.nix +++ b/home/program/bash/module/Checksum.nix @@ -1,87 +1,88 @@ -{ ... }: { - text = '' - # Save file checksums. - # For file with a name `file` it will create a new file called `.file.sha1` with hash in it. - # All files by default. - # Usage: checksum_create [FILES] - function checksum_create() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) +{ ... }: +{ + text = '' + # Save file checksums. + # For file with a name `file` it will create a new file called `.file.sha1` with hash in it. + # All files by default. + # Usage: checksum_create [FILES] + function checksum_create() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - process() { - local hashfile=".''${target#./}.sha1" + process() { + local hashfile=".''${target#./}.sha1" - # Skip if hash exists. - [[ -f "''${hashfile}" ]] && return 0 + # Skip if hash exists. + [[ -f "''${hashfile}" ]] && return 0 - # Calculate hash. - pv ''${target} | sha1sum > ''${hashfile} - } + # Calculate hash. + pv ''${target} | sha1sum > ''${hashfile} + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Check stored values against actual files. - # All files by default. - # Usage: checksum_check [FILES] - function checksum_check() { - local IFS=$'\n' - local targets=(''${@}) - [[ "''${targets}" = "" ]] && targets=($(_ls_file)) + # Check stored values against actual files. + # All files by default. + # Usage: checksum_check [FILES] + function checksum_check() { + local IFS=$'\n' + local targets=(''${@}) + [[ "''${targets}" = "" ]] && targets=($(_ls_file)) - process() { - local hashfile=".''${target#./}.sha1" + process() { + local hashfile=".''${target#./}.sha1" - # Skip if hash doesn't exist. - [[ -f "''${hashfile}" ]] || { _iterate_skip "No hash found."; return 0; } + # Skip if hash doesn't exist. + [[ -f "''${hashfile}" ]] || { _iterate_skip "No hash found."; return 0; } - # Calculate hash. - local stored=$(cat "''${hashfile}" | cut -d\ -f1) - local actual=$(pv "''${target}" | sha1sum | cut -d\ -f1) + # Calculate hash. + local stored=$(cat "''${hashfile}" | cut -d\ -f1) + local actual=$(pv "''${target}" | sha1sum | cut -d\ -f1) - if [[ "''${stored}" != "''${actual}" ]]; then - _error "Failed." - return 1 - fi - } + if [[ "''${stored}" != "''${actual}" ]]; then + _error "Failed." + return 1 + fi + } - _iterate_targets process ''${targets[@]} - } + _iterate_targets process ''${targets[@]} + } - # Calculate hashes for all files recursively and store in a file called `checksum.sha1`. - function checksum() { - find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 - } + # Calculate hashes for all files recursively and store in a file called `checksum.sha1`. + function checksum() { + find -type f | parallel -j $(_core_count) -- sha1sum {} >> checksum.sha1 + } - # Create checksum for a file. - # Usage: _checksum_create - function _checksum_create() { - local path="''${1%/*}" - local name="''${1##*/}" - sha1sum "''${path}/''${name}" > "''${path}/.''${name}.sha1" - } + # Create checksum for a file. + # Usage: _checksum_create + function _checksum_create() { + local path="''${1%/*}" + local name="''${1##*/}" + sha1sum "''${path}/''${name}" > "''${path}/.''${name}.sha1" + } - # Check checksum for a file. - # Usage: _checksum_check - function _checksum_check() { - local file="''${1##*\ \ }" - local stored="''${1%%\ \ *}" + # Check checksum for a file. + # Usage: _checksum_check + function _checksum_check() { + local file="''${1##*\ \ }" + local stored="''${1%%\ \ *}" - # Skip if no file. - [[ -f "''${file}" ]] || return 0 + # Skip if no file. + [[ -f "''${file}" ]] || return 0 - # Check file hash. - local actual=$(sha1sum "''${file}") - actual="''${actual%%\ \ *}" + # Check file hash. + local actual=$(sha1sum "''${file}") + actual="''${actual%%\ \ *}" - # Compare values. - if [[ "''${stored}" != "''${actual}" ]]; then - _error "''${file}: Failed." - return 1 - fi + # Compare values. + if [[ "''${stored}" != "''${actual}" ]]; then + _error "''${file}: Failed." + return 1 + fi - return 0 - } - ''; + return 0 + } + ''; } diff --git a/home/program/bash/module/Chmod.nix b/home/program/bash/module/Chmod.nix index 9d4153c..6971f83 100644 --- a/home/program/bash/module/Chmod.nix +++ b/home/program/bash/module/Chmod.nix @@ -1,9 +1,10 @@ -{ ... }: { - text = '' - # Add executable flag to file. - # Usage: x - function x() { - chmod +x -- "''${@}" - } - ''; +{ ... }: +{ + text = '' + # Add executable flag to file. + # Usage: x + function x() { + chmod +x -- "''${@}" + } + ''; } diff --git a/home/program/bash/module/Color.nix b/home/program/bash/module/Color.nix index 48b4c2c..a2afdc2 100644 --- a/home/program/bash/module/Color.nix +++ b/home/program/bash/module/Color.nix @@ -1,28 +1,29 @@ -{ ... }: { - 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/Container.nix b/home/program/bash/module/Container.nix index 641998d..ed271b5 100644 --- a/home/program/bash/module/Container.nix +++ b/home/program/bash/module/Container.nix @@ -1,84 +1,85 @@ -{ ... }: { - text = '' - # Attach/create container box in current directory with specified name. - # By default uses current dir name. - # Usage: ca [NAME] - function ca() { - local name="''${1}" +{ ... }: +{ + text = '' + # Attach/create container box in current directory with specified name. + # By default uses current dir name. + # Usage: ca [NAME] + function ca() { + 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##*/}") - # Append box prefix. - name="box-''${name}" + # Append box prefix. + name="box-''${name}" - # Create container. - docker run \ - --privileged \ - -d -it \ - -h "''${HOSTNAME}''${name#box}" --name "''${name}" \ - --workdir /data \ - -e XDG_RUNTIME_DIR=/tmp \ - -e WAYLAND_DISPLAY=''${WAYLAND_DISPLAY} \ - -v ''${XDG_RUNTIME_DIR}/''${WAYLAND_DISPLAY}:/tmp/''${WAYLAND_DISPLAY} \ - -v ''${PWD}:/data \ - -v ''${HOME}:/root \ - debian:latest bash -c bash &> /dev/null + # Create container. + docker run \ + --privileged \ + -d -it \ + -h "''${HOSTNAME}''${name#box}" --name "''${name}" \ + --workdir /data \ + -e XDG_RUNTIME_DIR=/tmp \ + -e WAYLAND_DISPLAY=''${WAYLAND_DISPLAY} \ + -v ''${XDG_RUNTIME_DIR}/''${WAYLAND_DISPLAY}:/tmp/''${WAYLAND_DISPLAY} \ + -v ''${PWD}:/data \ + -v ''${HOME}:/root \ + debian:latest bash -c bash &> /dev/null - # Attempt to start container. - docker start "''${name}" &> /dev/null + # Attempt to start container. + docker start "''${name}" &> /dev/null - # Attach to running container. - docker attach "''${name}" - } + # Attach to running container. + docker attach "''${name}" + } - # Remove container box with specified name. - # By default uses current dir name. - # Usage: ck [NAME] - function ck() { - local name="''${1}" + # Remove container box with specified name. + # By default uses current dir name. + # Usage: ck [NAME] + function ck() { + local name="''${1}" - # Set default name. - [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") + # Set default name. + [[ "''${name}" = "" ]] && name=$(parse_alnum "''${PWD##*/}") - # Append box prefix. - name="box-''${name}" + # Append box prefix. + name="box-''${name}" - # Kill container. - docker kill "''${name}" &> /dev/null - docker rm "''${name}" &> /dev/null - } + # Kill container. + docker kill "''${name}" &> /dev/null + docker rm "''${name}" &> /dev/null + } - # Remove all container boxes. - function cka() { - local IFS=$'\n' - local boxes=$(_get_boxes) + # Remove all container boxes. + function cka() { + local IFS=$'\n' + local boxes=$(_get_boxes) - for box in ''${boxes[@]}; do - ck "''${box}" - done - } + for box in ''${boxes[@]}; do + ck "''${box}" + done + } - # List all container boxes. - function cl() { - _get_boxes - } + # List all container boxes. + function cl() { + _get_boxes + } - # Print all boxes. - function _get_boxes() { - local IFS=$'\n' - local boxes=$(docker ps -a | grep "box-" | sed -e "s/.*box-//") + # Print all boxes. + function _get_boxes() { + local IFS=$'\n' + local boxes=$(docker ps -a | grep "box-" | sed -e "s/.*box-//") - [[ "''${boxes[@]}" != "" ]] && echo "''${boxes[@]}" || true - } + [[ "''${boxes[@]}" != "" ]] && echo "''${boxes[@]}" || true + } - # Autocomplete with boxes. - function _comp_get_boxes() { - local IFS=$'\n' - _autocomplete_first $(_get_boxes) - } + # Autocomplete with boxes. + function _comp_get_boxes() { + local IFS=$'\n' + _autocomplete_first $(_get_boxes) + } - complete -F _comp_get_boxes ca ck - ''; + complete -F _comp_get_boxes ca ck + ''; } diff --git a/home/program/bash/module/Copypaste.nix b/home/program/bash/module/Copypaste.nix index 62400e6..051ef38 100644 --- a/home/program/bash/module/Copypaste.nix +++ b/home/program/bash/module/Copypaste.nix @@ -1,13 +1,14 @@ -{ ... }: { - 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 f047895..6b648f4 100644 --- a/home/program/bash/module/Cp.nix +++ b/home/program/bash/module/Cp.nix @@ -1,54 +1,55 @@ -{ ... }: { - 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 9780297..4b5406a 100644 --- a/home/program/bash/module/Curl.nix +++ b/home/program/bash/module/Curl.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 5fb42f5..8fdd681 100644 --- a/home/program/bash/module/Date.nix +++ b/home/program/bash/module/Date.nix @@ -1,13 +1,14 @@ -{ ... }: { -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/Dconf.nix b/home/program/bash/module/Dconf.nix index 9975d73..f35573f 100644 --- a/home/program/bash/module/Dconf.nix +++ b/home/program/bash/module/Dconf.nix @@ -1,20 +1,21 @@ -{ ... }: { - text = '' - export _gdconf_path="''${HOME}/.config/linux/Gnome.dconf" +{ ... }: +{ + text = '' + export _gdconf_path="''${HOME}/.config/linux/Gnome.dconf" - # Load Gnome settings. - function dconf_load() { - sed -i -e s/voronind/$(whoami)/g ''${_gdconf_path} ; dconf load / < ''${_gdconf_path} - } + # Load Gnome settings. + function dconf_load() { + sed -i -e s/voronind/$(whoami)/g ''${_gdconf_path} ; dconf load / < ''${_gdconf_path} + } - # Dump Gnome settings into the file. - # Default name is `gnome.dconf`. - # Do this before changing settings and after, an then run `diff` to find out what to add to the main `gnome.dconf`. - # Usage: dconf_save [FILE] - function dconf_save() { - local name="''${1}" - [[ "''${name}" = "" ]] && name="gnome.dconf" - dconf dump / > "''${name}" - } - ''; + # Dump Gnome settings into the file. + # Default name is `gnome.dconf`. + # Do this before changing settings and after, an then run `diff` to find out what to add to the main `gnome.dconf`. + # Usage: dconf_save [FILE] + function dconf_save() { + local name="''${1}" + [[ "''${name}" = "" ]] && name="gnome.dconf" + dconf dump / > "''${name}" + } + ''; } diff --git a/home/program/bash/module/Disk.nix b/home/program/bash/module/Disk.nix index ca395fd..2a7443b 100644 --- a/home/program/bash/module/Disk.nix +++ b/home/program/bash/module/Disk.nix @@ -1,72 +1,73 @@ -{ ... }: { - 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/Distrobox.nix b/home/program/bash/module/Distrobox.nix index 0b28206..7c69006 100644 --- a/home/program/bash/module/Distrobox.nix +++ b/home/program/bash/module/Distrobox.nix @@ -1,19 +1,20 @@ -{ ... }: { - text = '' - # Create/Attach to the box. - # Uses name `main` by default. - # Usage: da [BOX] - function da() { - local name="''${1}" +{ ... }: +{ + text = '' + # Create/Attach to the box. + # Uses name `main` by default. + # Usage: da [BOX] + function da() { + local name="''${1}" - [[ "''${name}" = "" ]] && name="main" - # if [[ "''${name}" = "" ]]; then - # help da - # return 2 - # fi + [[ "''${name}" = "" ]] && name="main" + # if [[ "''${name}" = "" ]]; then + # help da + # return 2 + # fi - # --user 0 is required for rootless docker. - distrobox enter -a '--user=0' "''${name}" - } - ''; + # --user 0 is required for rootless docker. + distrobox enter -a '--user=0' "''${name}" + } + ''; } diff --git a/home/program/bash/module/Dmenu.nix b/home/program/bash/module/Dmenu.nix index 5483007..8ee2a72 100644 --- a/home/program/bash/module/Dmenu.nix +++ b/home/program/bash/module/Dmenu.nix @@ -1,15 +1,16 @@ -{ ... }: { - text = '' - # Wrapped dmenu_path to include my functions. - function _dmenu_path_wrapped() { - c=0 - while [ ''${c} -lt 1000 ]; do - echo - ((c++)) - done +{ ... }: +{ + text = '' + # Wrapped dmenu_path to include my functions. + function _dmenu_path_wrapped() { + c=0 + while [ ''${c} -lt 1000 ]; do + echo + ((c++)) + done - find_function | grep -v ^_ - dmenu_path - } - ''; + find_function | grep -v ^_ + dmenu_path + } + ''; } diff --git a/home/program/bash/module/Docker.nix b/home/program/bash/module/Docker.nix index 2febc60..0c3660e 100644 --- a/home/program/bash/module/Docker.nix +++ b/home/program/bash/module/Docker.nix @@ -1,99 +1,100 @@ -{ ... }: { - 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 3d44cda..126e449 100644 --- a/home/program/bash/module/Dvd.nix +++ b/home/program/bash/module/Dvd.nix @@ -1,43 +1,44 @@ -{ ... }: { - 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 84b6bda..5b54909 100644 --- a/home/program/bash/module/Ffmpeg.nix +++ b/home/program/bash/module/Ffmpeg.nix @@ -1,112 +1,113 @@ -{ ... }: { - 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 6955a62..b1989ff 100644 --- a/home/program/bash/module/File.nix +++ b/home/program/bash/module/File.nix @@ -1,32 +1,33 @@ -{ ... }: { - text = '' - # Open file/dir in GUI. - # Usage: o - function o() { - xdg-open "''${@}" - } +{ ... }: +{ + text = '' + # Open file/dir in GUI. + # Usage: o + function o() { + xdg-open "''${@}" + } - # Play media file from CLI. All files by default. - # Usage: play [FILE] - function play() { - local targets=''${*} - [[ "''${targets}" = "" ]] && targets=$(_ls_file) + # Play media file from CLI. All files by default. + # Usage: play [FILE] + function play() { + local targets=''${*} + [[ "''${targets}" = "" ]] && targets=$(_ls_file) - mpv --no-video ''${targets} - } + mpv --no-video ''${targets} + } - # Play media files shuffled from CLI. All files by default. - # Usage: play_shuffle [FILE] - function play_shuffle() { - local targets=''${*} - [[ "''${targets}" = "" ]] && targets=$(_ls_file) + # Play media files shuffled from CLI. All files by default. + # Usage: play_shuffle [FILE] + function play_shuffle() { + local targets=''${*} + [[ "''${targets}" = "" ]] && targets=$(_ls_file) - mpv --no-video --shuffle ''${targets} - } + mpv --no-video --shuffle ''${targets} + } - # Open files app. - function files() { - nautilus - } - ''; + # Open files app. + function files() { + nautilus + } + ''; } diff --git a/home/program/bash/module/Find.nix b/home/program/bash/module/Find.nix index ef94b59..9224ae1 100644 --- a/home/program/bash/module/Find.nix +++ b/home/program/bash/module/Find.nix @@ -1,9 +1,10 @@ -{ ... }: { - 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 5947edb..57b59fa 100644 --- a/home/program/bash/module/Fix.nix +++ b/home/program/bash/module/Fix.nix @@ -1,70 +1,71 @@ -{ ... }: { - 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}" + } - # Fix nautilus after typing wrong sftp password. - function fix_files_sftp() { - secret-tool clear protocol sftp - } + # Fix nautilus after typing wrong sftp password. + function fix_files_sftp() { + secret-tool clear protocol sftp + } - # 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 - + } - # Fix Gnome's broken RDP ffs. - # Usage: fix_gnome_rdp - function fix_gnome_rdp() { - local user="''${USERNAME}" - local password="''${1}" + # Fix Gnome's broken RDP ffs. + # Usage: fix_gnome_rdp + function fix_gnome_rdp() { + local user="''${USERNAME}" + local password="''${1}" - # Check params. - if [[ "''${password}" = "" ]]; then - help fix_gnome_rdp - return 2 - fi + # Check params. + if [[ "''${password}" = "" ]]; then + help fix_gnome_rdp + return 2 + fi - # Unlock keyring. PROTIP: Disable password for it in password manager. - pkill -9 -f gnome-keyring-daemon - echo -n "''${user}" | gnome-keyring-daemon --unlock + # Unlock keyring. PROTIP: Disable password for it in password manager. + pkill -9 -f gnome-keyring-daemon + echo -n "''${user}" | gnome-keyring-daemon --unlock - # Generate keys. - cd /tmp - openssl genrsa -out rdp-tls.key 4096 - openssl req -new -key rdp-tls.key -subj "/C=US" | openssl x509 -req -days 730 -signkey rdp-tls.key -out rdp-tls.crt - mkdir -p "''${HOME}/.local/share/gnome-remote-desktop/" - mv rdp-tls.key rdp-tls.crt "''${HOME}/.local/share/gnome-remote-desktop/" + # Generate keys. + cd /tmp + openssl genrsa -out rdp-tls.key 4096 + openssl req -new -key rdp-tls.key -subj "/C=US" | openssl x509 -req -days 730 -signkey rdp-tls.key -out rdp-tls.crt + mkdir -p "''${HOME}/.local/share/gnome-remote-desktop/" + mv rdp-tls.key rdp-tls.crt "''${HOME}/.local/share/gnome-remote-desktop/" - # Configure RDP. - grdctl rdp set-tls-cert "''${HOME}/.local/share/gnome-remote-desktop/rdp-tls.crt" - grdctl rdp set-tls-key "''${HOME}/.local/share/gnome-remote-desktop/rdp-tls.key" - grdctl rdp set-credentials "''${user}" "''${password}" - grdctl rdp disable-view-only + # Configure RDP. + grdctl rdp set-tls-cert "''${HOME}/.local/share/gnome-remote-desktop/rdp-tls.crt" + grdctl rdp set-tls-key "''${HOME}/.local/share/gnome-remote-desktop/rdp-tls.key" + grdctl rdp set-credentials "''${user}" "''${password}" + grdctl rdp disable-view-only - # Start service. - grdctl rdp enable - systemctl --user start gnome-remote-desktop.service + # Start service. + grdctl rdp enable + systemctl --user start gnome-remote-desktop.service - # Show status. - grdctl status --show-credentials - systemctl --user status gnome-remote-desktop.service + # Show status. + grdctl status --show-credentials + systemctl --user status gnome-remote-desktop.service - # Show extra info. - _warn "You may need to manually restart Desktop sharing via Gnome Settings." - } - ''; + # Show extra info. + _warn "You may need to manually restart Desktop sharing via Gnome Settings." + } + ''; } diff --git a/home/program/bash/module/Git.nix b/home/program/bash/module/Git.nix index 53c8783..512684c 100644 --- a/home/program/bash/module/Git.nix +++ b/home/program/bash/module/Git.nix @@ -1,299 +1,300 @@ -{ ... }: { - 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 --cached --binary - } + # Git patch create. + # Usage: gpc > + function gpc() { + git diff --cached --binary + } - # Git patch (apply). - # Usage: gp - function gp() { - git apply "''${@}" - } + # Git patch (apply). + # Usage: gp + function gp() { + git apply "''${@}" + } - # 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}" + } - # Sign the old commits. 0 to resign from root. - # Usage: git_sign [COMMIT_COUNT] - function git_sign() { - local base="''${1}" + # Sign the old commits. 0 to resign from root. + # Usage: git_sign [COMMIT_COUNT] + function git_sign() { + 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 b8d6d22..beb8d67 100644 --- a/home/program/bash/module/Gpg.nix +++ b/home/program/bash/module/Gpg.nix @@ -1,76 +1,77 @@ -{ ... }: { - 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[@]} + } + ''; } diff --git a/home/program/bash/module/Group.nix b/home/program/bash/module/Group.nix index a99809d..a19ae26 100644 --- a/home/program/bash/module/Group.nix +++ b/home/program/bash/module/Group.nix @@ -1,73 +1,74 @@ -{ ... }: { - 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 1949c92..27e9eaf 100644 --- a/home/program/bash/module/Help.nix +++ b/home/program/bash/module/Help.nix @@ -1,29 +1,30 @@ -{ ... }: { - 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 e4cbd06..ca001d7 100644 --- a/home/program/bash/module/Ls.nix +++ b/home/program/bash/module/Ls.nix @@ -1,70 +1,71 @@ -{ ... }: { - 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/Markdown.nix b/home/program/bash/module/Markdown.nix index b8cf8da..77498fc 100644 --- a/home/program/bash/module/Markdown.nix +++ b/home/program/bash/module/Markdown.nix @@ -1,19 +1,20 @@ -{ ... }: { - text = '' - # Render markdown in browser using Gitea API. Because I want consistency with Gitea web render. - # Works only inside LAN. - # Usage: markdown_render - function markdown_render() { - local IFS=$'\n' - local file="''${1}" - local render="markdown_render.html" +{ ... }: +{ + text = '' + # Render markdown in browser using Gitea API. Because I want consistency with Gitea web render. + # Works only inside LAN. + # Usage: markdown_render + function markdown_render() { + local IFS=$'\n' + local file="''${1}" + local render="markdown_render.html" - if [[ "''${file}" = "" ]]; then - help markdown_render - return 2 - fi + if [[ "''${file}" = "" ]]; then + help markdown_render + return 2 + fi - curl -X POST https://git.voronind.com/markdown -d "$(cat ''${file})" > "''${render}" && o "''${render}" && sleep 2 && rm "''${render}" - } - ''; + curl -X POST https://git.voronind.com/markdown -d "$(cat ''${file})" > "''${render}" && o "''${render}" && sleep 2 && rm "''${render}" + } + ''; } diff --git a/home/program/bash/module/Name.nix b/home/program/bash/module/Name.nix index 2aac288..2008cfe 100644 --- a/home/program/bash/module/Name.nix +++ b/home/program/bash/module/Name.nix @@ -1,399 +1,400 @@ -{ ... }: { - 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/Network.nix b/home/program/bash/module/Network.nix index f284713..6e3578a 100644 --- a/home/program/bash/module/Network.nix +++ b/home/program/bash/module/Network.nix @@ -1,36 +1,37 @@ -{ ... }: { - text = '' - # Open bluetooth control panel. - function bluetooth() { - blueman-manager - } +{ ... }: +{ + text = '' + # Open bluetooth control panel. + function bluetooth() { + blueman-manager + } - # Open network control panel. - function network() { - nm-connection-editor - } + # Open network control panel. + function network() { + nm-connection-editor + } - # Show active connections. - function nms() { - nmcli connection show - } + # Show active connections. + function nms() { + nmcli connection show + } - # Start the connection. - # Usage: nu - function nmu() { - nmcli connection up "''${@}" - } + # Start the connection. + # Usage: nu + function nmu() { + nmcli connection up "''${@}" + } - # Stop the connection. - # Usage: nd - function nmd() { - nmcli connection down "''${@}" - } + # Stop the connection. + # Usage: nd + function nmd() { + nmcli connection down "''${@}" + } - function _complete_connections() { - _autocomplete $(nmcli connection show | sed "1d" | cut -d\ -f1) - } + function _complete_connections() { + _autocomplete $(nmcli connection show | sed "1d" | cut -d\ -f1) + } - complete -F _complete_connections nmd nmu - ''; + complete -F _complete_connections nmd nmu + ''; } diff --git a/home/program/bash/module/Nix.nix b/home/program/bash/module/Nix.nix index 1d643d4..3bbe2af 100644 --- a/home/program/bash/module/Nix.nix +++ b/home/program/bash/module/Nix.nix @@ -1,91 +1,92 @@ -{ const, ... }: { - text = '' - export _nix_system_config="git+${const.url}" +{ const, ... }: +{ + text = '' + export _nix_system_config="git+${const.url}" - # Rebuild system. - # Optionally force the hostname. - # Usage: nixos_rebuild [HOSTNAME] - function nixos_rebuild() { - local target="''${1}" - [[ "''${target}" = "" ]] && target="''${HOSTNAME}" + # Rebuild system. + # Optionally force the hostname. + # Usage: nixos_rebuild [HOSTNAME] + function nixos_rebuild() { + local target="''${1}" + [[ "''${target}" = "" ]] && target="''${HOSTNAME}" - nixos-rebuild boot --refresh --option eval-cache false --flake "''${_nix_system_config}#''${target}" - } + nixos-rebuild boot --refresh --option eval-cache false --flake "''${_nix_system_config}#''${target}" + } - # Rebuild and switch system. - # Optionally force the hostname. - # Usage: nixos_switch [HOSTNAME] - function nixos_switch() { - local target="''${1}" - [[ "''${target}" = "" ]] && target="''${HOSTNAME}" + # Rebuild and switch system. + # Optionally force the hostname. + # Usage: nixos_switch [HOSTNAME] + function nixos_switch() { + local target="''${1}" + [[ "''${target}" = "" ]] && target="''${HOSTNAME}" - nixos-rebuild switch --refresh --option eval-cache false --flake "''${_nix_system_config}#''${target}" - } + nixos-rebuild switch --refresh --option eval-cache false --flake "''${_nix_system_config}#''${target}" + } - # 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" + # 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" - # Create Nix GC root in .NixRoot{NAME}. - nix build ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" -o ".NixRoot''${target^}" + # Create Nix GC root in .NixRoot{NAME}. + nix build ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" -o ".NixRoot''${target^}" - SHELL_NAME="''${target}" nix develop ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" - } + SHELL_NAME="''${target}" nix develop ".#devShells.''${NIX_CURRENT_SYSTEM}.''${target}" + } - # Spawn temporary nix-shell with specified packages. - # Usage: tmpshell - function tmpshell() { - local IFS=$'\n' - local input=("''${@}") - local pkgs=() - local tag="''${SHELL_NAME}" + # Spawn temporary nix-shell with specified packages. + # Usage: tmpshell + function tmpshell() { + local IFS=$'\n' + local input=("''${@}") + local pkgs=() + local tag="''${SHELL_NAME}" - if [[ "''${input}" = "" ]]; then - help tmpshell - return 2 - fi + if [[ "''${input}" = "" ]]; then + help tmpshell + return 2 + fi - [[ "''${tag}" = "" ]] && tag="''${1}" + [[ "''${tag}" = "" ]] && tag="''${1}" - 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[@]} + } - # Build live image. - function nixos_live() { - nix build "''${_nix_system_config}#nixosConfigurations.live.config.system.build.isoImage" --refresh ''${@} - } + # Build live image. + function nixos_live() { + nix build "''${_nix_system_config}#nixosConfigurations.live.config.system.build.isoImage" --refresh ''${@} + } - # List nixos generations. - function nixos_generations() { - nix-env -p /nix/var/nix/profiles/system --list-generations - } + # List nixos generations. + function nixos_generations() { + nix-env -p /nix/var/nix/profiles/system --list-generations + } - # Switch nix-on-droid. - function nixdroid_switch() { - nix-on-droid switch --flake "''${_nix_system_config}" ''${@} - } + # Switch nix-on-droid. + function nixdroid_switch() { + nix-on-droid switch --flake "''${_nix_system_config}" ''${@} + } - # Nix auto-run wrapper. - # Usage: , - function ,() { - NIX_AUTO_RUN=1 ''${@} - } + # Nix auto-run wrapper. + # Usage: , + function ,() { + NIX_AUTO_RUN=1 ''${@} + } - # Autocomplete with available hosts. - function _comp_hosts() { - local IFS=$'\n' - local targets=($(ls ~/.config/linux/system/host/)) + # Autocomplete with available hosts. + function _comp_hosts() { + local IFS=$'\n' + local targets=($(ls ~/.config/linux/system/host/)) - _autocomplete_first ''${targets[@]} - } + _autocomplete_first ''${targets[@]} + } - complete -F _comp_hosts nix_switch nix_rebuild - ''; + complete -F _comp_hosts nix_switch nix_rebuild + ''; } diff --git a/home/program/bash/module/Notify.nix b/home/program/bash/module/Notify.nix index 25cef20..a1e55c3 100644 --- a/home/program/bash/module/Notify.nix +++ b/home/program/bash/module/Notify.nix @@ -1,15 +1,16 @@ -{ ... }: { - text = '' - # Send Telegram notification. - # Usage: notify - function notify() { - curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null - } +{ ... }: +{ + text = '' + # Send Telegram notification. + # Usage: notify + function notify() { + curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null + } - # Send silent Telegram notification. - # Usage: notify_silent - function notify_silent() { - curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null - } - ''; + # Send silent Telegram notification. + # Usage: notify_silent + function notify_silent() { + curl -X POST -H 'Content-Type: Application/json' -d "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null + } + ''; } diff --git a/home/program/bash/module/Own.nix b/home/program/bash/module/Own.nix index 067d9c2..7630b9b 100644 --- a/home/program/bash/module/Own.nix +++ b/home/program/bash/module/Own.nix @@ -1,40 +1,41 @@ -{ ... }: { - 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 9fc13ba..0e12b24 100644 --- a/home/program/bash/module/Pack.nix +++ b/home/program/bash/module/Pack.nix @@ -1,202 +1,203 @@ -{ ... }: { - 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}") - # 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 dac76e0..d5ae89a 100644 --- a/home/program/bash/module/Parse.nix +++ b/home/program/bash/module/Parse.nix @@ -1,172 +1,173 @@ -{ ... }: { - 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 3b785c1..f861cc1 100644 --- a/home/program/bash/module/Permission.nix +++ b/home/program/bash/module/Permission.nix @@ -1,13 +1,14 @@ -{ ... }: { - 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/Power.nix b/home/program/bash/module/Power.nix index 54026d0..030e6bc 100644 --- a/home/program/bash/module/Power.nix +++ b/home/program/bash/module/Power.nix @@ -1,13 +1,14 @@ -{ ... }: { - text = '' - # Suspend system. - function slp() { - systemctl suspend -i - } +{ ... }: +{ + text = '' + # Suspend system. + function slp() { + systemctl suspend -i + } - # Poweroff. - function bye() { - systemctl poweroff -i - } - ''; + # Poweroff. + function bye() { + systemctl poweroff -i + } + ''; } diff --git a/home/program/bash/module/Prune.nix b/home/program/bash/module/Prune.nix index 8a5133d..08d39a8 100644 --- a/home/program/bash/module/Prune.nix +++ b/home/program/bash/module/Prune.nix @@ -1,28 +1,29 @@ -{ ... }: { - text = '' - export _flatpakcfg_path="''${HOME}/.config/linux/Flatpak.txt" +{ ... }: +{ + text = '' + export _flatpakcfg_path="''${HOME}/.config/linux/Flatpak.txt" - # Prune everything unused in docker. - function prune_docker() { - docker system prune --volumes --all - } + # Prune everything unused in docker. + function prune_docker() { + docker system prune --volumes --all + } - # Prune Nix Store. - function prune_nix() { - nix-store --gc - } + # Prune Nix Store. + function prune_nix() { + nix-store --gc + } - # Uninstall flatpaks not listed in the config. - function prune_flatpak() { - local IFS=$'\n' - local config=($(cat ''${_flatpakcfg_path} | cut -f2)) - local installed=($(flatpak list --app | cut -f2)) + # Uninstall flatpaks not listed in the config. + function prune_flatpak() { + local IFS=$'\n' + local config=($(cat ''${_flatpakcfg_path} | cut -f2)) + local installed=($(flatpak list --app | cut -f2)) - process() { - _contains ''${target} ''${config[@]} || flatpak uninstall ''${target} - } + process() { + _contains ''${target} ''${config[@]} || flatpak uninstall ''${target} + } - _iterate_targets process ''${installed[@]} - } - ''; + _iterate_targets process ''${installed[@]} + } + ''; } diff --git a/home/program/bash/module/Ps.nix b/home/program/bash/module/Ps.nix index bc4fa8b..0a9afe1 100644 --- a/home/program/bash/module/Ps.nix +++ b/home/program/bash/module/Ps.nix @@ -1,15 +1,16 @@ -{ ... }: { - 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 d29b689..39e7e2f 100644 --- a/home/program/bash/module/Ps1.nix +++ b/home/program/bash/module/Ps1.nix @@ -1,157 +1,159 @@ -{ 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.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[@]}") - 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 8346d43..e28b80c 100644 --- a/home/program/bash/module/Random.nix +++ b/home/program/bash/module/Random.nix @@ -1,14 +1,15 @@ -{ ... }: { - 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 38419fa..81aa69e 100644 --- a/home/program/bash/module/Recursive.nix +++ b/home/program/bash/module/Recursive.nix @@ -1,84 +1,85 @@ -{ ... }: { - 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 9d435cc..04555f5 100644 --- a/home/program/bash/module/Reload.nix +++ b/home/program/bash/module/Reload.nix @@ -1,8 +1,9 @@ -{ ... }: { - 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 4760280..85d49c0 100644 --- a/home/program/bash/module/Shopt.nix +++ b/home/program/bash/module/Shopt.nix @@ -1,27 +1,28 @@ -{ ... }: { - 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/Ssh.nix b/home/program/bash/module/Ssh.nix index 9ec7632..f40fcfc 100644 --- a/home/program/bash/module/Ssh.nix +++ b/home/program/bash/module/Ssh.nix @@ -1,22 +1,23 @@ -{ ... }: { - text = '' - # Mount FS over ssh. Just extra config for sshfs. - # Usage: ssh_mount - function ssh_mount() { - sshfs -o uid=''${UID},auto_unmount "''${@}" - } +{ ... }: +{ + text = '' + # Mount FS over ssh. Just extra config for sshfs. + # Usage: ssh_mount + function ssh_mount() { + sshfs -o uid=''${UID},auto_unmount "''${@}" + } - # Mount FS over ssh. Just extra config for sshfs. - # Usage: ssh_mount - function ssh_mount_ro() { - sshfs -o uid=''${UID},auto_unmount,ro "''${@}" - } + # Mount FS over ssh. Just extra config for sshfs. + # Usage: ssh_mount + function ssh_mount_ro() { + sshfs -o uid=''${UID},auto_unmount,ro "''${@}" + } - # Generate private an public keys on a local host and print a public key. - function ssh_keygen() { - ssh-keygen && cat ~/.ssh/*.pub - } + # Generate private an public keys on a local host and print a public key. + function ssh_keygen() { + ssh-keygen && cat ~/.ssh/*.pub + } - complete -o nospace -F _sshfs sshmount - ''; + complete -o nospace -F _sshfs sshmount + ''; } diff --git a/home/program/bash/module/Steam.nix b/home/program/bash/module/Steam.nix index 381d09d..37ad0ad 100644 --- a/home/program/bash/module/Steam.nix +++ b/home/program/bash/module/Steam.nix @@ -1,8 +1,9 @@ -{ ... }: { - text = '' - # Start Steam with Wayland screen share for Link to work. - function steam_link() { - steam -pipewire -pipewire-dmabuf - } - ''; +{ ... }: +{ + text = '' + # Start Steam with Wayland screen share for Link to work. + function steam_link() { + steam -pipewire -pipewire-dmabuf + } + ''; } diff --git a/home/program/bash/module/Su.nix b/home/program/bash/module/Su.nix index e05b200..ee15da9 100644 --- a/home/program/bash/module/Su.nix +++ b/home/program/bash/module/Su.nix @@ -1,34 +1,35 @@ -{ ... }: { - 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/Terminal.nix b/home/program/bash/module/Terminal.nix index e833edc..bd56690 100644 --- a/home/program/bash/module/Terminal.nix +++ b/home/program/bash/module/Terminal.nix @@ -1,10 +1,11 @@ -{ ... }: { - text = '' - # Get terminal size. - function tsize() { - local width=$(tput cols) - local height=$(tput lines) - echo "''${width}x''${height}" - } - ''; +{ ... }: +{ + text = '' + # Get terminal size. + function tsize() { + local width=$(tput cols) + local height=$(tput lines) + echo "''${width}x''${height}" + } + ''; } diff --git a/home/program/bash/module/Tmp.nix b/home/program/bash/module/Tmp.nix index dfb8ffd..d1d169e 100644 --- a/home/program/bash/module/Tmp.nix +++ b/home/program/bash/module/Tmp.nix @@ -1,20 +1,21 @@ -{ ... }: { - text = '' - # CD into host's primary tmp dir. - function tmp() { - local host="''${HOSTNAME}" - local tmp_path +{ ... }: +{ + text = '' + # CD into host's primary tmp dir. + function tmp() { + local host="''${HOSTNAME}" + local tmp_path - case "''${host}" in - "desktop"|"home") - tmp_path="/storage/hot/tmp" - ;; - *) - tmp_path="''${HOME}/tmp" - ;; - esac + case "''${host}" in + "desktop"|"home") + tmp_path="/storage/hot/tmp" + ;; + *) + tmp_path="''${HOME}/tmp" + ;; + esac - cd "''${tmp_path}" - } - ''; + cd "''${tmp_path}" + } + ''; } diff --git a/home/program/bash/module/Tmux.nix b/home/program/bash/module/Tmux.nix index 39aa94f..de2d6b6 100644 --- a/home/program/bash/module/Tmux.nix +++ b/home/program/bash/module/Tmux.nix @@ -1,98 +1,99 @@ -{ ... }: { - 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/Todo.nix b/home/program/bash/module/Todo.nix index e2d10e3..554feea 100644 --- a/home/program/bash/module/Todo.nix +++ b/home/program/bash/module/Todo.nix @@ -1,8 +1,9 @@ -{ ... }: { - text = '' - # Open `~/.todo.md` file. - function todo() { - vi ~/.todo.md - } - ''; +{ ... }: +{ + text = '' + # Open `~/.todo.md` file. + function todo() { + vi ~/.todo.md + } + ''; } diff --git a/home/program/bash/module/Transcode.nix b/home/program/bash/module/Transcode.nix index feb13fb..58923ef 100644 --- a/home/program/bash/module/Transcode.nix +++ b/home/program/bash/module/Transcode.nix @@ -1,101 +1,102 @@ -{ ... }: { - 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 33ceb0d..eaea4f1 100644 --- a/home/program/bash/module/Try.nix +++ b/home/program/bash/module/Try.nix @@ -1,25 +1,26 @@ -{ ... }: { - 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 0ca0a74..d2e4acf 100644 --- a/home/program/bash/module/Util.nix +++ b/home/program/bash/module/Util.nix @@ -1,175 +1,176 @@ -{ ... }: { - 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[@]} + } - # Force the command to be called twice within the specified period in seconds. Used primarily in important keyboard shortcuts like poweroff. - # Usage: _twice - function _twice() { - local IFS=$'\n' - local file="/tmp/.twice" - local period=''${1} - local command="''${@:2}" + # Force the command to be called twice within the specified period in seconds. Used primarily in important keyboard shortcuts like poweroff. + # Usage: _twice + function _twice() { + local IFS=$'\n' + local file="/tmp/.twice" + local period=''${1} + local command="''${@:2}" - if [[ "$(cat ''${file} 2> /dev/null)" = "''${command}" ]]; then - ''${command} - return 0 - fi - echo "''${command}" > "''${file}" - sleep ''${period} - rm "''${file}" 2> /dev/null - } - ''; + if [[ "$(cat ''${file} 2> /dev/null)" = "''${command}" ]]; then + ''${command} + return 0 + fi + echo "''${command}" > "''${file}" + sleep ''${period} + rm "''${file}" 2> /dev/null + } + ''; } diff --git a/home/program/bash/module/Vdl.nix b/home/program/bash/module/Vdl.nix index 3c480e2..270f40e 100644 --- a/home/program/bash/module/Vdl.nix +++ b/home/program/bash/module/Vdl.nix @@ -1,45 +1,46 @@ -{ ... }: { - text = '' - export VDL_PROXY="" +{ ... }: +{ + text = '' + export VDL_PROXY="" - # 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 + # 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 ''${VDL_PROXY} -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 ''${VDL_PROXY} -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 d813bfe..960b7ea 100644 --- a/home/program/bash/module/Vi.nix +++ b/home/program/bash/module/Vi.nix @@ -1,8 +1,9 @@ -{ ... }: { - 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 167f990..6a951a0 100644 --- a/home/program/bash/module/Watch.nix +++ b/home/program/bash/module/Watch.nix @@ -1,28 +1,29 @@ -{ ... }: { - 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 ee6564f..9c8acc7 100644 --- a/home/program/bash/module/Zapret.nix +++ b/home/program/bash/module/Zapret.nix @@ -1,10 +1,11 @@ -{ ... }: { - 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 200 --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 200 --queue-bypass + nfqws --pidfile=/run/nfqws.pid --qnum=201 ''${@} + } + ''; } diff --git a/home/program/default.nix b/home/program/default.nix index 89ebd00..0c0533e 100644 --- a/home/program/default.nix +++ b/home/program/default.nix @@ -1,17 +1,19 @@ -{ secret, ... } @args: let - bash = import ./bash args; -in { - home-manager.enable = true; +{ secret, ... }@args: +let + bash = import ./bash args; +in +{ + home-manager.enable = true; - gpg = { - enable = true; - inherit (secret.crypto) publicKeys; - }; + gpg = { + enable = true; + inherit (secret.crypto) publicKeys; + }; - firefox = import ./firefox args; + firefox = import ./firefox args; - bash = { - enable = true; - initExtra = bash.bashrc; - }; + bash = { + enable = true; + initExtra = bash.bashrc; + }; } diff --git a/home/program/firefox/default.nix b/home/program/firefox/default.nix index ea9ce77..baac62f 100644 --- a/home/program/firefox/default.nix +++ b/home/program/firefox/default.nix @@ -1,151 +1,153 @@ -{ util, pkgs, config, ... }: let - extraConfig = util.trimTabs '' - // Bookmarks. - user_pref("browser.microsummary.enabled", true); - user_pref("browser.places.importBookmarksHTML", true); - user_pref("browser.toolbars.bookmarks.visibility", "never"); +{ pkgs, config, ... }: +let + extraConfig = '' + // Bookmarks. + user_pref("browser.microsummary.enabled", true); + user_pref("browser.places.importBookmarksHTML", true); + user_pref("browser.toolbars.bookmarks.visibility", "never"); - // Fonts. - user_pref("browser.display.use_document_fonts", 0); - user_pref("font.minimum-size.x-cyrillic", ${toString config.style.font.size.application}); - user_pref("font.minimum-size.x-unicode", ${toString config.style.font.size.application}); - user_pref("font.minimum-size.x-western", ${toString config.style.font.size.application}); - user_pref("font.name.monospace.x-cyrillic", "${config.style.font.monospace.name}"); - user_pref("font.name.monospace.x-unicode", "${config.style.font.monospace.name}"); - user_pref("font.name.monospace.x-western", "${config.style.font.monospace.name}"); - user_pref("font.name.sans-serif.x-cyrillic", "${config.style.font.sansSerif.name}"); - user_pref("font.name.sans-serif.x-unicode", "${config.style.font.sansSerif.name}"); - user_pref("font.name.sans-serif.x-western", "${config.style.font.sansSerif.name}"); - user_pref("font.name.serif.x-cyrillic", "${config.style.font.serif.name}"); - user_pref("font.name.serif.x-unicode", "${config.style.font.serif.name}"); - user_pref("font.name.serif.x-western", "${config.style.font.serif.name}"); + // Fonts. + user_pref("browser.display.use_document_fonts", 0); + user_pref("font.minimum-size.x-cyrillic", ${toString config.style.font.size.application}); + user_pref("font.minimum-size.x-unicode", ${toString config.style.font.size.application}); + user_pref("font.minimum-size.x-western", ${toString config.style.font.size.application}); + user_pref("font.name.monospace.x-cyrillic", "${config.style.font.monospace.name}"); + user_pref("font.name.monospace.x-unicode", "${config.style.font.monospace.name}"); + user_pref("font.name.monospace.x-western", "${config.style.font.monospace.name}"); + user_pref("font.name.sans-serif.x-cyrillic", "${config.style.font.sansSerif.name}"); + user_pref("font.name.sans-serif.x-unicode", "${config.style.font.sansSerif.name}"); + user_pref("font.name.sans-serif.x-western", "${config.style.font.sansSerif.name}"); + user_pref("font.name.serif.x-cyrillic", "${config.style.font.serif.name}"); + user_pref("font.name.serif.x-unicode", "${config.style.font.serif.name}"); + user_pref("font.name.serif.x-western", "${config.style.font.serif.name}"); - // Animations. - user_pref("browser.fullscreen.animateUp", 0); - user_pref("browser.fullscreen.autohide", true); + // Animations. + user_pref("browser.fullscreen.animateUp", 0); + user_pref("browser.fullscreen.autohide", true); - // Homepage. - user_pref("browser.newtabpage.enabled", false); - user_pref("browser.startup.homepage", "https://home.voronind.com/"); - user_pref("browser.startup.page", 3); + // Homepage. + user_pref("browser.newtabpage.enabled", false); + user_pref("browser.startup.homepage", "https://home.voronind.com/"); + user_pref("browser.startup.page", 3); - // Passwords. - user_pref("signon.prefillForms", false); - user_pref("signon.rememberSignons", false); + // Passwords. + user_pref("signon.prefillForms", false); + user_pref("signon.rememberSignons", false); - // Formats. - user_pref("image.jxl.enabled", true); + // Formats. + user_pref("image.jxl.enabled", true); - // User agent. - // user_pref("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. + // user_pref("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. - user_pref("network.http.http3.enable", false); + // Disable HTTP3. + user_pref("network.http.http3.enable", false); - // Disable built-in DoH. - user_pref("doh-rollout.disable-heuristics", true); - user_pref("network.trr.mode", 5); + // Disable built-in DoH. + user_pref("doh-rollout.disable-heuristics", true); + user_pref("network.trr.mode", 5); - // HTTPS only mode. - user_pref("dom.security.https_only_mode", true); - user_pref("dom.security.https_only_mode_ever_enabled", true); + // HTTPS only mode. + user_pref("dom.security.https_only_mode", true); + user_pref("dom.security.https_only_mode_ever_enabled", true); - // Style. - user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true); - ''; + // Style. + user_pref("toolkit.legacyUserProfileCustomizations.stylesheets", true); + ''; - userChrome = util.trimTabs '' - * { - font-family: "${config.style.font.serif.name}" !important; - font-size: ${toString config.style.font.size.application}pt !important; - } - ''; + userChrome = '' + * { + font-family: "${config.style.font.serif.name}" !important; + font-size: ${toString config.style.font.size.application}pt !important; + } + ''; - userContent = util.trimTabs '' - @-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 = install_url: { - inherit install_url; - installation_mode = "force_installed"; - }; + mkExtension = install_url: { + inherit install_url; + installation_mode = "force_installed"; + }; - mkBookmark = name: url: { inherit name url; }; -in { - enable = true; - package = pkgs.firefox-esr; - # languagePacks = [ "en-US" "ru" ]; - profiles.default = { - inherit extraConfig userChrome userContent; - }; - policies = { - ManagedBookmarks = [ - { toplevel_name = "Pin"; } - (mkBookmark "Dashboard" "https://home.voronind.com") - (mkBookmark "Watch" "https://watch.voronind.com") - (mkBookmark "Telegram" "https://web.telegram.org/a") - (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") - ]; - ExtensionUpdate = true; - ExtensionSettings = { - # Block extension installation outside of this config. - "*" = { - install_sources = [ "*" ]; - installation_mode = "blocked"; - }; - "addon@darkreader.org" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/darkreader/latest.xpi"; - "cliget@zaidabdulla.com" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/cliget/latest.xpi"; - "foxyproxy@eric.h.jung" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/foxyproxy-standard/latest.xpi"; - "uBlock0@raymondhill.net" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi"; - "{446900e4-71c2-419f-a6a7-df9c091e268b}" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi"; - "{a6c4a591-f1b2-4f03-b3ff-767e5bedf4e7}" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/user-agent-string-switcher/latest.xpi"; - "{d7742d87-e61d-4b78-b8a1-b469842139fa}" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/vimium-ff/latest.xpi"; - "{e7625f06-e252-479d-ac7a-db68aeaff2cb}" = mkExtension "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`. - # "queryamoid@kaply.com" = mkExtension "https://github.com/mkaply/queryamoid/releases/download/v0.1/query_amo_addon_id-0.1-fx.xpi"; - }; - # NOTE: `firefox-esr` edition is required to change default search engine. - SearchEngines = { - Default = "Searx"; - Add = [ - { - Alias = "s"; - Description = "Searx Search"; - IconURL = "https://search.voronind.com/favicon.ico"; - Method = "POST"; - Name = "Searx"; - PostData = "q={searchTerms}"; - # SuggestURLTemplate = "https://search.voronind.com/autocomplete?q={searchTerms}"; - URLTemplate = "https://search.voronind.com/search?q=%{searchTerms}"; - } - ]; - }; - }; + mkBookmark = name: url: { inherit name url; }; +in +{ + enable = true; + package = pkgs.firefox-esr; + # languagePacks = [ "en-US" "ru" ]; + profiles.default = { + inherit extraConfig userChrome userContent; + }; + policies = { + ManagedBookmarks = [ + { toplevel_name = "Pin"; } + (mkBookmark "Dashboard" "https://home.voronind.com") + (mkBookmark "Watch" "https://watch.voronind.com") + (mkBookmark "Telegram" "https://web.telegram.org/a") + (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") + ]; + ExtensionUpdate = true; + ExtensionSettings = { + # Block extension installation outside of this config. + "*" = { + install_sources = [ "*" ]; + installation_mode = "blocked"; + }; + "addon@darkreader.org" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/darkreader/latest.xpi"; + "cliget@zaidabdulla.com" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/cliget/latest.xpi"; + "foxyproxy@eric.h.jung" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/foxyproxy-standard/latest.xpi"; + "uBlock0@raymondhill.net" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/ublock-origin/latest.xpi"; + "{446900e4-71c2-419f-a6a7-df9c091e268b}" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/bitwarden-password-manager/latest.xpi"; + "{a6c4a591-f1b2-4f03-b3ff-767e5bedf4e7}" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/user-agent-string-switcher/latest.xpi"; + "{d7742d87-e61d-4b78-b8a1-b469842139fa}" = mkExtension "https://addons.mozilla.org/firefox/downloads/latest/vimium-ff/latest.xpi"; + "{e7625f06-e252-479d-ac7a-db68aeaff2cb}" = mkExtension "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`. + # "queryamoid@kaply.com" = mkExtension "https://github.com/mkaply/queryamoid/releases/download/v0.1/query_amo_addon_id-0.1-fx.xpi"; + }; + # NOTE: `firefox-esr` edition is required to change default search engine. + SearchEngines = { + Default = "Searx"; + Add = [ + { + Alias = "s"; + Description = "Searx Search"; + IconURL = "https://search.voronind.com/favicon.ico"; + Method = "POST"; + Name = "Searx"; + PostData = "q={searchTerms}"; + # SuggestURLTemplate = "https://search.voronind.com/autocomplete?q={searchTerms}"; + URLTemplate = "https://search.voronind.com/search?q=%{searchTerms}"; + } + ]; + }; + }; } diff --git a/home/user/Dasha.nix b/home/user/Dasha.nix index cfa5bcc..adb1a9b 100644 --- a/home/user/Dasha.nix +++ b/home/user/Dasha.nix @@ -1,29 +1,39 @@ -{ lib -, config -, ... }: with lib; let - cfg = config.user.dasha; -in { - options = { - user.dasha = { - enable = mkEnableOption "dasha"; - }; - }; +{ + lib, + config, + ... +}: +with lib; +let + cfg = config.user.dasha; +in +{ + options = { + user.dasha = { + enable = 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 = 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" + ]; + }; + }; } diff --git a/home/user/Root.nix b/home/user/Root.nix index b0ac676..8e2d0ea 100644 --- a/home/user/Root.nix +++ b/home/user/Root.nix @@ -1,23 +1,33 @@ -{ lib -, config -, secret -, ... }: with lib; let - cfg = config.user.root; -in { - options = { - user.root = { - enable = mkEnableOption "root"; - }; - }; +{ + lib, + config, + secret, + ... +}: +with lib; +let + cfg = config.user.root; +in +{ + options = { + user.root = { + enable = 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 = mkIf cfg.enable { + home.nixos.users = [ + { + username = "root"; + homeDirectory = "/root"; + } + ]; + users.users.root.hashedPassword = secret.hashedPassword; + security.sudo = { + enable = false; + extraConfig = '' + Defaults rootpw + ''; + }; + }; } diff --git a/home/user/Voronind.nix b/home/user/Voronind.nix index e0c4750..f572129 100644 --- a/home/user/Voronind.nix +++ b/home/user/Voronind.nix @@ -1,30 +1,40 @@ -{ lib -, config -, secret -, ... }: with lib; let - cfg = config.user.voronind; -in { - options = { - user.voronind = { - enable = mkEnableOption "voronind"; - }; - }; +{ + lib, + config, + secret, + ... +}: +with lib; +let + cfg = config.user.voronind; +in +{ + options = { + user.voronind = { + enable = 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 = 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" + ]; + }; + }; } diff --git a/home/variable/default.nix b/home/variable/default.nix index c718e08..e6e9a64 100644 --- a/home/variable/default.nix +++ b/home/variable/default.nix @@ -1,28 +1,29 @@ -{ 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 7837544..913f07f 100644 --- a/home/xdg/default.nix +++ b/home/xdg/default.nix @@ -1,17 +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_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_TMP_DIR = "${homeDirectory}/tmp/"; + }; + }; } diff --git a/host/x86_64-linux/dasha/Filesystem.nix b/host/x86_64-linux/dasha/Filesystem.nix index 3b0d528..0ee9c86 100644 --- a/host/x86_64-linux/dasha/Filesystem.nix +++ b/host/x86_64-linux/dasha/Filesystem.nix @@ -1,15 +1,22 @@ -{ ... }: { - fileSystems = { - "/storage/hot" = { - device = "/dev/storage/hot"; - fsType = "ext4"; - options = [ "nofail" "noatime" ]; - }; +{ ... }: +{ + fileSystems = { + "/storage/hot" = { + device = "/dev/storage/hot"; + fsType = "ext4"; + options = [ + "nofail" + "noatime" + ]; + }; - "/storage/cold" = { - device = "/dev/storage/cold"; - fsType = "ext4"; - options = [ "nofail" "noatime" ]; - }; - }; + "/storage/cold" = { + device = "/dev/storage/cold"; + fsType = "ext4"; + options = [ + "nofail" + "noatime" + ]; + }; + }; } diff --git a/host/x86_64-linux/dasha/default.nix b/host/x86_64-linux/dasha/default.nix index 78c41d2..da3ed68 100644 --- a/host/x86_64-linux/dasha/default.nix +++ b/host/x86_64-linux/dasha/default.nix @@ -1,39 +1,40 @@ -{ ... }: { - home.nixos.enable = true; - user = { - dasha.enable = true; - root.enable = true; - }; +{ ... }: +{ + 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; - }; - }; + 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"; - }; - }; + setting = { + cpu.hwmon = { + path = "/sys/devices/platform/coretemp.0/hwmon"; + file = "temp1_input"; + }; + }; } diff --git a/host/x86_64-linux/desktop/Filesystem.nix b/host/x86_64-linux/desktop/Filesystem.nix index 66ccc98..39d9c5a 100644 --- a/host/x86_64-linux/desktop/Filesystem.nix +++ b/host/x86_64-linux/desktop/Filesystem.nix @@ -1,21 +1,33 @@ -{ ... }: { - 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 08f236e..de32465 100644 --- a/host/x86_64-linux/desktop/default.nix +++ b/host/x86_64-linux/desktop/default.nix @@ -1,57 +1,58 @@ -{ ... }: { - 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; - 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; - }; - }; + module = { + autoupdate.enable = true; + builder.client.enable = true; + distrobox.enable = true; + keyd.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"; - }; - }; + setting = { + cpu.hwmon = { + path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; + file = "temp1_input"; + }; + }; } diff --git a/host/x86_64-linux/home/Backup.nix b/host/x86_64-linux/home/Backup.nix index 20f7466..03b7241 100644 --- a/host/x86_64-linux/home/Backup.nix +++ b/host/x86_64-linux/home/Backup.nix @@ -1,103 +1,110 @@ -{ pkgs, util, __findFile, ... } @args: let - bash = import args; - script = pkgs.writeText "backupScript" '' - source ${bash.modulesFile} +{ + pkgs, + util, + __findFile, + ... +}@args: +let + bash = import args; + script = pkgs.writeText "backupScript" '' + 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 32f37a0..3499d6f 100644 --- a/host/x86_64-linux/home/Container.nix +++ b/host/x86_64-linux/home/Container.nix @@ -1,58 +1,80 @@ -{ ... }: { - 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 = { + # 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; + }; - 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" ]; - }; - }; + 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" + ]; + }; + }; } diff --git a/host/x86_64-linux/home/Filesystem.nix b/host/x86_64-linux/home/Filesystem.nix index f6b9231..936decb 100644 --- a/host/x86_64-linux/home/Filesystem.nix +++ b/host/x86_64-linux/home/Filesystem.nix @@ -1,27 +1,37 @@ -{ ... }: { - 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 = [ + "nofail" + "noatime" + ]; + }; - "/storage/cold_2" = { - device = "/dev/storage/cold_2"; - fsType = "ext4"; - options = [ "nofail" "noatime" ]; - }; + "/storage/cold_2" = { + device = "/dev/storage/cold_2"; + fsType = "ext4"; + options = [ + "nofail" + "noatime" + ]; + }; - "/storage/hot" = { - device = "/dev/storage/hot"; - fsType = "ext4"; - options = [ "nofail" "noatime" ]; - }; - }; + "/storage/hot" = { + device = "/dev/storage/hot"; + fsType = "ext4"; + options = [ + "nofail" + "noatime" + ]; + }; + }; - # 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 8514206..f6d9336 100644 --- a/host/x86_64-linux/home/Network.nix +++ b/host/x86_64-linux/home/Network.nix @@ -1,129 +1,136 @@ -{ util, 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. +{ 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; - }; + 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; + }; - # Disable SSH access from everywhere, configure access bellow. - services.openssh.openFirewall = false; + # Disable SSH access from everywhere, configure access bellow. + services.openssh.openFirewall = false; - networking = { - # Use only external DNS. - networkmanager.insertNameservers = [ - "1.1.1.1" - "8.8.8.8" - ]; + networking = { + # Use only external DNS. + networkmanager.insertNameservers = [ + "1.1.1.1" + "8.8.8.8" + ]; - # 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 - ''; + # 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 + ''; - firewall = { - enable = true; - extraCommands = let - # Container configs. - cfg = config.container.module; + firewall = { + enable = true; + extraCommands = + let + # Container configs. + cfg = config.container.module; - # Const. - tcp = "tcp"; - udp = "udp"; + # Const. + tcp = "tcp"; + udp = "udp"; - # 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 + # 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 - # 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} + # 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} - # 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 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) - # 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) + # 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) - # 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) + # 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) - # Allow VPN connections from Wan. - + (mkForward external cfg.vpn.port cfg.vpn.address cfg.vpn.port udp) + # Allow VPN connections from Wan. + + (mkForward external cfg.vpn.port cfg.vpn.address cfg.vpn.port 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) + # 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) - # 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) + # 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) - # 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) + # 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) - # Print serivce. - + (mkForward internal cfg.print.port cfg.print.address cfg.print.port tcp) - ; - }; + # Print serivce. + + (mkForward internal cfg.print.port cfg.print.address cfg.print.port tcp); + }; - # Create Lan bridge. - bridges.${lan}.interfaces = [ - "enp6s0f0" - "enp6s0f1" - "enp7s0f1" - "enp7s0f1" - ]; + # Create Lan bridge. + bridges.${lan}.interfaces = [ + "enp6s0f0" + "enp6s0f1" + "enp7s0f1" + "enp7s0f1" + ]; - interfaces = { - ${lan}.ipv4 = { - # Assign Lan address and subnet. - addresses = [{ - address = internal; - prefixLength = 24; - }]; + 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; - } - ]; - }; - }; - }; + # 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 a77b97b..4e3d645 100644 --- a/host/x86_64-linux/home/Photoprocess.nix +++ b/host/x86_64-linux/home/Photoprocess.nix @@ -1,79 +1,88 @@ # Takes pictures from first photo dir, processes and stores to the second one. -{ util, pkgs, lib, ... } @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 "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /dev/null - } +{ + util, + pkgs, + lib, + ... +}@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 "{\"chat_id\":\"155897358\",\"text\":\"$1\",\"disable_notification\":\"true\"}" https://api.telegram.org/bot2046849441:AAHQpjRK4xpL8tEUyN4JTSDUUze4J0wSIy4/sendMessage &> /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 = { + Type = "oneshot"; + ExecStart = "-${lib.getExe pkgs.bashInteractive} ${script}"; + Restart = "on-failure"; + }; + 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 4940b7c..60c45b1 100644 --- a/host/x86_64-linux/home/default.nix +++ b/host/x86_64-linux/home/default.nix @@ -1,55 +1,56 @@ -{ config, ... }: { - home.nixos.enable = true; - user = { - root.enable = true; - voronind.enable = true; - }; +{ config, ... }: +{ + 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" - "quora.com" - "quoracdn.net" - ]; - }; - }; + 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" + "quora.com" + "quoracdn.net" + ]; + }; + }; - setting = { - cpu.hwmon = { - path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; - file = "temp1_input"; - }; - }; + setting = { + cpu.hwmon = { + path = "/sys/devices/pci0000:00/0000:00:18.3/hwmon"; + file = "temp1_input"; + }; + }; } diff --git a/host/x86_64-linux/laptop/Filesystem.nix b/host/x86_64-linux/laptop/Filesystem.nix index 198c001..c427bcd 100644 --- a/host/x86_64-linux/laptop/Filesystem.nix +++ b/host/x86_64-linux/laptop/Filesystem.nix @@ -1,7 +1,11 @@ -{ ... }: { - 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 40ff579..62a0f36 100644 --- a/host/x86_64-linux/laptop/default.nix +++ b/host/x86_64-linux/laptop/default.nix @@ -1,34 +1,35 @@ -{ ... }: { - 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 0011afc..81cd3be 100644 --- a/host/x86_64-linux/live/default.nix +++ b/host/x86_64-linux/live/default.nix @@ -1,18 +1,19 @@ -{ 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/installation-cd-minimal.nix" + "${inputs.nixpkgs}/nixos/modules/installer/cd-dvd/channel.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 eeba131..de387a5 100644 --- a/host/x86_64-linux/work/Fprint.nix +++ b/host/x86_64-linux/work/Fprint.nix @@ -1,13 +1,14 @@ -{ 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 83d92fc..c2c5d4b 100644 --- a/host/x86_64-linux/work/default.nix +++ b/host/x86_64-linux/work/default.nix @@ -1,39 +1,40 @@ -{ ... }: { - # 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; - voronind.enable = true; - }; + home.nixos.enable = true; + user = { + root.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; - }; - }; + 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"; - }; - }; + setting = { + cpu.hwmon = { + path = "/sys/devices/platform/coretemp.0/hwmon"; + file = "temp1_input"; + }; + }; } diff --git a/lib/Container.nix b/lib/Container.nix index 7e2d959..eb68f25 100644 --- a/lib/Container.nix +++ b/lib/Container.nix @@ -1,78 +1,93 @@ -{ 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; +{ + 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; - # 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 = '' + # 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 378f897..a29e63f 100644 --- a/lib/Util.nix +++ b/lib/Util.nix @@ -1,35 +1,36 @@ # Collection of common functions. -{ 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)); +{ 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)); - # 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 + trimTabs ((import mod args).text) - ) "" files; + # Concat all files by `text` key. + catText = files: args: builtins.foldl' (acc: mod: acc + (import mod args).text) "" 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); - - # Systemd service that does not restart with system switch. - mkStaticSystemdService = params: params // { - restartIfChanged = false; - stopIfChanged = false; - unitConfig.X-StopOnRemoval = false; - }; + # Concat all file paths by `file` key. + catFile = + files: args: builtins.foldl' (acc: mod: acc + (builtins.readFile (import mod args).file)) "" files; + # Concat all files as a set. + catSet = files: args: lib.mkMerge (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; + }; } diff --git a/module/AmdCompute.nix b/module/AmdCompute.nix index 8b3eedb..4b2c7b2 100644 --- a/module/AmdCompute.nix +++ b/module/AmdCompute.nix @@ -1,17 +1,25 @@ -{ 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."; - }; +{ + 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 = 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 = 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 e415266..269bf78 100644 --- a/module/AmdCpu.nix +++ b/module/AmdCpu.nix @@ -1,27 +1,37 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.amd.cpu; +{ + pkgs, + lib, + config, + ... +}: +with lib; +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"; + enableCmd = "0"; + disableCmd = "1"; +in +{ + options = { + module.amd.cpu = { + enable = mkEnableOption "Enable AMD Cpu support."; + powersave = mkEnableOption "Enable 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 = 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; + }; + }; + }) + ]); } diff --git a/module/AmdGpu.nix b/module/AmdGpu.nix index 94e93d2..3dd3048 100644 --- a/module/AmdGpu.nix +++ b/module/AmdGpu.nix @@ -1,25 +1,33 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.amd.gpu; -in { - options = { - module.amd.gpu.enable = mkEnableOption "Enable AMD Gpu support."; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.amd.gpu; +in +{ + options = { + module.amd.gpu.enable = mkEnableOption "Enable 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 = mkIf cfg.enable { + boot.initrd.kernelModules = [ "amdgpu" ]; + services.xserver.videoDrivers = [ "amdgpu" ]; + hardware.graphics = { + enable = true; + enable32Bit = true; + }; + environment.variables.AMD_VULKAN_ICD = "RADV"; - # 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 da28ebb..6d3e36b 100644 --- a/module/AutoUpdateSigned.nix +++ b/module/AutoUpdateSigned.nix @@ -2,61 +2,72 @@ # This is a systemd service that pulls updates every hour. # 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."; - }; - }; +{ + const, + pkgs, + lib, + util, + config, + secret, + ... +}: +with lib; +let + cfg = config.module.autoupdate; +in +{ + options = { + module.autoupdate = { + enable = mkEnableOption "System auto-updates."; + }; + }; - config = mkIf cfg.enable { - programs.git = { - enable = true; - config = { - gpg.ssh.allowedSignersFile = toString secret.crypto.sign.git.allowed; - }; - }; + config = 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"; - Type = "oneshot"; - }; - path = with pkgs; [ - bash - 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 - }; - make switch - ''; - after = [ "network-online.target" ]; - wants = [ "network-online.target" ]; - }; + systemd.services.autoupdate = util.mkStaticSystemdService { + enable = true; + description = "Signed system auto-update."; + serviceConfig = { + RuntimeMaxSec = "55m"; + Type = "oneshot"; + }; + path = with pkgs; [ + bash + 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 + }; + 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; + Unit = "autoupdate.service"; + # RandomizedDelaySec = 60; + }; + wantedBy = [ "timers.target" ]; + }; + }; } diff --git a/module/Bluetooth.nix b/module/Bluetooth.nix index 2d42897..bbe2dde 100644 --- a/module/Bluetooth.nix +++ b/module/Bluetooth.nix @@ -1,15 +1,18 @@ -{ lib, config, ... }: with lib; let - cfg = config.module.desktop.bluetooth; -in { - options = { - module.desktop.bluetooth.enable = mkEnableOption "Bluetooth."; - }; +{ lib, config, ... }: +with lib; +let + cfg = config.module.desktop.bluetooth; +in +{ + options = { + module.desktop.bluetooth.enable = mkEnableOption "Bluetooth."; + }; - config = mkIf cfg.enable { - hardware.bluetooth = { - enable = true; - powerOnBoot = true; - }; - services.blueman.enable = true; - }; + config = mkIf cfg.enable { + hardware.bluetooth = { + enable = true; + powerOnBoot = true; + }; + services.blueman.enable = true; + }; } diff --git a/module/Brightness.nix b/module/Brightness.nix index 6903ec3..284daab 100644 --- a/module/Brightness.nix +++ b/module/Brightness.nix @@ -1,11 +1,14 @@ -{ lib, config, ... }: with lib; let - cfg = config.module.desktop.brightness; -in { - options = { - module.desktop.brightness.enable = mkEnableOption "Brightness."; - }; +{ lib, config, ... }: +with lib; +let + cfg = config.module.desktop.brightness; +in +{ + options = { + module.desktop.brightness.enable = mkEnableOption "Brightness."; + }; - config = mkIf cfg.enable { - programs.light.enable = true; - }; + config = mkIf cfg.enable { + programs.light.enable = true; + }; } diff --git a/module/DisplayManager.nix b/module/DisplayManager.nix index 4c88755..fedc8d1 100644 --- a/module/DisplayManager.nix +++ b/module/DisplayManager.nix @@ -1,15 +1,18 @@ -{ config, lib, ... }: with lib; let - cfg = config.module.desktop.dm; -in { - options = { - module.desktop.dm.enable = mkEnableOption "Display Manager."; - }; +{ config, lib, ... }: +with lib; +let + cfg = config.module.desktop.dm; +in +{ + options = { + module.desktop.dm.enable = mkEnableOption "Display Manager."; + }; - config = mkIf cfg.enable { - services.xserver.enable = true; - services.xserver.xkb = { - layout = config.setting.keyboard.layouts; - options = config.setting.keyboard.options; - }; - }; + config = mkIf cfg.enable { + services.xserver.enable = true; + services.xserver.xkb = { + layout = config.setting.keyboard.layouts; + options = config.setting.keyboard.options; + }; + }; } diff --git a/module/Distrobox.nix b/module/Distrobox.nix index fe4dbc8..73f4315 100644 --- a/module/Distrobox.nix +++ b/module/Distrobox.nix @@ -1,16 +1,24 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.distrobox; -in { - options = { - module.distrobox = { - enable = mkEnableOption "Distrobox."; - }; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.distrobox; +in +{ + options = { + module.distrobox = { + enable = mkEnableOption "Distrobox."; + }; + }; - config = mkIf cfg.enable { - # Distrobox works best with Podman, so enable it here. - module.podman.enable = true; + config = mkIf cfg.enable { + # Distrobox works best with Podman, so enable it here. + module.podman.enable = true; - environment.systemPackages = with pkgs; [ distrobox ]; - }; + environment.systemPackages = with pkgs; [ distrobox ]; + }; } diff --git a/module/Docker.nix b/module/Docker.nix index c1a4713..9b1ea4c 100644 --- a/module/Docker.nix +++ b/module/Docker.nix @@ -1,38 +1,45 @@ -{ 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, ... }: +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; + }; + }; + }; - config = mkIf cfg.enable (mkMerge [ - { - virtualisation.docker.enable = true; + config = mkIf cfg.enable (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 + { + services = { + docker-prune.wantedBy = mkForce [ ]; + docker.wantedBy = mkForce [ ]; + }; + sockets.docker.wantedBy = mkForce [ ]; + }; + } - (mkIf cfg.rootless { - virtualisation.docker.rootless = { - enable = true; - setSocketVariable = true; - }; - }) - ]); + (mkIf cfg.rootless { + virtualisation.docker.rootless = { + enable = true; + setSocketVariable = true; + }; + }) + ]); } diff --git a/module/Ftpd.nix b/module/Ftpd.nix index 3b03038..bb59670 100644 --- a/module/Ftpd.nix +++ b/module/Ftpd.nix @@ -1,31 +1,39 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.ftpd; -in { - options = { - module.ftpd = { - enable = mkEnableOption "Enable FTP server"; - storage = mkOption { - default = null; - type = types.str; - }; - }; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.ftpd; +in +{ + options = { + module.ftpd = { + enable = mkEnableOption "Enable FTP server"; + storage = mkOption { + default = null; + type = 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 = 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 + ''; + }; + }; } diff --git a/module/Gnome.nix b/module/Gnome.nix index f63a84e..b3a160f 100644 --- a/module/Gnome.nix +++ b/module/Gnome.nix @@ -1,54 +1,62 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.desktop.gnome; -in { - options = { - module.desktop.gnome.enable = mkEnableOption "Enable GnOmE"; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.desktop.gnome; +in +{ + options = { + module.desktop.gnome.enable = mkEnableOption "Enable GnOmE"; + }; - config = mkIf cfg.enable { - module.desktop = { - dm.enable = true; - sound.enable = true; - wayland.enable = true; - }; + config = 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; + services.xserver.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 = 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/IntelCpu.nix b/module/IntelCpu.nix index b55da91..5d8d37c 100644 --- a/module/IntelCpu.nix +++ b/module/IntelCpu.nix @@ -1,27 +1,37 @@ # Intel CPU specific configuration. -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.intel.cpu; +{ + pkgs, + lib, + config, + ... +}: +with lib; +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"; + enableCmd = "1"; + disableCmd = "0"; +in +{ + options = { + module.intel.cpu = { + enable = mkEnableOption "Support for Shintel CPUs"; + powersave = mkEnableOption "Enable Shintel 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 = mkIf cfg.enable (mkMerge [ + { + boot.kernelModules = [ "kvm-intel" ]; + } + (mkIf cfg.powersave { + module.powersave = { + enable = true; + cpu.boost = { + inherit controlFile enableCmd disableCmd; + }; + }; + }) + ]); } diff --git a/module/Kernel.nix b/module/Kernel.nix index 20324b7..9c98b10 100644 --- a/module/Kernel.nix +++ b/module/Kernel.nix @@ -1,88 +1,96 @@ -{ 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; - }; - }; - }; +{ + 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 = mkIf cfg.enable (mkMerge [ - { - boot.kernel.sysctl = { - # Allow sysrq. - "kernel.sysrq" = 1; + config = mkIf cfg.enable (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_instances" = 9999999; + "fs.inotify.max_user_watches" = 9999999; + "fs.inotify.max_user_event" = 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; + (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; - }) + (mkIf cfg.hotspotTtlBypass { + boot.kernel.sysctl."net.ipv4.ip_default_ttl" = 65; + }) - (mkIf cfg.latest { - boot.kernelPackages = pkgs.linuxPackages_latest; - }) - ]); + (mkIf cfg.latest { + boot.kernelPackages = pkgs.linuxPackages_latest; + }) + ]); } diff --git a/module/Keyd.nix b/module/Keyd.nix index b3dba1a..fa7d56c 100644 --- a/module/Keyd.nix +++ b/module/Keyd.nix @@ -1,94 +1,102 @@ -{ pkgs, config, lib, ... }: with lib; let - cfg = config.module.keyd; -in { - options = { - module.keyd = { - enable = mkEnableOption "Keyboard remaps."; - }; - }; +{ + pkgs, + config, + lib, + ... +}: +with lib; +let + cfg = config.module.keyd; +in +{ + options = { + module.keyd = { + enable = mkEnableOption "Keyboard remaps."; + }; + }; - config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ keyd ]; + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ keyd ]; - services.keyd = { - enable = true; - keyboards.default = { - ids = [ "*" ]; - settings = { - 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 = { + 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 = { + 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. + }; - # 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 = { + space = "playpause"; + a = "back"; + c = "ejectcd"; + d = "forward"; + e = "nextsong"; + q = "previoussong"; + s = "volumedown"; + v = "micmute"; + w = "volumeup"; + x = "stopcd"; + z = "mute"; + }; - # 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 = { + 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"; + }; + }; + }; + }; - # 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 index 8005ce2..6b4d4a1 100644 --- a/module/Ld.nix +++ b/module/Ld.nix @@ -1,67 +1,68 @@ -{ 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 - # ]; - # }; +{ 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 bbcb36e..3d90502 100644 --- a/module/Ollama.nix +++ b/module/Ollama.nix @@ -1,53 +1,61 @@ # https://github.com/ollama/ollama -{ pkgsStable, lib, config, ... }: with lib; let - pkgs = pkgsStable; - cfg = config.module.ollama; -in { - options = { - module.ollama = { - enable = mkEnableOption "Local LLM server"; - primaryModel = mkOption { - default = "llama3"; - type = types.str; - }; - models = mkOption { - default = [ cfg.primaryModel ]; - type = types.listOf types.str; - }; - }; - }; +{ + pkgsStable, + lib, + config, + ... +}: +with lib; +let + pkgs = pkgsStable; + cfg = config.module.ollama; +in +{ + options = { + module.ollama = { + enable = mkEnableOption "Local LLM server"; + primaryModel = mkOption { + default = "llama3"; + type = types.str; + }; + models = mkOption { + default = [ cfg.primaryModel ]; + type = types.listOf types.str; + }; + }; + }; - config = mkIf cfg.enable { - environment = { - # Specify default model. - variables.OLLAMA_MODEL = cfg.primaryModel; - }; + config = mkIf cfg.enable { + environment = { + # Specify default model. + variables.OLLAMA_MODEL = cfg.primaryModel; + }; - systemd.services = { - # Enable Ollama server. - ollama = { - description = "Ollama LLM server."; - wantedBy = [ "multi-user.target" ]; - wants = [ "NetworkManager-wait-online.service" ]; - after = [ "NetworkManager-wait-online.service" ]; - serviceConfig.Type = "simple"; - script = '' - HOME=/root ${getExe pkgs.ollama} serve - ''; - }; + systemd.services = { + # Enable Ollama server. + ollama = { + description = "Ollama LLM server."; + wantedBy = [ "multi-user.target" ]; + wants = [ "NetworkManager-wait-online.service" ]; + after = [ "NetworkManager-wait-online.service" ]; + serviceConfig.Type = "simple"; + script = '' + HOME=/root ${getExe pkgs.ollama} serve + ''; + }; - # Download Ollama models. - ollamamodel = { - description = "Ollama LLM model."; - wantedBy = [ "multi-user.target" ]; - wants = [ "ollama.service" ]; - after = [ "ollama.service" ]; - serviceConfig.Type = "simple"; - script = '' - sleep 5 - ${getExe pkgs.ollama} pull ${concatStringsSep " " cfg.models} - ''; - }; - }; - }; + # Download Ollama models. + ollamamodel = { + description = "Ollama LLM model."; + wantedBy = [ "multi-user.target" ]; + wants = [ "ollama.service" ]; + after = [ "ollama.service" ]; + serviceConfig.Type = "simple"; + script = '' + sleep 5 + ${getExe pkgs.ollama} pull ${concatStringsSep " " cfg.models} + ''; + }; + }; + }; } diff --git a/module/Package.nix b/module/Package.nix index 9d37611..7a2743c 100644 --- a/module/Package.nix +++ b/module/Package.nix @@ -1,92 +1,103 @@ -{ 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."; - }; - }; +{ + 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."; + }; + }; - config = mkMerge [ - # Core apps. - (mkIf cfg.core.enable { - environment.systemPackages = package.core; + config = mkMerge [ + # Core apps. + (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 { - 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"; - }; + # Common apps. + (mkIf cfg.common.enable { + 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"; + }; - environment.systemPackages = package.common; + environment.systemPackages = package.common; - services.gvfs.enable = true; - }) + services.gvfs.enable = true; + }) - # Desktop apps. - (mkIf cfg.desktop.enable { - environment.systemPackages = package.desktop; - }) + # Desktop apps. + (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. + (mkIf cfg.gaming.enable { + hardware.graphics = + let + packages = with pkgs; [ + dxvk + gamescope + pkgs.mangohud + vkd3d + ]; + in + { + extraPackages = packages; + extraPackages32 = packages; + }; - programs.steam.enable = true; + programs.steam.enable = true; - environment.systemPackages = package.gaming; - }) + environment.systemPackages = package.gaming; + }) - # Creative. - (mkIf cfg.creative.enable { - environment.systemPackages = package.creative; - }) + # Creative. + (mkIf cfg.creative.enable { + environment.systemPackages = package.creative; + }) - # Development. - (mkIf cfg.dev.enable { - environment.systemPackages = package.dev; - }) + # Development. + (mkIf cfg.dev.enable { + environment.systemPackages = package.dev; + }) - # Extras. - (mkIf cfg.extra.enable { - environment.systemPackages = package.extra; - }) - ]; + # Extras. + (mkIf cfg.extra.enable { + environment.systemPackages = package.extra; + }) + ]; } diff --git a/module/Podman.nix b/module/Podman.nix index a32a7d7..c0317a3 100644 --- a/module/Podman.nix +++ b/module/Podman.nix @@ -1,24 +1,27 @@ -{ lib, config, ... }: with lib; let - cfg = config.module.podman; -in { - options = { - module.podman = { - enable = mkEnableOption "OCI Podman."; - }; - }; +{ lib, config, ... }: +with lib; +let + cfg = config.module.podman; +in +{ + options = { + module.podman = { + enable = mkEnableOption "OCI Podman."; + }; + }; - config = mkIf cfg.enable { - virtualisation = { - podman = { - enable = true; + config = 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 1aca08b..d04400b 100644 --- a/module/Polkit.nix +++ b/module/Polkit.nix @@ -1,28 +1,36 @@ # 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."; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.desktop.polkit; +in +{ + options = { + module.desktop.polkit.enable = mkEnableOption "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 = 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" ]; + }; + }; + }; + }; } diff --git a/module/Portal.nix b/module/Portal.nix index 836d19d..705d591 100644 --- a/module/Portal.nix +++ b/module/Portal.nix @@ -1,27 +1,35 @@ # 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."; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.desktop.portal; +in +{ + options = { + module.desktop.portal.enable = mkEnableOption "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 = mkIf cfg.enable { + xdg.portal = { + enable = true; + extraPortals = with pkgs; [ + xdg-desktop-portal-gtk + ]; + config = { + common = { + default = [ + "gtk" + "wlr" + ]; + }; + }; + wlr.enable = true; + xdgOpenUsePortal = false; + }; + }; } diff --git a/module/PowerlimitThinkpad.nix b/module/PowerlimitThinkpad.nix index 2648513..2c0ff0b 100644 --- a/module/PowerlimitThinkpad.nix +++ b/module/PowerlimitThinkpad.nix @@ -1,80 +1,88 @@ # ThinkPad charge limits. -{ pkgs, lib, config, ... } @args: with lib; let - cfg = config.module.powerlimit.thinkpad; +{ + pkgs, + lib, + config, + ... +}@args: +with lib; +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"; + controlFileMin = "/sys/class/power_supply/BAT0/charge_control_start_threshold"; + controlFileMax = "/sys/class/power_supply/BAT0/charge_control_end_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" '' + 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 = 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; + }; + }; + }; - 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 = 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};'"; + }; + }; - # 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 d7594d1..cb672b5 100644 --- a/module/Powersave.nix +++ b/module/Powersave.nix @@ -1,74 +1,82 @@ -{ lib, config, pkgs, ... }: with lib; let - cfg = config.module.powersave; +{ + lib, + config, + pkgs, + ... +}: +with lib; +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" '' + 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 = 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; + }; + }; + }; + }; + }; + }; - 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 = 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}'"; + }; + }; - # 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 21f46a8..73fec70 100644 --- a/module/Print.nix +++ b/module/Print.nix @@ -1,17 +1,25 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.print; -in { - options = { - module.print.enable = mkEnableOption "Add support for printers."; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.print; +in +{ + options = { + module.print.enable = mkEnableOption "Add support for printers."; + }; - config = mkIf cfg.enable { - services.printing = { - enable = true; - clientConf = '' - DigestOptions DenyMD5 - ServerName 10.0.0.1 - ''; - }; - }; + config = mkIf cfg.enable { + services.printing = { + enable = true; + clientConf = '' + DigestOptions DenyMD5 + ServerName 10.0.0.1 + ''; + }; + }; } diff --git a/module/Realtime.nix b/module/Realtime.nix index 08880b4..bc790aa 100644 --- a/module/Realtime.nix +++ b/module/Realtime.nix @@ -1,14 +1,22 @@ # Improve DE performance. -{ lib, config, ... }: with lib; let - cfg = config.module.realtime; -in { - options = { - module.realtime.enable = mkEnableOption "Realtime access."; - }; +{ lib, config, ... }: +with lib; +let + cfg = config.module.realtime; +in +{ + options = { + module.realtime.enable = mkEnableOption "Realtime access."; + }; - config = mkIf cfg.enable { - security.pam.loginLimits = [ - { domain = "@users"; item = "rtprio"; type = "-"; value = 1; } - ]; - }; + config = mkIf cfg.enable { + security.pam.loginLimits = [ + { + domain = "@users"; + item = "rtprio"; + type = "-"; + value = 1; + } + ]; + }; } diff --git a/module/RemoteBuild.nix b/module/RemoteBuild.nix index 60eeccd..49b9b27 100644 --- a/module/RemoteBuild.nix +++ b/module/RemoteBuild.nix @@ -1,84 +1,102 @@ -{ 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."; - }; - }; +{ + 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 = 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 = 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" + ''; + }; - # 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 = { + openssh.authorizedKeys.keys = secret.ssh.buildKeys; + description = "Nix Remote Builder"; + isNormalUser = true; + createHome = lib.mkForce false; + uid = 1234; + home = "/"; + group = "nixbuilder"; + }; - # 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" ]; - }; - }) - ]; + (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" ]; + }; + }) + ]; } diff --git a/module/Sound.nix b/module/Sound.nix index c811910..09a12d0 100644 --- a/module/Sound.nix +++ b/module/Sound.nix @@ -1,20 +1,23 @@ -{ lib, config, ... }: with lib; let - cfg = config.module.desktop.sound; -in { - options = { - module.desktop.sound.enable = mkEnableOption "Sound."; - }; +{ lib, config, ... }: +with lib; +let + cfg = config.module.desktop.sound; +in +{ + options = { + module.desktop.sound.enable = mkEnableOption "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 = 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/Sway.nix b/module/Sway.nix index d625a5b..43b8c23 100644 --- a/module/Sway.nix +++ b/module/Sway.nix @@ -1,41 +1,49 @@ -{ 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; - }; - }; - }; +{ + 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 = 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; - }; + 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"; + 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 - ]; - }; - }; + programs.sway = { + enable = true; + wrapperFeatures = { + base = true; + gtk = true; + }; + extraPackages = with pkgs; [ + swaykbdd + ]; + }; + }; } diff --git a/module/Tablet.nix b/module/Tablet.nix index 356a8bc..803369a 100644 --- a/module/Tablet.nix +++ b/module/Tablet.nix @@ -1,12 +1,15 @@ -{ lib, config, ... }: with lib; let - cfg = config.module.tablet; -in { - options = { - module.tablet.enable = mkEnableOption "Support for tables."; - }; +{ lib, config, ... }: +with lib; +let + cfg = config.module.tablet; +in +{ + options = { + module.tablet.enable = mkEnableOption "Support for tables."; + }; - config = mkIf cfg.enable { - hardware.opentabletdriver.enable = true; - systemd.user.services.opentabletdriver.wantedBy = [ "default.target" ]; - }; + config = 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 94cb250..a14ef63 100644 --- a/module/VirtManager.nix +++ b/module/VirtManager.nix @@ -1,19 +1,27 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.virtmanager; -in { - options = { - module.virtmanager.enable = mkEnableOption "VM support."; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.virtmanager; +in +{ + options = { + module.virtmanager.enable = mkEnableOption "VM support."; + }; - config = mkIf cfg.enable { - virtualisation.libvirtd.enable = true; - programs.virt-manager.enable = true; + config = 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/Waybar.nix b/module/Waybar.nix index 22f2220..08dc797 100644 --- a/module/Waybar.nix +++ b/module/Waybar.nix @@ -1,14 +1,21 @@ -{ lib, config, pkgs, ... }: with lib; let - cfg = config.module.desktop.waybar; -in { - options = { - module.desktop.waybar = { - enable = mkEnableOption "Use Waybar."; - }; - }; +{ + lib, + config, + pkgs, + ... +}: +with lib; +let + cfg = config.module.desktop.waybar; +in +{ + options = { + module.desktop.waybar = { + enable = mkEnableOption "Use Waybar."; + }; + }; - config = mkIf cfg.enable { - environment.systemPackages = with pkgs; [ waybar ]; - }; + config = mkIf cfg.enable { + environment.systemPackages = with pkgs; [ waybar ]; + }; } - diff --git a/module/Wayland.nix b/module/Wayland.nix index a3dc57e..3c440ef 100644 --- a/module/Wayland.nix +++ b/module/Wayland.nix @@ -1,30 +1,38 @@ -{ pkgs, lib, config, ... }: with lib; let - cfg = config.module.desktop.wayland; -in { - options = { - module.desktop.wayland.enable = mkEnableOption "Wayland."; - }; +{ + pkgs, + lib, + config, + ... +}: +with lib; +let + cfg = config.module.desktop.wayland; +in +{ + options = { + module.desktop.wayland.enable = mkEnableOption "Wayland."; + }; - config = { - programs.xwayland.enable = true; + config = { + programs.xwayland.enable = true; - environment = { - systemPackages = with pkgs; [ - wl-clipboard # CLI clipboard support. - ]; + 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"; - }; - }; - }; + 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 3dbb2c4..9228707 100644 --- a/module/Zapret.nix +++ b/module/Zapret.nix @@ -1,156 +1,156 @@ { - lib, - config, - pkgs, - ... + lib, + config, + pkgs, + ... }: let - cfg = config.module.zapret; + 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"; + 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. +{ + 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 = '' + 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 c432a21..ad853d5 100644 --- a/overlay/Example.nix +++ b/overlay/Example.nix @@ -2,26 +2,27 @@ # 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 6227401..a75e934 100644 --- a/overlay/Keyd.nix +++ b/overlay/Keyd.nix @@ -1,40 +1,47 @@ # 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, ... }: +{ + 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="; + }) + ]; - postInstall = let - pypkgs = prev.python3.pkgs; - appMap = pypkgs.buildPythonApplication rec { - inherit (prev.keyd) version src; - inherit patches; + postInstall = + let + pypkgs = prev.python3.pkgs; + appMap = pypkgs.buildPythonApplication rec { + inherit (prev.keyd) version src; + inherit patches; - pname = "keyd-application-mapper"; - format = "other"; + pname = "keyd-application-mapper"; + format = "other"; - postPatch = '' - substituteInPlace scripts/${pname} \ - --replace /bin/sh ${prev.runtimeShell} - ''; + postPatch = '' + substituteInPlace scripts/${pname} \ + --replace /bin/sh ${prev.runtimeShell} + ''; - propagatedBuildInputs = with pypkgs; [ xlib ]; + propagatedBuildInputs = with pypkgs; [ xlib ]; - dontBuild = true; + dontBuild = true; - installPhase = '' - install -Dm555 -t $out/bin scripts/${pname} - ''; + 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 - ''; - }); - })]; + meta.mainProgram = "keyd-application-mapper"; + }; + 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 4fa7538..adbf63c 100644 --- a/overlay/Nix.nix +++ b/overlay/Nix.nix @@ -1,8 +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 40c3ef3..b765342 100644 --- a/package/applefont/default.nix +++ b/package/applefont/default.nix @@ -1,57 +1,66 @@ # Apple San Francisco and New York fonts. # 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 = "sha256-B8xljBAqOoRFXvSOkOKDDWeYUebtMmQLJ8lF05iFnXk="; - }; +{ + lib, + stdenv, + fetchurl, + p7zip, +}: +let + pro = fetchurl { + url = "https://devimages-cdn.apple.com/design/resources/download/SF-Pro.dmg"; + sha256 = "sha256-B8xljBAqOoRFXvSOkOKDDWeYUebtMmQLJ8lF05iFnXk="; + }; - compact = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/SF-Compact.dmg"; - sha256 = "sha256-L4oLQ34Epw1/wLehU9sXQwUe/LaeKjHRxQAF6u2pfTo="; - }; + compact = fetchurl { + url = "https://devimages-cdn.apple.com/design/resources/download/SF-Compact.dmg"; + sha256 = "sha256-L4oLQ34Epw1/wLehU9sXQwUe/LaeKjHRxQAF6u2pfTo="; + }; - mono = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/SF-Mono.dmg"; - sha256 = "sha256-Uarx1TKO7g5yVBXAx6Yki065rz/wRuYiHPzzi6cTTl8="; - }; + mono = fetchurl { + url = "https://devimages-cdn.apple.com/design/resources/download/SF-Mono.dmg"; + sha256 = "sha256-Uarx1TKO7g5yVBXAx6Yki065rz/wRuYiHPzzi6cTTl8="; + }; - ny = fetchurl { - url = "https://devimages-cdn.apple.com/design/resources/download/NY.dmg"; - sha256 = "sha256-yYyqkox2x9nQ842laXCqA3UwOpUGyIfUuprX975OsLA="; - }; -in stdenv.mkDerivation { - name = "applefont"; + ny = fetchurl { + url = "https://devimages-cdn.apple.com/design/resources/download/NY.dmg"; + sha256 = "sha256-yYyqkox2x9nQ842laXCqA3UwOpUGyIfUuprX975OsLA="; + }; +in +stdenv.mkDerivation { + name = "applefont"; - dontUnpack = true; + dontUnpack = true; - nativeBuildInputs = [ p7zip ]; + 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"} + 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 - ''; + 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/default.nix b/package/default.nix index e31362f..5882b0b 100644 --- a/package/default.nix +++ b/package/default.nix @@ -1,121 +1,150 @@ -{ 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 htop # System monitors. - coreutils # UNIX Core utilities. - cryptsetup # Filesystem encryption (LUKS). - curl wcurl # CLI http client. - ddrescue testdisk # Apps to recover data from drives. - 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 gzip xz # Archive and compression tools. - 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 zmap # Network analyzer. - openssh sshfs # 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. - tmux # Terminal multiplexor. - tree # Show directory stricture as a tree. - usbutils # Usb utilities like udiskctl. - utillinux # Common Linux utilities. - ventoy # Boot multiple ISO/images from a single USB stick. - wireguard-tools # Tools to work with Wireguard. - xray zapret # FRKN. - yazi chafa # CLI file manager. - yt-dlp # Video downloader. - zip unzip # Zip archive/unarchive tools. +{ + 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 + htop # System monitors. + coreutils # UNIX Core utilities. + cryptsetup # Filesystem encryption (LUKS). + curl + wcurl # CLI http client. + ddrescue + testdisk # Apps to recover data from drives. + 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 + gzip + xz # Archive and compression tools. + 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 + zmap # Network analyzer. + openssh + sshfs # 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. + tmux # Terminal multiplexor. + tree # Show directory stricture as a tree. + usbutils # Usb utilities like udiskctl. + utillinux # Common Linux utilities. + ventoy # Boot multiple ISO/images from a single USB stick. + wireguard-tools # Tools to work with Wireguard. + xray + zapret # FRKN. + yazi + chafa # CLI file manager. + yt-dlp # Video downloader. + zip + unzip # Zip archive/unarchive tools. - # (pkgs.callPackage ./ytdlp {}) - (pkgs.callPackage ./yamusicdownload {}) - ]; + # (pkgs.callPackage ./ytdlp {}) + (pkgs.callPackage ./yamusicdownload { }) + ]; - desktop = with pkgs; [ - adwaita-icon-theme # GTK icons. - foot # Terminal emulator. - fuzzel # Application launcher. - grim slurp wf-recorder swappy # Screenshot. - mako # Notification system. - networkmanagerapplet # Internet configuration. - pamixer pavucontrol pulseaudio # Audio. - playerctl # Multimedia controls. - sway waybar # Sway WM. + desktop = with pkgs; [ + adwaita-icon-theme # GTK icons. + foot # Terminal emulator. + fuzzel # Application launcher. + grim + slurp + wf-recorder + swappy # Screenshot. + mako # Notification system. + networkmanagerapplet # Internet configuration. + pamixer + pavucontrol + pulseaudio # Audio. + playerctl # Multimedia controls. + sway + waybar # Sway WM. - (pkgs.callPackage ./swayscript args) - ]; + (pkgs.callPackage ./swayscript args) + ]; - common = with pkgs; [ - evince # Document viewer. - chromium # Just in case I ever need it. - 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. + chromium # Just in case I ever need it. + 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. - (mpv.override { scripts = [ mpvScripts.mpris ]; }) # Media player. - ]; + (mpv.override { scripts = [ mpvScripts.mpris ]; }) # Media player. + ]; - gaming = with pkgs; [ - scanmem # Memory edit tool. - steam bottles dxvk gamescope mangohud vkd3d wine64 # Gaming! - steam-run # Run games outside of Steam. - ]; + gaming = with pkgs; [ + scanmem # Memory edit tool. + steam + bottles + dxvk + gamescope + mangohud + vkd3d + wine64 # Gaming! + steam-run # Run games outside of Steam. + ]; - creative = with pkgs; [ - aseprite # Pixel Art draw app. WARNING: Always builds from source. - blender-hip # Blender with HiP support. - krita # Draw! - ]; + creative = with pkgs; [ + aseprite # Pixel Art draw app. WARNING: Always builds from source. + blender-hip # Blender with HiP support. + krita # Draw! + ]; - dev = with pkgs; [ - android-studio - jetbrains.idea-community - nixd # Nix LSP. - ]; + 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 cmatrix # CLI Screensavers. - cowsay lolcat # CLI funni. - 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 + cmatrix # CLI Screensavers. + cowsay + lolcat # CLI funni. + gnome-font-viewer # Font viewer. + jamesdsp # Active audio processing. + 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 5fedd76..52d0701 100644 --- a/package/homer/Config.nix +++ b/package/homer/Config.nix @@ -1,103 +1,109 @@ -{ pkgs, config, ... }: let - iconTheme = "fa-solid"; +{ pkgs, config, ... }: +let + iconTheme = "fa-solid"; - mkGroup = name: icon: items: { - inherit name items; - icon = "${iconTheme} ${icon}"; - }; + mkGroup = name: icon: items: { + inherit name items; + icon = "${iconTheme} ${icon}"; + }; - mkLink = name: icon: url: { - inherit name url; - icon = "${iconTheme} ${icon}"; - target = "_blank"; - }; + mkLink = name: icon: url: { + inherit name url; + icon = "${iconTheme} ${icon}"; + target = "_blank"; + }; - cfg = { - title = "Dashboard"; - subtitle = "Home"; - header = false; - footer = false; - connectivityCheck = false; + cfg = { + 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; - }; + 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; + }; - links = [ - (mkLink "Status" "fa-heartbeat" "https://${config.container.module.status.domain}") - ]; + 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 "Work" "fa-briefcase" [ - (mkLink "Vm Manager" "fa-server" "https://fs-vcsa.fs.fsight.world/ui") - ]) - (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") - ]) - ]; - }; -in { - file = (pkgs.formats.yaml {}).generate "HomerConfig" cfg; + 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 "Work" "fa-briefcase" [ + (mkLink "Vm Manager" "fa-server" "https://fs-vcsa.fs.fsight.world/ui") + ]) + (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") + ]) + ]; + }; +in +{ + file = (pkgs.formats.yaml { }).generate "HomerConfig" cfg; } diff --git a/package/homer/default.nix b/package/homer/default.nix index bfc1121..a9f3dec 100644 --- a/package/homer/default.nix +++ b/package/homer/default.nix @@ -1,26 +1,33 @@ -{ stdenv, pkgs, config, ... } @args: let - cfg = (import ./Config.nix args).file; -in stdenv.mkDerivation (finalAttrs: { - pname = "Homer"; - version = "24.05.1"; +{ + stdenv, + pkgs, + config, + ... +}@args: +let + cfg = (import ./Config.nix args).file; +in +stdenv.mkDerivation (finalAttrs: { + pname = "Homer"; + version = "24.05.1"; - src = pkgs.fetchurl { - url = "https://github.com/bastienwirtz/homer/releases/download/v${finalAttrs.version}/homer.zip"; - sha256 = "sha256-Ji/7BSKCnnhj4NIdGngTHcGRRbx9UWrx48bBsKkEj34="; - }; + src = pkgs.fetchurl { + url = "https://github.com/bastienwirtz/homer/releases/download/v${finalAttrs.version}/homer.zip"; + sha256 = "sha256-Ji/7BSKCnnhj4NIdGngTHcGRRbx9UWrx48bBsKkEj34="; + }; - nativeBuildInputs = with pkgs; [ unzip ]; + nativeBuildInputs = with pkgs; [ unzip ]; - dontUnpack = true; + dontUnpack = true; - installPhase = '' - runHook preInstall + installPhase = '' + runHook preInstall - mkdir -p $out/assets - pushd $out - unzip $src - cp ${cfg} $out/assets/config.yml + 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 7fbfa20..addefe3 100644 --- a/package/jobber/default.nix +++ b/package/jobber/default.nix @@ -1,4 +1,5 @@ -{ 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 ada3deb..c053693 100644 --- a/package/print/default.nix +++ b/package/print/default.nix @@ -1,36 +1,51 @@ # 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"; +{ + stdenv, + fetchurl, + pkgs, + ... +}: +let +in +stdenv.mkDerivation rec { + pname = "pantum-driver"; + version = "1.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="; - }; + src = fetchurl { + url = "https://cloud.voronind.com/s/k6Ea6QsrsKcAeNg/download/Pantum%20Ubuntu%20Driver%20V1_1_106.zip"; + # hash = "sha256-vyhQIdiF7CgRg1wPN94Ex8yfLLam6pf5KRGqSCVlQ34="; + hash = "sha256-IflzEM2kqqMqOQWZ5Eu906dEa85h+NFRmoR7y7WPX7Q="; + }; - buildInputs = with pkgs; [ libusb1 libjpeg8 cups ]; - nativeBuildInputs = with pkgs; [ unzip dpkg autoPatchelfHook ]; + buildInputs = with pkgs; [ + libusb1 + libjpeg8 + cups + ]; + nativeBuildInputs = with pkgs; [ + unzip + dpkg + autoPatchelfHook + ]; - dontUnpack = true; + dontUnpack = true; - installPhase = '' - unzip $src - pushd Pantum\ Ubuntu\ Driver\ V1.1.106/ + installPhase = '' + unzip $src + pushd Pantum\ Ubuntu\ Driver\ V1.1.106/ - dpkg-deb -x ./Resources/pantum_${version}-1_amd64.deb . + 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 645dcf0..71fd9a8 100644 --- a/package/privatebin/Config.nix +++ b/package/privatebin/Config.nix @@ -1,281 +1,282 @@ -{ util, config, ... }: { - text = util.trimTabs '' - ;project page." + ; (optional) info text to display + ; use single, instead of double quotes for HTML attributes + ;info = "More information on the 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." + ; (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 + ; 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" + ; 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) 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 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) 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" + ; (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" + ; 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 + ; 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 + ; 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" + ; 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] + ; 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 + [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" + [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 + [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) 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 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" + ; (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 + [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 + ; 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] + ; 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 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 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 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 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 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 + ;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" + ;[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. + [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" - ''; + ; (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" + ''; } diff --git a/package/privatebin/default.nix b/package/privatebin/default.nix index 1458d58..b00bbef 100644 --- a/package/privatebin/default.nix +++ b/package/privatebin/default.nix @@ -1,35 +1,43 @@ -{ 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"; +{ + 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"; - src = pkgs.fetchFromGitHub { - owner = "PrivateBin"; - repo = "PrivateBin"; - rev = finalAttrs.version; - hash = "sha256-RFP6rhzfBzTmqs4eJXv7LqdniWoeBJpQQ6fLdoGd5Fk="; - }; + src = pkgs.fetchFromGitHub { + owner = "PrivateBin"; + repo = "PrivateBin"; + rev = finalAttrs.version; + hash = "sha256-RFP6rhzfBzTmqs4eJXv7LqdniWoeBJpQQ6fLdoGd5Fk="; + }; - vendorHash = "sha256-JGuO8kXLLXqq76EccdNSoHwYO5OuJT3Au1O2O2szAHI="; + vendorHash = "sha256-JGuO8kXLLXqq76EccdNSoHwYO5OuJT3Au1O2O2szAHI="; - installPhase = '' - runHook preInstall + installPhase = '' + runHook preInstall - mv $out/share/php/PrivateBin/* $out - rm -r $out/share + mv $out/share/php/PrivateBin/* $out + rm -r $out/share - cp ${cfg} $out/cfg/conf.php + cp ${cfg} $out/cfg/conf.php - touch $out/.env - pushd $out + touch $out/.env + pushd $out - runHook postInstall - ''; + runHook postInstall + ''; - postFixup = '' - substituteInPlace $out/index.php --replace-fail \ - "define('PATH', ''')" \ - "define('PATH', '$out/')" - ''; + 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 0168447..51a7ef0 100644 --- a/package/swayscript/default.nix +++ b/package/swayscript/default.nix @@ -1,4 +1,2 @@ -{ 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 b335084..19cf55d 100644 --- a/package/swayscript/script/DisplayWidget.nix +++ b/package/swayscript/script/DisplayWidget.nix @@ -1,101 +1,102 @@ -{ ... }: { - 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 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 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 + } - # Waybar output. - function displaywidget() { - local __monitor=$(_monitor) - local __gaming=$(_gaming) - local __recording=$(_recording) - local __dnd=$(_dnd) - local class="" + # Waybar output. + function displaywidget() { + local __monitor=$(_monitor) + local __gaming=$(_gaming) + local __recording=$(_recording) + local __dnd=$(_dnd) + local class="" - if [[ "''${__monitor}" = "Y" ]] || [[ "''${__gaming}" = "Y" ]] || [[ "''${__recording}" = "Y" ]] || [[ "''${__dnd}" = "Y" ]]; then - class="modified" - fi + if [[ "''${__monitor}" = "Y" ]] || [[ "''${__gaming}" = "Y" ]] || [[ "''${__recording}" = "Y" ]] || [[ "''${__dnd}" = "Y" ]]; then + class="modified" + fi - printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${__dnd} / Monitor: ''${__monitor} / Gaming: ''${__gaming} / Recording: ''${__recording}\", \"class\": \"''${class}\"}\n" - } + printf "{\"text\": \"󰍹\", \"tooltip\": \"DND: ''${__dnd} / Monitor: ''${__monitor} / Gaming: ''${__gaming} / Recording: ''${__recording}\", \"class\": \"''${class}\"}\n" + } - function _monitor() { - local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .power')) + function _monitor() { + 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 _recording() { - [[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y - } + function _recording() { + [[ "$(ps cax | rg wf-recorder)" = "" ]] && printf n || printf Y + } - function _dnd() { - [[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n - } + function _dnd() { + [[ "$(makoctl mode)" = "dnd" ]] && printf Y || printf n + } - function _gaming() { - local outputs=($(swaymsg -t get_outputs | jq -r '.[] | .adaptive_sync_status')) + function _gaming() { + 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 4abc5c8..8974679 100644 --- a/package/swayscript/script/Reload.nix +++ b/package/swayscript/script/Reload.nix @@ -1,26 +1,27 @@ -{ ... }: { - 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 + } - _sway_iterate_sockets re - } - ''; + _sway_iterate_sockets re + } + ''; } diff --git a/package/swayscript/script/Scratchpad.nix b/package/swayscript/script/Scratchpad.nix index d8ae345..1e34911 100644 --- a/package/swayscript/script/Scratchpad.nix +++ b/package/swayscript/script/Scratchpad.nix @@ -1,13 +1,14 @@ -{ ... }: { - 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 fa864ef..cd51530 100644 --- a/package/swayscript/script/Sound.nix +++ b/package/swayscript/script/Sound.nix @@ -1,16 +1,17 @@ -{ ... }: { - 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 991d41e..114a634 100644 --- a/package/swayscript/script/Util.nix +++ b/package/swayscript/script/Util.nix @@ -1,15 +1,16 @@ -{ ... }: { - 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 3b7adf2..701d72c 100644 --- a/package/swayscript/script/Vpn.nix +++ b/package/swayscript/script/Vpn.nix @@ -1,17 +1,18 @@ -{ ... }: { - 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 b41f7e8..5d8aacb 100644 --- a/package/yamusicdownload/default.nix +++ b/package/yamusicdownload/default.nix @@ -1,22 +1,24 @@ -{ pkgs, ... }: with pkgs.python3Packages; buildPythonPackage { - version = "1.0.0"; - pname = "yandex-music-downloader"; - format = "pyproject"; +{ pkgs, ... }: +with pkgs.python3Packages; +buildPythonPackage { + version = "1.0.0"; + pname = "yandex-music-downloader"; + format = "pyproject"; - propagatedBuildInputs = [ - setuptools - setuptools-git - requests - eyed3 - browser-cookie3 - ]; + propagatedBuildInputs = [ + setuptools + setuptools-git + requests + eyed3 + browser-cookie3 + ]; - src = pkgs.fetchFromGitHub { - owner = "llistochek"; - repo = "yandex-music-downloader"; - rev = "08ea384869cbc31efb1e78b831e2356882219951"; - hash = "sha256-WOFesD7HjskyqHaXZAPy3pgSPaEO+tOyQ+5MV3ZO7XU="; - }; + src = pkgs.fetchFromGitHub { + owner = "llistochek"; + repo = "yandex-music-downloader"; + rev = "08ea384869cbc31efb1e78b831e2356882219951"; + hash = "sha256-WOFesD7HjskyqHaXZAPy3pgSPaEO+tOyQ+5MV3ZO7XU="; + }; - meta.mainProgram = "yandex-music-downloader"; + meta.mainProgram = "yandex-music-downloader"; } diff --git a/package/ytdlp/default.nix b/package/ytdlp/default.nix index d315b7a..c943d2a 100644 --- a/package/ytdlp/default.nix +++ b/package/ytdlp/default.nix @@ -1,30 +1,37 @@ -{ lib, stdenv, fetchurl, autoPatchelfHook }: let - version = "2024.05.27"; - hash = "sha256-rwVwteYBlqF4WhLn9I/Hy3tXRbC7mHDKL+btkN3YC0Y="; -in stdenv.mkDerivation { - name = "ytdlp"; +{ + lib, + stdenv, + fetchurl, + autoPatchelfHook, +}: +let + version = "2024.05.27"; + hash = "sha256-rwVwteYBlqF4WhLn9I/Hy3tXRbC7mHDKL+btkN3YC0Y="; +in +stdenv.mkDerivation { + name = "ytdlp"; - dontUnpack = true; + 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}"; - }; + # 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 ]; + nativeBuildInputs = [ autoPatchelfHook ]; - installPhase = '' - mkdir -p $out/bin - cp $src $out/bin/yt-dlp - chmod +x $out/bin/yt-dlp - ''; + 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"; - }; + meta = with lib; { + description = "Youtube Downloader."; + homepage = "https://github.com/yt-dlp/yt-dlp"; + license = licenses.unlicense; + meta.platforms = platforms.all; + mainProgram = "yt-dlp"; + }; } diff --git a/secret/default.nix b/secret/default.nix index 21fe918..7bee284 100644 --- a/secret/default.nix +++ b/secret/default.nix @@ -1,39 +1,40 @@ -{ ... }: { - # 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 = { + format = "ssh"; + key = ./Ssh.key; + allowed = ./Signers.key; + }; - # List of accepted public keys. - publicKeys = [ - { - source = ./Gpg.key; - trust = 5; - } - ]; - }; + # List of accepted public keys. + publicKeys = [ + { + source = ./Gpg.key; + trust = 5; + } + ]; + }; } diff --git a/system/Bootloader.nix b/system/Bootloader.nix index d642b13..c115393 100644 --- a/system/Bootloader.nix +++ b/system/Bootloader.nix @@ -1,41 +1,42 @@ -{ ... }: { - # Enable non-free firmware. - hardware.enableRedistributableFirmware = true; +{ ... }: +{ + # Enable non-free firmware. + hardware.enableRedistributableFirmware = true; - # Configure bootloader. - boot = { - loader = { - efi.canTouchEfiVariables = true; + # Configure bootloader. + boot = { + loader = { + efi.canTouchEfiVariables = true; - # Use systemd to boot. - systemd-boot = { - enable = 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; - }; - }; + # Limit the amound of generations availabe for rollback. + # This helps to save storage space. + configurationLimit = 10; + }; + }; - # Mount /tmp on tmpfs. - tmp.useTmpfs = true; + # Mount /tmp on tmpfs. + tmp.useTmpfs = true; - initrd = { - # Don't really know if I need it. Kept from hardware-configuration. - kernelModules = [ "dm-snapshot" ]; + 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" - ]; - }; - }; + # Kernel modules available for all the hosts. + 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 18e01a6..7ce352e 100644 --- a/system/Crypto.nix +++ b/system/Crypto.nix @@ -1,27 +1,28 @@ -{ 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; [ - yubikey-manager - # yubioath-desktop # OTP. - ]; + environment.systemPackages = with pkgs; [ + 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 11c4da2..822f5ab 100644 --- a/system/Dbus.nix +++ b/system/Dbus.nix @@ -1,3 +1,4 @@ -{ ... }: { - services.dbus.implementation = "broker"; +{ ... }: +{ + services.dbus.implementation = "broker"; } diff --git a/system/Filesystem.nix b/system/Filesystem.nix index 1131fe1..c46594c 100644 --- a/system/Filesystem.nix +++ b/system/Filesystem.nix @@ -1,23 +1,24 @@ # 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."/" = { + device = "/dev/disk/by-partlabel/NIXROOT"; + fsType = "ext4"; + options = [ "noatime" ]; + }; - fileSystems."/boot" = { - device = "/dev/disk/by-partlabel/NIXBOOT"; - fsType = "vfat"; - }; + 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; - # }; + # /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; + # }; } diff --git a/system/Firewall.nix b/system/Firewall.nix index 5c9a0aa..fb2b763 100644 --- a/system/Firewall.nix +++ b/system/Firewall.nix @@ -1,3 +1,4 @@ -{ ... }: { - networking.firewall.enable = true; +{ ... }: +{ + networking.firewall.enable = true; } diff --git a/system/Font.nix b/system/Font.nix index 8bc8ce4..cd18899 100644 --- a/system/Font.nix +++ b/system/Font.nix @@ -1,15 +1,16 @@ -{ pkgs, __findFile, ... }: { - fonts.packages = with pkgs; [ - # Use Apple fonts for system and text. - (pkgs.callPackage {}) +{ 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" ]; }) + # Use Nerd version of Terminus for monospaced fonts. + (nerdfonts.override { fonts = [ "Terminus" ]; }) - # I don't use FA, but add it for compatibility. - font-awesome + # I don't use FA, but add it for compatibility. + font-awesome - # Minecraft font. - minecraftia - ]; + # Minecraft font. + minecraftia + ]; } diff --git a/system/Fstrim.nix b/system/Fstrim.nix index 7b47580..c7d1151 100644 --- a/system/Fstrim.nix +++ b/system/Fstrim.nix @@ -1,3 +1,4 @@ -{ ... }: { - services.fstrim.enable = true; +{ ... }: +{ + services.fstrim.enable = true; } diff --git a/system/Locale.nix b/system/Locale.nix index caf957f..87355b0 100644 --- a/system/Locale.nix +++ b/system/Locale.nix @@ -1,17 +1,18 @@ -{ const, ... }: { - time.timeZone = const.timeZone; - i18n.defaultLocale = "en_US.UTF-8"; +{ 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"; - }; + # 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"; + }; } diff --git a/system/Network.nix b/system/Network.nix index ed42fca..1704b66 100644 --- a/system/Network.nix +++ b/system/Network.nix @@ -1,6 +1,7 @@ -{ 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 450c0e5..d32932c 100644 --- a/system/Nix.nix +++ b/system/Nix.nix @@ -1,33 +1,37 @@ -{ ... }: { - # Allow installation of proprietary software. - nixpkgs.config.allowUnfree = true; +{ ... }: +{ + # 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; + 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" ]; + # Allow use of flakes. + experimental-features = [ + "nix-command " + "flakes" + ]; - # When running GC, keep .drv files. - keep-derivations = true; + # When running GC, keep .drv files. + keep-derivations = true; - # When running GC, keep build dependencies. - keep-outputs = 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; - }; + # 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: 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; - # }; + # 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; + # }; } diff --git a/system/Shell.nix b/system/Shell.nix index 88db7e2..85a6338 100644 --- a/system/Shell.nix +++ b/system/Shell.nix @@ -1,4 +1,5 @@ -{ 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 e3db7c1..fadfb1c 100644 --- a/system/Sshd.nix +++ b/system/Sshd.nix @@ -1,35 +1,39 @@ -{ secret, ... }: { - users.users.root.openssh.authorizedKeys.keys = secret.ssh.trustedKeys; +{ 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; + 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; + UseDns = false; + UsePAM = true; - GSSAPIAuthentication = false; - HostbasedAuthentication = false; - KbdInteractiveAuthentication = false; - KerberosAuthentication = false; - PasswordAuthentication = false; - PermitEmptyPasswords = false; - PubkeyAuthentication = true; - }; - }; + GSSAPIAuthentication = false; + HostbasedAuthentication = false; + KbdInteractiveAuthentication = false; + KerberosAuthentication = false; + PasswordAuthentication = false; + PermitEmptyPasswords = false; + PubkeyAuthentication = true; + }; + }; } diff --git a/system/Systemd.nix b/system/Systemd.nix index b97c50d..47cc1e9 100644 --- a/system/Systemd.nix +++ b/system/Systemd.nix @@ -1,19 +1,20 @@ -{ ... }: { - # 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 fd731c0..53edb55 100644 --- a/system/Users.nix +++ b/system/Users.nix @@ -1,7 +1,8 @@ -{ ... }: { - # 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 c0a7add..d369b2f 100644 --- a/system/Vm.nix +++ b/system/Vm.nix @@ -1,26 +1,27 @@ -{ 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 24b1318..511f113 100644 --- a/system/Zram.nix +++ b/system/Zram.nix @@ -1,3 +1,4 @@ -{ ... }: { - zramSwap.enable = true; +{ ... }: +{ + zramSwap.enable = true; }