From 751694df63b34946e1a79d379eac8c35ba40eed1 Mon Sep 17 00:00:00 2001 From: Azat Bahawi Date: Fri, 16 Sep 2022 15:13:19 +0300 Subject: 2022-09-16 --- configurations/default.nix | 54 +++++++++++++++---------------- configurations/melian/default.nix | 52 ++++++----------------------- flake.nix | 10 ++++-- lib/default.nix | 16 +++++++-- modules/nixfiles/common/home-manager.nix | 20 ++++++------ modules/nixfiles/common/kernel.nix | 1 + modules/nixfiles/common/shell/default.nix | 9 +++++- modules/nixfiles/profiles/headful.nix | 28 +++++++++------- modules/nixfiles/qutebrowser.nix | 29 ++++++++--------- modules/nixfiles/throttled.nix | 3 ++ modules/nixfiles/unbound.nix | 3 +- modules/nixfiles/vim/default.nix | 10 +++--- 12 files changed, 117 insertions(+), 118 deletions(-) diff --git a/configurations/default.nix b/configurations/default.nix index 124baec..40c133f 100644 --- a/configurations/default.nix +++ b/configurations/default.nix @@ -13,11 +13,37 @@ with lib; let modules = attrValues inputs.self.nixosModules ++ modules - ++ [(import configuration)]; + ++ optional (configuration != null) (import configuration); specialArgs = {inherit inputs lib this;}; }); in mapAttrs' mkConfiguration { + test-headless = { + modules = with inputs; [ + "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix" + nixpkgs.nixosModules.notDetected + ]; + this = { + hostname = "test-headless"; + system = "x86_64-linux"; + isHeadless = true; + isHeadful = false; + }; + }; + + test-headful = { + modules = with inputs; [ + "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix" + nixpkgs.nixosModules.notDetected + ]; + this = { + hostname = "test-headful"; + system = "x86_64-linux"; + isHeadless = false; + isHeadful = true; + }; + }; + melian.modules = with inputs; [ nixos-hardware.nixosModules.common-pc-laptop-ssd nixos-hardware.nixosModules.lenovo-thinkpad-t480 @@ -44,30 +70,4 @@ in nixos-hardware.nixosModules.common-pc-hdd nixpkgs.nixosModules.notDetected ]; - - test-headless = { - modules = with inputs; [ - "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix" - nixpkgs.nixosModules.notDetected - ]; - this = { - hostname = "test-headless"; - system = "x86_64-linux"; - isHeadless = true; - isHeadful = false; - }; - }; - - test-headful = { - modules = with inputs; [ - "${nixpkgs}/nixos/modules/profiles/qemu-guest.nix" - nixpkgs.nixosModules.notDetected - ]; - this = { - hostname = "test-headful"; - system = "x86_64-linux"; - isHeadless = false; - isHeadful = true; - }; - }; } diff --git a/configurations/melian/default.nix b/configurations/melian/default.nix index 08cbc8c..0aca218 100644 --- a/configurations/melian/default.nix +++ b/configurations/melian/default.nix @@ -66,15 +66,12 @@ with lib; { }; boot = { - kernelPackages = mkForce pkgs.linuxPackages_xanmod_latest; - - # Speeding Wi-Fi a bit. + # Speeding up Wi-Fi a bit. extraModprobeConfig = '' options iwlwifi 11n_disable=1 ''; initrd = { - kernelModules = []; availableKernelModules = ["ahci" "nvme" "sd_mod" "usb_storage" "usbhid" "xhci_pci"]; luks.devices."root" = { @@ -83,7 +80,6 @@ with lib; { bypassWorkqueues = true; }; }; - kernelModules = ["kvm-intel"]; loader = { efi.canTouchEfiVariables = true; @@ -95,19 +91,10 @@ with lib; { }; }; - hardware = { - trackpoint = { - enable = true; - speed = 500; - sensitivity = 250; - }; - - opengl.extraPackages = with pkgs; [ - intel-media-driver - libvdpau-va-gl - vaapiIntel - vaapiVdpau - ]; + hardware.trackpoint = { + enable = true; + speed = 500; + sensitivity = 250; }; powerManagement = let @@ -127,31 +114,9 @@ with lib; { }; services = { - # No need for this anymore but it kept just in case. - # tlp = { - # enable = true; - # settings = { - # START_CHARGE_THRESH_BAT0 = 75; - # STOP_CHARGE_THRESH_BAT0 = 80; - # RESTORE_THRESHOLDS_ON_BAT = 1; - # }; - # }; - - throttled.enable = mkForce false; - thinkfan = { enable = true; - # Old-style configuration should be nullified because it does not support - # hwmon search and appends to valid configuration resulting in conflicts - # and crash. I probably should make a PR to remove what was introduced[1] - # before. - # - # [1]: https://github.com/NixOS/nixpkgs/commit/02b872310d6a6503639f5a71a14f00441f961bc9 - sensors = mkForce null; - fans = mkForce null; - levels = mkForce null; - settings = { sensors = [ { @@ -161,10 +126,13 @@ with lib; { } ]; fans = [{tpacpi = "/proc/acpi/ibm/fan";}]; - levels = [["level auto" 0 50] ["level disengaged" 50 32767]]; + levels = [ + ["level auto" 0 50] + ["level disengaged" 50 32767] + ]; }; }; - xserver.videoDrivers = ["intel" "modesetting"]; + # xserver.videoDrivers = ["intel" "modesetting"]; }; } diff --git a/flake.nix b/flake.nix index 5fd0fb5..68f66d2 100644 --- a/flake.nix +++ b/flake.nix @@ -259,8 +259,14 @@ inherit (self.checks.${system}.preCommit) shellHook; }; - # Very opinionated but works fast and doesn't get in a way like nixfmt. - formatter = pkgs.alejandra; + # This interface is very primitive... + formatter = pkgs.writeShellApplication { + name = "fmt"; + runtimeInputs = with pkgs; [alejandra]; + text = '' + alejandra --quiet "$@" + ''; + }; checks.preCommit = pre-commit-hooks.lib.${system}.run { src = ./.; diff --git a/lib/default.nix b/lib/default.nix index 7a8dfbf..6517125 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -14,7 +14,19 @@ lib: _: rec { assert exponent > 0; builtins.foldl' (x: _: x * base) 1 (builtins.genList _ exponent); - comcat = lib.concatStringsSep ","; + comcat = builtins.concatStringsSep ","; - mkTcpMem = min: ini: max: (lib.concatMapStrings (x: toString x + " ") [(pow 2 min) (pow 2 ini) (pow 2 max)]); + mapListToAttrs = f: xs: + builtins.listToAttrs (map (name: { + name = + if builtins.isList name + then builtins.elemAt name (builtins.length name - 1) + else name; + value = f name; + }) + xs); + + mkTcpMem = min: ini: max: + assert min <= ini && ini <= max; + builtins.concatMapStrings (x: toString x + " ") (map (pow 2) [min ini max]); } diff --git a/modules/nixfiles/common/home-manager.nix b/modules/nixfiles/common/home-manager.nix index 3e715bb..91f6705 100644 --- a/modules/nixfiles/common/home-manager.nix +++ b/modules/nixfiles/common/home-manager.nix @@ -10,23 +10,21 @@ with lib; { (mkAliasOptionModule ["hm"] ["home-manager" "users" my.username]) ]; - hm.home = {inherit (config.system) stateVersion;}; - home-manager = { backupFileExtension = "bak"; useUserPackages = true; useGlobalPkgs = true; verbose = true; - # TODO You know what to do. - users = { - root.home = { - inherit (config.system) stateVersion; - }; - ${my.username}.home = { - inherit (config.system) stateVersion; - }; - }; + users = + mapListToAttrs (_: { + home = { + inherit (config.system) stateVersion; + }; + }) [ + "root" + my.username + ]; }; system.extraDependencies = [inputs.home-manager]; diff --git a/modules/nixfiles/common/kernel.nix b/modules/nixfiles/common/kernel.nix index f6c096b..2fdfeeb 100644 --- a/modules/nixfiles/common/kernel.nix +++ b/modules/nixfiles/common/kernel.nix @@ -1,6 +1,7 @@ {lib, ...}: with lib; { boot = { + # I don't use it even on laptops. kernelParams = ["hibernate=no"]; kernel.sysctl = { diff --git a/modules/nixfiles/common/shell/default.nix b/modules/nixfiles/common/shell/default.nix index 50ae488..4e0572f 100644 --- a/modules/nixfiles/common/shell/default.nix +++ b/modules/nixfiles/common/shell/default.nix @@ -120,6 +120,13 @@ with lib; { // genAttrs ["grep" "egrep" "fgrep"] (name: "${pkgs.gnugrep}/bin/${name} --color=always"); - systemPackages = with pkgs; [bash-completion bc gawk hr moreutils pv]; + systemPackages = with pkgs; [ + bash-completion + bc + gawk + hr + moreutils + pv + ]; }; } diff --git a/modules/nixfiles/profiles/headful.nix b/modules/nixfiles/profiles/headful.nix index f4d3dc9..ba54b03 100644 --- a/modules/nixfiles/profiles/headful.nix +++ b/modules/nixfiles/profiles/headful.nix @@ -97,18 +97,22 @@ in { }; }; - # There are (arguably) not a lot of reasons to keep mitigations enabled for - # on machine that is not web-facing. First of all, to completely mitigate - # any possible Spectre holes one would need to disable Hyperthreading - # altogether which will essentially put one's computer into the stone age by - # not being able to to effectively utilise multi-core its multicore - # capabilities. Secondly, by enabling mitigations, we introduce a plethora - # of performace overheads[1], which, albeit small, but still contribute to - # the overall speed of things. This is however still poses a security risk, - # which I am willing to take. - # - # [1]: https://www.phoronix.com/scan.php?page=article&item=spectre-meltdown-2&num=11 - boot.kernelParams = ["mitigations=off"]; + boot = { + kernelPackages = mkForce pkgs.linuxPackages_xanmod_latest; + + # There are (arguably) not a lot of reasons to keep mitigations enabled + # for on machine that is not web-facing. First of all, to completely + # mitigate any possible Spectre holes one would need to disable + # Hyperthreading altogether which will essentially put one's computer into + # the stone age by not being able to to effectively utilise multi-core its + # multicore capabilities. Secondly, by enabling mitigations, we introduce + # a plethora of performace overheads[1], which, albeit small, but still + # contribute to the overall speed of things. This is however still poses a + # security risk, which I am willing to take. + # + # [1]: https://www.phoronix.com/scan.php?page=article&item=spectre-meltdown-2&num=11 + kernelParams = ["mitigations=off"]; + }; hardware.opengl = { enable = true; diff --git a/modules/nixfiles/qutebrowser.nix b/modules/nixfiles/qutebrowser.nix index 3fd2c24..dd1d027 100644 --- a/modules/nixfiles/qutebrowser.nix +++ b/modules/nixfiles/qutebrowser.nix @@ -451,21 +451,20 @@ in { }; }; } - // (listToAttrs - (map (name: nameValuePair name "default_size default_family") [ - "completion.category" - "completion.entry" - "contextmenu" - "debug_console" - "downloads" - "hints" - "keyhint" - "messages.error" - "messages.info" - "messages.warning" - "prompts" - "statusbar" - ])); + // mapListToAttrs (_: "default_size default_family") [ + "completion.category" + "completion.entry" + "contextmenu" + "debug_console" + "downloads" + "hints" + "keyhint" + "messages.error" + "messages.info" + "messages.warning" + "prompts" + "statusbar" + ]; qt = mkIf kde.enable { force_platform = null; diff --git a/modules/nixfiles/throttled.nix b/modules/nixfiles/throttled.nix index 2454ebd..f182ee1 100644 --- a/modules/nixfiles/throttled.nix +++ b/modules/nixfiles/throttled.nix @@ -10,6 +10,9 @@ in { options.nixfiles.modules.throttled.enable = mkEnableOption "Throttled"; config = mkIf cfg.enable { + # Disable the module we are trying to "override". + services.throttled.enable = mkForce false; + environment.etc."throttled.conf".text = '' [GENERAL] # Enable or disable the script execution diff --git a/modules/nixfiles/unbound.nix b/modules/nixfiles/unbound.nix index 066cdd3..8c40291 100644 --- a/modules/nixfiles/unbound.nix +++ b/modules/nixfiles/unbound.nix @@ -108,8 +108,7 @@ in { name = "."; forward-tls-upstream = true; forward-addr = let - mkDnsOverTls = ips: auth: - map (ip: concatStrings [ip "@" auth]) ips; + mkDnsOverTls = ips: auth: map (ip: concatStrings [ip "@" auth]) ips; in mkDnsOverTls dns.const.quad9.default "853#dns.quad9.net"; } diff --git a/modules/nixfiles/vim/default.nix b/modules/nixfiles/vim/default.nix index a38c58f..db46d34 100644 --- a/modules/nixfiles/vim/default.nix +++ b/modules/nixfiles/vim/default.nix @@ -12,8 +12,7 @@ in { config = mkIf cfg.enable { programs.vim.package = with pkgs; ((vim_configurable.override {features = "normal";} - // listToAttrs - (map (name: nameValuePair name false) [ + // mapListToAttrs false [ "cscopeSupport" "darwinSupport" "guiSupport" @@ -26,11 +25,14 @@ in { "rubySupport" "tclSupport" "ximSupport" - ])) + ]) .overrideAttrs (_: super: { configureFlags = super.configureFlags - ++ ["--enable-gpm=no" "--enable-gui=no"]; + ++ [ + "--enable-gpm=no" + "--enable-gui=no" + ]; })) .customize { name = "vim"; -- cgit v1.2.3