From 416247800a029fd6a50bb9e327088cf49ab8efdd Mon Sep 17 00:00:00 2001 From: Nathan McCarty Date: Tue, 21 Mar 2023 00:27:19 -0400 Subject: [PATCH] Merge linux base modules --- modules/linux/base.nix | 70 ++++++++++++++++++++++++++++++------ modules/linux/default.nix | 1 - modules/linux/linux/base.nix | 54 ---------------------------- 3 files changed, 59 insertions(+), 66 deletions(-) delete mode 100644 modules/linux/linux/base.nix diff --git a/modules/linux/base.nix b/modules/linux/base.nix index 5169a2e..fb14d5c 100644 --- a/modules/linux/base.nix +++ b/modules/linux/base.nix @@ -1,14 +1,62 @@ -{ config, lib, pkgs, ... }: - +{ config, lib, pkgs, inputs, ... }@attrs: with lib; { - - config = { - nix = mkIf config.nathan.config.nix.autoGC { - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 7d"; + config = mkMerge [ + (mkIf pkgs.stdenv.isLinux { + zramSwap = mkIf config.nathan.services.zramSwap { + enable = true; + algorithm = "lz4"; + memoryPercent = 25; }; - }; - }; + nix = mkIf config.nathan.config.nix.autoGC { + settings.auto-optimise-store = true; + }; + }) + (mkIf config.nathan.config.harden + (import "${inputs.nixpkgs}/nixos/modules/profiles/hardened.nix" attrs)) + (mkIf config.nathan.config.harden { + boot.kernelPackages = pkgs.linuxPackages_5_18_hardened; + security = { + allowSimultaneousMultithreading = true; + unprivilegedUsernsClone = true; + }; + }) + (mkIf ((!config.nathan.config.harden) && config.nathan.config.isDesktop) { + # Use the zen kernel with muqss turned on + boot.kernelPackages = + let unstable = inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}; + in unstable.linuxKernel.packages.linux_lqx; + }) + (mkIf config.nathan.config.isDesktop { + # Setup frequency scaling + powerManagement = { + enable = true; + cpuFreqGovernor = "schedutil"; + }; + }) + (mkIf (config.nathan.config.nix.autoUpdate && pkgs.stdenv.isLinux) { + # Auto update daily at 2 am + system.autoUpgrade = { + enable = true; + allowReboot = true; + # Update from the flake + flake = "git+https://git.stranger.systems/nix/System"; + # Attempt to update daily at 2AM + dates = lib.mkDefault "2:00"; + }; + }) + # Systemd user service cludge + { + systemd.user.extraConfig = '' + DefaultEnvironment="PATH=/run/current-system/sw/bin:/etc/profiles/per-user/${config.nathan.config.user}/bin" + ''; + nix = mkIf config.nathan.config.nix.autoGC { + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 7d"; + }; + }; + + } + ]; } diff --git a/modules/linux/default.nix b/modules/linux/default.nix index 3d3fc1b..98e3f1c 100644 --- a/modules/linux/default.nix +++ b/modules/linux/default.nix @@ -25,7 +25,6 @@ in { ./services/matrix.nix ./services/ipfs.nix ./services/resolved.nix - ./linux/base.nix ]; options = with lib; diff --git a/modules/linux/linux/base.nix b/modules/linux/linux/base.nix deleted file mode 100644 index a9b4735..0000000 --- a/modules/linux/linux/base.nix +++ /dev/null @@ -1,54 +0,0 @@ -{ config, lib, pkgs, inputs, ... }@attrs: -with lib; { - config = mkMerge [ - (mkIf pkgs.stdenv.isLinux { - zramSwap = mkIf config.nathan.services.zramSwap { - enable = true; - algorithm = "lz4"; - memoryPercent = 25; - }; - nix = mkIf config.nathan.config.nix.autoGC { - settings.auto-optimise-store = true; - }; - }) - (mkIf config.nathan.config.harden - (import "${inputs.nixpkgs}/nixos/modules/profiles/hardened.nix" attrs)) - (mkIf config.nathan.config.harden { - boot.kernelPackages = pkgs.linuxPackages_5_18_hardened; - security = { - allowSimultaneousMultithreading = true; - unprivilegedUsernsClone = true; - }; - }) - (mkIf ((!config.nathan.config.harden) && config.nathan.config.isDesktop) { - # Use the zen kernel with muqss turned on - boot.kernelPackages = - let unstable = inputs.nixpkgs-unstable.legacyPackages.${pkgs.system}; - in unstable.linuxKernel.packages.linux_lqx; - }) - (mkIf config.nathan.config.isDesktop { - # Setup frequency scaling - powerManagement = { - enable = true; - cpuFreqGovernor = "schedutil"; - }; - }) - (mkIf (config.nathan.config.nix.autoUpdate && pkgs.stdenv.isLinux) { - # Auto update daily at 2 am - system.autoUpgrade = { - enable = true; - allowReboot = true; - # Update from the flake - flake = "git+https://git.stranger.systems/nix/System"; - # Attempt to update daily at 2AM - dates = lib.mkDefault "2:00"; - }; - }) - # Systemd user service cludge - { - systemd.user.extraConfig = '' - DefaultEnvironment="PATH=/run/current-system/sw/bin:/etc/profiles/per-user/${config.nathan.config.user}/bin" - ''; - } - ]; -}