From 5da01d688fcfd4d1956197f7b7f9372e88687d05 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Sat, 4 Nov 2023 16:52:03 +0300 Subject: 2023-11-04 --- darwinConfigurations/mairon/default.nix | 2 +- modules/common/bat.nix | 3 +- modules/common/common/nix/default.nix | 38 ++++++------ modules/common/common/shell/default.nix | 2 +- modules/common/direnv.nix | 3 +- modules/common/git.nix | 35 ++++++++--- modules/common/mpv.nix | 79 ++++++++++++++++++++++++ modules/common/profiles/email.nix | 2 +- modules/common/zathura.nix | 5 ++ modules/nixos/common/console.nix | 10 ++- modules/nixos/common/systemd.nix | 1 + modules/nixos/common/xdg.nix | 104 +++++++++----------------------- modules/nixos/default.nix | 1 + modules/nixos/emacs.nix | 15 ++++- modules/nixos/firefox/default.nix | 6 ++ modules/nixos/firefox/userContent.css | 1 + modules/nixos/kde.nix | 2 + modules/nixos/profiles/headful.nix | 40 +----------- modules/nixos/thunderbird.nix | 53 ++++++++++++++++ modules/nixos/unbound.nix | 4 +- packages/nixfiles.nix | 4 +- 21 files changed, 257 insertions(+), 153 deletions(-) create mode 100644 modules/nixos/thunderbird.nix diff --git a/darwinConfigurations/mairon/default.nix b/darwinConfigurations/mairon/default.nix index 807b4f8..dbef20a 100644 --- a/darwinConfigurations/mairon/default.nix +++ b/darwinConfigurations/mairon/default.nix @@ -12,6 +12,7 @@ with lib; { brews = [ {name = "carthage";} {name = "sourcery";} + {name = "xcbeautify";} {name = "xcodegen";} ]; casks = [ @@ -24,7 +25,6 @@ with lib; { {name = "shadowsocksx-ng";} {name = "vial";} {name = "wireshark";} - {name = "xcbeautify";} {name = "xcodes";} ]; }; diff --git a/modules/common/bat.nix b/modules/common/bat.nix index e2d5da1..7f78a59 100644 --- a/modules/common/bat.nix +++ b/modules/common/bat.nix @@ -23,8 +23,9 @@ in { bash = { shellAliases = { - bay = "bat --language=yaml --tabs 2"; baj = "bat --language=json --tabs 2"; + bay = "bat --language=yaml --tabs 2"; + bas = "bat --language=syslog"; }; initExtra = mkAfter '' diff --git a/modules/common/common/nix/default.nix b/modules/common/common/nix/default.nix index a79a0c3..ad7e706 100644 --- a/modules/common/common/nix/default.nix +++ b/modules/common/common/nix/default.nix @@ -174,21 +174,25 @@ with lib; { variables.NIXFILES = "${config.my.home}/src/nixfiles"; }; - hm.home.file.".nix-defexpr/default.nix".text = let - hostname = strings.escapeNixIdentifier this.hostname; - in - optionalString this.isHeadful '' - let - self = builtins.getFlake "nixfiles"; - configurations = self.nixosConfigurations; - local = configurations.${hostname}; - in rec { - inherit self; - inherit (self) inputs lib; - inherit (lib) my; - this = my.configurations.${hostname}; - inherit (local) config; - inherit (local.config.system.build) toplevel vm vmWithBootLoader manual; - } // configurations // local._module.args - ''; + hm = { + home.file.".nix-defexpr/default.nix".text = let + hostname = strings.escapeNixIdentifier this.hostname; + in + optionalString this.isHeadful '' + let + self = builtins.getFlake "nixfiles"; + configurations = self.nixosConfigurations; + local = configurations.${hostname}; + in rec { + inherit self; + inherit (self) inputs lib; + inherit (lib) my; + this = my.configurations.${hostname}; + inherit (local) config; + inherit (local.config.system.build) toplevel vm vmWithBootLoader manual; + } // configurations // local._module.args + ''; + + programs.bash.shellAliases.nix = "nix --verbose --print-build-logs"; + }; } diff --git a/modules/common/common/shell/default.nix b/modules/common/common/shell/default.nix index c3c29de..01db7a5 100644 --- a/modules/common/common/shell/default.nix +++ b/modules/common/common/shell/default.nix @@ -113,7 +113,7 @@ with lib; { // genAttrs ["grep" "egrep" "fgrep"] (name: "${pkgs.gnugrep}/bin/${name} --color=always"); - historyControl = ["ignoredups" "ignorespace"]; + historyControl = ["erasedups" "ignoredups" "ignorespace"]; }; command-not-found.enable = false; diff --git a/modules/common/direnv.nix b/modules/common/direnv.nix index 743f3cf..3429218 100644 --- a/modules/common/direnv.nix +++ b/modules/common/direnv.nix @@ -6,8 +6,7 @@ with lib; let cfg = config.nixfiles.modules.direnv; in { - options.nixfiles.modules.direnv.enable = - mkEnableOption "direnv"; + options.nixfiles.modules.direnv.enable = mkEnableOption "direnv"; config = mkIf cfg.enable { hm = { diff --git a/modules/common/git.nix b/modules/common/git.nix index de401fb..da33eb2 100644 --- a/modules/common/git.nix +++ b/modules/common/git.nix @@ -59,17 +59,31 @@ in { extraConfig = { - advice.detachedHead = false; color.ui = true; core.whitespace = "trailing-space"; + init.defaultBranch = "master"; + status.submoduleSummary = true; + commit.verbose = 1; + push.autoSetupRemote = true; + pull.rebase = true; + rebase = { + autoStash = true; + autoSquash = true; + }; diff = { mnemonicPrefix = true; renames = "copies"; submodule = "log"; }; - init.defaultBranch = "master"; - push.autoSetupRemote = true; - status.submoduleSummary = true; + submodule.recurse = true; + sendemail = rec { + smtpServer = my.domain.shire; + smtpUser = "${my.username}@${smtpServer}"; + smtpEncryption = "ssl"; + smtpServerPort = 465; + annotate = true; + confirm = "always"; + }; github.user = my.username; gitlab.user = my.username; } @@ -95,10 +109,14 @@ in { git = "${config.hm.programs.git.package}/bin/git"; curl = "${pkgs.curl}/bin/curl"; in { - fuck = "!${git} reset --hard && ${git} clean -fdx"; + amend = "commit --amend"; + cat = "cat-file -p"; + fast = "clone --depth=1"; + fixup = "commit --fixup"; + fuck = "!${git} reset --hard && ${git} clean --force -dx"; + get = "pull --all --recurse-submodules --autostash"; gud = ''commit -m "git gud"''; - review = "!${git} lg @{push}.."; - reword = "commit --amend"; + refresh = "clean --force -X"; tree = "log --graph --date=relative --pretty=tformat:'%Cred%h%Creset -%C(auto)%d%Creset %s %Cgreen(%an %ad)%Creset'"; uncommit = "reset --soft HEAD~1"; untrack = "rm --cache --"; @@ -106,8 +124,7 @@ in { }; # All helper tools/editor generated files should go here. This must be - # kept relatively clean and void of any project-specific residual - # files. + # kept void of any project-specific or residual files. ignores = [ "*~" ".DS_Store" diff --git a/modules/common/mpv.nix b/modules/common/mpv.nix index 37fbe4c..757ccd8 100644 --- a/modules/common/mpv.nix +++ b/modules/common/mpv.nix @@ -10,6 +10,85 @@ in { options.nixfiles.modules.mpv.enable = mkEnableOption "mpv"; config = mkIf cfg.enable { + nixfiles.modules.common.xdg.defaultApplications.mpv = let + audio = [ + "audio/aac" + "audio/ac3" + "audio/basic" + "audio/flac" + "audio/midi" + "audio/mp4" + "audio/mpeg" + "audio/ogg" + "audio/opus" + "audio/vnd.dts" + "audio/vnd.dts.hd" + "audio/webm" + "audio/x-adpcm" + "audio/x-aifc" + "audio/x-aiff" + "audio/x-ape" + "audio/x-flac+ogg" + "audio/x-m4b" + "audio/x-m4r" + "audio/x-matroska" + "audio/x-mpegurl" + "audio/x-musepack" + "audio/x-opus+ogg" + "audio/x-speex" + "audio/x-speex+ogg" + "audio/x-vorbis+ogg" + "audio/x-wav" + "audio/x-wavpack" + "x-content/audio-cdda" + "x-content/audio-dvd" + ]; + video = [ + "video/3gpp" + "video/3gpp2" + "video/mkv" + "video/mp2t" + "video/mp4" + "video/mpeg" + "video/ogg" + "video/quicktime" + "video/vnd.mpegurl" + "video/vnd.radgamettools.bink" + "video/vnd.radgamettools.smacker" + "video/wavelet" + "video/webm" + "video/x-matroska" + "video/x-matroska-3d" + "video/x-mjpeg" + "video/x-msvideo" + "video/x-ogm+ogg" + "video/x-theora+ogg" + "x-content/video-bluray" + "x-content/video-dvd" + "x-content/video-hddvd" + "x-content/video-svcd" + "x-content/video-vcd" + ]; + image = [ + "image/avif" + "image/bmp" + "image/gif" + "image/jp2" + "image/jpeg" + "image/jpg" + "image/jpm" + "image/jpx" + "image/jxl" + "image/png" + "image/tiff" + "image/vnd.microsoft.icon" + "image/webp" + "image/webp" + "image/x-tga" + ]; + in + audio ++ video ++ image; + hm.programs = { mpv = { enable = true; diff --git a/modules/common/profiles/email.nix b/modules/common/profiles/email.nix index 56fabe1..9064f70 100644 --- a/modules/common/profiles/email.nix +++ b/modules/common/profiles/email.nix @@ -57,7 +57,7 @@ in { "'${toString line}!d'" ] ); - in rec { + in { shire = mkAccount rec { address = my.email; aliases = [address "frodo@rohan.net" "azahi@shire.net"]; diff --git a/modules/common/zathura.nix b/modules/common/zathura.nix index f78a9e9..408f218 100644 --- a/modules/common/zathura.nix +++ b/modules/common/zathura.nix @@ -10,6 +10,11 @@ in { mkEnableOption "Zathura PDF reader"; config = mkIf cfg.enable { + nixfiles.modules.common.xdg.defaultApplications."org.pwmt.zathura" = [ + "application/pdf" + "application/epub+zip" + ]; + hm.programs.zathura = with config.nixfiles.modules; { enable = true; diff --git a/modules/nixos/common/console.nix b/modules/nixos/common/console.nix index 3c73695..60a7153 100644 --- a/modules/nixos/common/console.nix +++ b/modules/nixos/common/console.nix @@ -1,6 +1,14 @@ -{config, ...}: { +{ + config, + lib, + pkgs, + ... +}: +with lib; { console = { earlySetup = true; + colors = take 16 (mapAttrsToList (_: removePrefix "#") config.colourScheme); + font = "${pkgs.terminus_font}/share/consolefonts/ter-v16b.psf.gz"; useXkbConfig = config.services.xserver.enable; }; } diff --git a/modules/nixos/common/systemd.nix b/modules/nixos/common/systemd.nix index 4e9eb26..f3d5217 100644 --- a/modules/nixos/common/systemd.nix +++ b/modules/nixos/common/systemd.nix @@ -23,6 +23,7 @@ }; environment.sessionVariables = { + SYSTEMD_PAGERSECURE = "1"; SYSTEMD_PAGER = "${pkgs.less}/bin/less"; SYSTEMD_LESS = "FRSXMK"; }; diff --git a/modules/nixos/common/xdg.nix b/modules/nixos/common/xdg.nix index b46c350..668996f 100644 --- a/modules/nixos/common/xdg.nix +++ b/modules/nixos/common/xdg.nix @@ -7,85 +7,37 @@ with lib; let cfg = config.nixfiles.modules.common.xdg; in { - xdg.portal = mkIf this.isHeadful { - enable = true; + options.nixfiles.modules.common.xdg.defaultApplications = mkOption { + description = "Default applications."; + type = with types; attrsOf (listOf str); + default = {}; }; - hm.xdg = mkMerge [ - (with cfg; { + config = { + xdg.portal = mkIf this.isHeadful { enable = true; + }; - inherit cacheHome; - inherit configHome; - inherit dataHome; - inherit stateHome; - inherit userDirs; - }) - (mkIf this.isHeadful { - mimeApps = { + hm.xdg = mkMerge [ + (with cfg; { enable = true; - # https://developer.mozilla.org/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types - defaultApplications = mkMerge (mapAttrsToList - (n: v: genAttrs v (_: ["${n}.desktop"])) - { - emacsclient = [ - "application/json" - "application/ld+json" - "application/vnd.ms-publisher" - "application/x-c" - "application/x-desktop" - "application/x-httpd-php" - "application/x-sh" - "application/x-tex" - "application/xhtml+xml" - "application/xml" - "text/css" - "text/csv" - "text/javascript" - "text/markdown" - "text/plain" - "text/x-lisp" - ]; - firefox = [ - "text/html" - "x-scheme-handler/http" - "x-scheme-handler/https" - ]; - mpv = [ - "audio/3gpp" - "audio/3gpp2" - "audio/aac" - "audio/flac" - "audio/mp3" - "audio/mpeg" - "audio/ogg" - "audio/opus" - "audio/wav" - "audio/webm" - "image/avif" - "image/bmp" - "image/gif" - "image/jpeg" - "image/jpg" - "image/png" - "image/tiff" - "image/vnd.microsoft.icon" - "image/webp" - "video/mkv" - "video/mp2t" - "video/mp4" - "video/mpeg" - "video/ogg" - "video/webm" - "video/x-matroska" - "video/x-msvideo" - ]; - "org.pwmt.zathura" = [ - "application/pdf" - "application/epub+zip" - ]; - }); - }; - }) - ]; + + inherit cacheHome; + inherit configHome; + inherit dataHome; + inherit stateHome; + inherit userDirs; + }) + (mkIf this.isHeadful { + mimeApps = { + enable = true; + defaultApplications = + mkMerge + (mapAttrsToList + (n: v: genAttrs v (_: ["${n}.desktop"])) + cfg.defaultApplications); + }; + }) + ]; + }; } diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix index e8c9467..1b1ec75 100644 --- a/modules/nixos/default.nix +++ b/modules/nixos/default.nix @@ -61,6 +61,7 @@ _: { ./sound.nix ./syncthing.nix ./throttled.nix + ./thunderbird.nix ./unbound.nix ./vaultwarden.nix ./vim diff --git a/modules/nixos/emacs.nix b/modules/nixos/emacs.nix index 5e263c9..8163c45 100644 --- a/modules/nixos/emacs.nix +++ b/modules/nixos/emacs.nix @@ -7,7 +7,20 @@ with lib; let cfg = config.nixfiles.modules.emacs; in { config = mkIf cfg.enable { - nixfiles.modules.x11.enable = true; + nixfiles.modules = { + common.xdg.defaultApplications.emacsclient = [ + "application/atom+xml" + "application/json" + "application/rss+xml" + "application/schema+json" + "application/xhtml+xml" + "application/xml" + "text/csv" + "text/plain" + ]; + + x11.enable = true; + }; hm.services.emacs = { enable = true; diff --git a/modules/nixos/firefox/default.nix b/modules/nixos/firefox/default.nix index e725e95..041752d 100644 --- a/modules/nixos/firefox/default.nix +++ b/modules/nixos/firefox/default.nix @@ -11,6 +11,12 @@ in { options.nixfiles.modules.firefox.enable = mkEnableOption "Firefox"; config = mkIf cfg.enable { + nixfiles.modules.common.xdg.defaultApplications.firefox = [ + "text/html" + "x-scheme-handler/http" + "x-scheme-handler/https" + ]; + hm = { imports = [inputs.arkenfox-nixos.hmModules.arkenfox]; diff --git a/modules/nixos/firefox/userContent.css b/modules/nixos/firefox/userContent.css index f5497ab..bb80dbc 100644 --- a/modules/nixos/firefox/userContent.css +++ b/modules/nixos/firefox/userContent.css @@ -316,6 +316,7 @@ #mp-topbanner, #siteNotice, #siteSub, + #wmde-banner-app, .mw-footer-container, .mw-header, .vector-page-toolbar { diff --git a/modules/nixos/kde.nix b/modules/nixos/kde.nix index 17fcf03..1a02d9d 100644 --- a/modules/nixos/kde.nix +++ b/modules/nixos/kde.nix @@ -11,6 +11,8 @@ in { config = mkIf cfg.enable { nixfiles.modules = { + common.xdg.defaultApplications."org.kde.dolphin" = ["inode/directory"]; + gnupg.pinentry = "qt"; sound.enable = true; x11.enable = true; diff --git a/modules/nixos/profiles/headful.nix b/modules/nixos/profiles/headful.nix index 6658582..938b711 100644 --- a/modules/nixos/profiles/headful.nix +++ b/modules/nixos/profiles/headful.nix @@ -12,6 +12,7 @@ in { chromium.enable = true; firefox.enable = true; sound.enable = true; + thunderbird.enable = true; nullmailer.enable = true; @@ -30,43 +31,7 @@ in { tor-browser-bundle-bin ]; - programs = { - bash.shellAliases.open = "xdg-open"; - - thunderbird = { - enable = true; - profiles.default = { - isDefault = true; - withExternalGnupg = true; - }; - settings = { - "app.update.auto" = false; - "browser.display.document_color_use" = 2; - "browser.display.use_system_colors" = true; - "browser.search.region" = "US"; - "browser.search.update" = false; - "datareporting.healthreport.uploadEnabled" = false; - "full-screen-api.warning.delay" = 0; - "full-screen-api.warning.timeout" = 0; - "general.autoScroll" = true; - "general.smoothScroll" = true; - "mail.default_send_format" = 0; - "mail.tabs.drawInTitlebar" = - if config.nixfiles.modules.kde.enable - then 1 - else 0; - "mailnews.start_page.url" = "about:blank"; - "media.autoplay.blocking_policy" = 2; - "media.autoplay.default" = 5; - "media.autoplay.enabled" = false; - "media.hardwaremediakeys.enabled" = false; - "network.cookie.cookieBehavior" = 2; - "places.history.enabled" = false; - "reader.parse-on-load.enabled" = false; - "toolkit.legacyUserProfileCustomizations.stylesheets" = true; - }; - }; - }; + programs.bash.shellAliases.open = "xdg-open"; }; boot = { @@ -104,7 +69,6 @@ in { }; services = { - # https://github.com/NixOS/nixpkgs/issues/135888 upower.enable = true; psd.enable = true; diff --git a/modules/nixos/thunderbird.nix b/modules/nixos/thunderbird.nix new file mode 100644 index 0000000..5afb163 --- /dev/null +++ b/modules/nixos/thunderbird.nix @@ -0,0 +1,53 @@ +{ + config, + lib, + ... +}: +with lib; let + cfg = config.nixfiles.modules.thunderbird; +in { + options.nixfiles.modules.thunderbird.enable = mkEnableOption "Thunderbird"; + + config = mkIf cfg.enable { + nixfiles.modules.common.xdg.defaultApplications.thunderbird = [ + "message/rfc822" + "x-scheme-handler/mailto" + ]; + + hm = { + programs.thunderbird = { + enable = true; + profiles.default = { + isDefault = true; + withExternalGnupg = true; + }; + settings = { + "app.update.auto" = false; + "browser.display.document_color_use" = 2; + "browser.display.use_system_colors" = true; + "browser.search.region" = "US"; + "browser.search.update" = false; + "datareporting.healthreport.uploadEnabled" = false; + "full-screen-api.warning.delay" = 0; + "full-screen-api.warning.timeout" = 0; + "general.autoScroll" = true; + "general.smoothScroll" = true; + "mail.default_send_format" = 0; + "mail.tabs.drawInTitlebar" = + if config.nixfiles.modules.kde.enable + then 1 + else 0; + "mailnews.start_page.url" = "about:blank"; + "media.autoplay.blocking_policy" = 2; + "media.autoplay.default" = 5; + "media.autoplay.enabled" = false; + "media.hardwaremediakeys.enabled" = false; + "network.cookie.cookieBehavior" = 2; + "places.history.enabled" = false; + "reader.parse-on-load.enabled" = false; + "toolkit.legacyUserProfileCustomizations.stylesheets" = true; + }; + }; + }; + }; +} diff --git a/modules/nixos/unbound.nix b/modules/nixos/unbound.nix index 4d21fd2..dd7e757 100644 --- a/modules/nixos/unbound.nix +++ b/modules/nixos/unbound.nix @@ -151,14 +151,12 @@ in { localControlSocketPath = "/run/unbound/unbound.socket"; }; - # TODO Switch to https://github.com/letsencrypt/unbound_exporter. prometheus.exporters.unbound = { enable = true; listenAddress = mkDefault this.wireguard.ipv4.address; port = 9167; - fetchType = "uds"; - controlInterface = config.services.unbound.localControlSocketPath; inherit (config.services.unbound) group user; + unbound.host = "unix://${config.services.unbound.localControlSocketPath}"; }; }; diff --git a/packages/nixfiles.nix b/packages/nixfiles.nix index b534e3c..c342501 100644 --- a/packages/nixfiles.nix +++ b/packages/nixfiles.nix @@ -108,10 +108,10 @@ # Assumes that hosts are configured in the OpenSSH configuration. host=''${cmd#@} hostname=$(ssh -q "$host" 'echo "$HOSTNAME"') - exec nixos-rebuild -v --flake ".#$hostname" --target-host "$host" --use-remote-sudo "$@" + exec nixos-rebuild -v --flake ".#$hostname" --target-host "$host" --use-remote-sudo --show-trace "$@" ;; *) - exec nixos-rebuild -v --fast --flake "." --use-remote-sudo "$cmd" "$@" + exec nixos-rebuild -v --fast --flake "." --use-remote-sudo --show-trace "$cmd" "$@" ;; esac ''; -- cgit 1.4.1