From c68a6aaa1900211d13e8b00e4a56cb75085aa9d6 Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Sun, 4 May 2025 15:12:41 -0400 Subject: [PATCH] Introduce config.me.optimizations.enable to toggle optimizations. This is more granular than the buildingIso setting. --- nix/configuration/flake.nix | 3 + nix/configuration/hosts/hydra/default.nix | 1 + nix/configuration/hosts/neelix/default.nix | 1 + .../hosts/neelix/optimized_build.nix | 40 +++++----- nix/configuration/hosts/odo/default.nix | 1 + .../hosts/odo/optimized_build.nix | 60 +++++++++------ nix/configuration/hosts/quark/default.nix | 1 + .../hosts/quark/optimized_build.nix | 74 ++++++++++--------- .../roles/global_options/default.nix | 7 +- 9 files changed, 111 insertions(+), 77 deletions(-) diff --git a/nix/configuration/flake.nix b/nix/configuration/flake.nix index 1855e62..9dfa76c 100644 --- a/nix/configuration/flake.nix +++ b/nix/configuration/flake.nix @@ -137,6 +137,7 @@ isoImage.makeEfiBootable = true; isoImage.makeUsbBootable = true; me.buildingIso = true; + me.optimizations.enable = false; } ]; } @@ -163,6 +164,7 @@ isoImage.makeEfiBootable = true; isoImage.makeUsbBootable = true; me.buildingIso = true; + me.optimizations.enable = false; } ]; } @@ -187,6 +189,7 @@ isoImage.makeEfiBootable = true; isoImage.makeUsbBootable = true; me.buildingIso = true; + me.optimizations.enable = false; } ]; } diff --git a/nix/configuration/hosts/hydra/default.nix b/nix/configuration/hosts/hydra/default.nix index 2e21349..fc8ad72 100644 --- a/nix/configuration/hosts/hydra/default.nix +++ b/nix/configuration/hosts/hydra/default.nix @@ -36,6 +36,7 @@ time.timeZone = "America/New_York"; i18n.defaultLocale = "en_US.UTF-8"; + me.optimizations.enable = true; me.secureBoot.enable = false; # Mount tmpfs at /tmp diff --git a/nix/configuration/hosts/neelix/default.nix b/nix/configuration/hosts/neelix/default.nix index 1424cb3..e2fcba8 100644 --- a/nix/configuration/hosts/neelix/default.nix +++ b/nix/configuration/hosts/neelix/default.nix @@ -15,6 +15,7 @@ time.timeZone = "America/New_York"; i18n.defaultLocale = "en_US.UTF-8"; + me.optimizations.enable = false; me.secureBoot.enable = false; # Early KMS diff --git a/nix/configuration/hosts/neelix/optimized_build.nix b/nix/configuration/hosts/neelix/optimized_build.nix index a6ae54f..c1c21ec 100644 --- a/nix/configuration/hosts/neelix/optimized_build.nix +++ b/nix/configuration/hosts/neelix/optimized_build.nix @@ -9,22 +9,15 @@ config = lib.mkMerge [ { } - (lib.mkIf (!config.me.buildingIso) { - nix.settings.system-features = lib.mkForce [ - "gccarch-alderlake" - "gccarch-x86-64-v3" - "benchmark" - "big-parallel" - "kvm" - "nixos-test" - ]; - - # nixpkgs.hostPlatform = { - # gcc.arch = "alderlake"; - # gcc.tune = "alderlake"; - # system = "x86_64-linux"; - - # }; + (lib.mkIf (!config.me.optimizations.enable) { + boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_13; + }) + (lib.mkIf (config.me.optimizations.enable) { + nixpkgs.hostPlatform = { + gcc.arch = "alderlake"; + gcc.tune = "alderlake"; + system = "x86_64-linux"; + }; nixpkgs.overlays = [ ( @@ -42,7 +35,7 @@ }); in { - linux_alderlake = + linux_me = addConfig { # Full preemption @@ -68,10 +61,19 @@ ) ]; - boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_alderlake; + boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_me; + }) + (lib.mkIf (!config.me.buildingIso) { + nix.settings.system-features = lib.mkForce [ + "gccarch-alderlake" + "gccarch-x86-64-v3" + "benchmark" + "big-parallel" + "kvm" + "nixos-test" + ]; }) (lib.mkIf (config.me.buildingIso) { - boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_12; boot.supportedFilesystems = [ "zfs" ]; }) ]; diff --git a/nix/configuration/hosts/odo/default.nix b/nix/configuration/hosts/odo/default.nix index 9903c5f..a7e64f6 100644 --- a/nix/configuration/hosts/odo/default.nix +++ b/nix/configuration/hosts/odo/default.nix @@ -24,6 +24,7 @@ time.timeZone = "America/New_York"; i18n.defaultLocale = "en_US.UTF-8"; + me.optimizations.enable = true; me.secureBoot.enable = true; # Early KMS diff --git a/nix/configuration/hosts/odo/optimized_build.nix b/nix/configuration/hosts/odo/optimized_build.nix index 34ffeac..7315afa 100644 --- a/nix/configuration/hosts/odo/optimized_build.nix +++ b/nix/configuration/hosts/odo/optimized_build.nix @@ -10,27 +10,10 @@ config = lib.mkMerge [ { } - (lib.mkIf (!config.me.buildingIso) { - nix.settings.system-features = lib.mkForce [ - "gccarch-znver4" - "gccarch-skylake" - # "gccarch-alderlake" missing WAITPKG - "gccarch-x86-64-v3" - "gccarch-x86-64-v4" - "benchmark" - "big-parallel" - "kvm" - "nixos-test" - ]; - - # Keep ALL dependencies so we can rebuild offline. This DRASTICALLY increase disk usage, but disk space is cheap. - # system.includeBuildDependencies = true; - - nix.extraOptions = '' - keep-outputs = true - keep-derivations = true - ''; - + (lib.mkIf (!config.me.optimizations.enable) { + boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_14; + }) + (lib.mkIf (config.me.optimizations.enable) { nixpkgs.hostPlatform = { gcc.arch = "znver4"; gcc.tune = "znver4"; @@ -103,8 +86,41 @@ boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_me; }) + (lib.mkIf (!config.me.buildingIso) { + nix.settings.system-features = lib.mkForce [ + "gccarch-znver4" + "gccarch-skylake" + # "gccarch-alderlake" missing WAITPKG + "gccarch-x86-64-v3" + "gccarch-x86-64-v4" + "benchmark" + "big-parallel" + "kvm" + "nixos-test" + ]; + + # Keep ALL dependencies so we can rebuild offline. This DRASTICALLY increase disk usage, but disk space is cheap. + # system.includeBuildDependencies = true; + + # This also should enable building offline? TODO: test. + nix.extraOptions = '' + keep-outputs = true + keep-derivations = true + ''; + + # # building ON + # nixpkgs.localSystem = { system = "aarch64-linux"; }; + # # building FOR + # nixpkgs.crossSystem = { system = "aarch64-linux"; }; + + # nixpkgs.config = { + # replaceStdenv = ({ pkgs }: pkgs.clangStdenv); + # }; + # or maybe an overlay + # stdenv = prev.clangStdenv; + + }) (lib.mkIf (config.me.buildingIso) { - boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_14; boot.supportedFilesystems.zfs = true; }) ]; diff --git a/nix/configuration/hosts/quark/default.nix b/nix/configuration/hosts/quark/default.nix index c8d3d0c..6baad8c 100644 --- a/nix/configuration/hosts/quark/default.nix +++ b/nix/configuration/hosts/quark/default.nix @@ -22,6 +22,7 @@ time.timeZone = "America/New_York"; i18n.defaultLocale = "en_US.UTF-8"; + me.optimizations.enable = true; me.secureBoot.enable = true; # Early KMS diff --git a/nix/configuration/hosts/quark/optimized_build.nix b/nix/configuration/hosts/quark/optimized_build.nix index dff32d4..aecdd43 100644 --- a/nix/configuration/hosts/quark/optimized_build.nix +++ b/nix/configuration/hosts/quark/optimized_build.nix @@ -10,46 +10,16 @@ config = lib.mkMerge [ { } - (lib.mkIf (!config.me.buildingIso) { - nix.settings.system-features = lib.mkForce [ - "gccarch-znver4" - "gccarch-znver5" - "gccarch-skylake" - # "gccarch-alderlake" missing WAITPKG - "gccarch-x86-64-v3" - "gccarch-x86-64-v4" - "benchmark" - "big-parallel" - "kvm" - "nixos-test" - ]; - - # Keep ALL dependencies so we can rebuild offline. This DRASTICALLY increase disk usage, but disk space is cheap. - # system.includeBuildDependencies = true; - - # This also should enable building offline? TODO: test. - nix.extraOptions = '' - keep-outputs = true - keep-derivations = true - ''; - + (lib.mkIf (!config.me.optimizations.enable) { + boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_14; + }) + (lib.mkIf (config.me.optimizations.enable) { nixpkgs.hostPlatform = { gcc.arch = "znver5"; gcc.tune = "znver5"; system = "x86_64-linux"; }; - # # building ON - # nixpkgs.localSystem = { system = "aarch64-linux"; }; - # # building FOR - # nixpkgs.crossSystem = { system = "aarch64-linux"; }; - - # nixpkgs.config = { - # replaceStdenv = ({ pkgs }: pkgs.clangStdenv); - # }; - # or maybe an overlay - # stdenv = prev.clangStdenv; - nixpkgs.overlays = [ ( final: prev: @@ -110,8 +80,42 @@ boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_me; }) + (lib.mkIf (!config.me.buildingIso) { + nix.settings.system-features = lib.mkForce [ + "gccarch-znver4" + "gccarch-znver5" + "gccarch-skylake" + # "gccarch-alderlake" missing WAITPKG + "gccarch-x86-64-v3" + "gccarch-x86-64-v4" + "benchmark" + "big-parallel" + "kvm" + "nixos-test" + ]; + + # Keep ALL dependencies so we can rebuild offline. This DRASTICALLY increase disk usage, but disk space is cheap. + # system.includeBuildDependencies = true; + + # This also should enable building offline? TODO: test. + nix.extraOptions = '' + keep-outputs = true + keep-derivations = true + ''; + + # # building ON + # nixpkgs.localSystem = { system = "aarch64-linux"; }; + # # building FOR + # nixpkgs.crossSystem = { system = "aarch64-linux"; }; + + # nixpkgs.config = { + # replaceStdenv = ({ pkgs }: pkgs.clangStdenv); + # }; + # or maybe an overlay + # stdenv = prev.clangStdenv; + + }) (lib.mkIf (config.me.buildingIso) { - boot.kernelPackages = pkgs.linuxPackagesFor pkgs.linux_6_14; boot.supportedFilesystems.zfs = true; }) ]; diff --git a/nix/configuration/roles/global_options/default.nix b/nix/configuration/roles/global_options/default.nix index 9eeff72..5dec957 100644 --- a/nix/configuration/roles/global_options/default.nix +++ b/nix/configuration/roles/global_options/default.nix @@ -9,7 +9,12 @@ imports = [ ]; options.me = { - + optimizations.enable = lib.mkOption { + type = lib.types.bool; + default = false; + example = true; + description = "Whether we want to enable CPU optimizations (will trigger a rebuild from source)."; + }; }; # options.me.graphics_card_type = lib.mkOption {