From 0363c18c3704c44d4a282ecbd1455b325bc37a77 Mon Sep 17 00:00:00 2001 From: Sam <30577766+Samasaur1@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:21:19 -0800 Subject: [PATCH 1/2] `system.nvram`: init (internal) --- modules/module-list.nix | 1 + modules/system/activation-scripts.nix | 1 + modules/system/nvram.nix | 40 +++++++++++++++++++++++++++ 3 files changed, 42 insertions(+) create mode 100644 modules/system/nvram.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index a75b3233b..66440a1ae 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -35,6 +35,7 @@ ./system/etc.nix ./system/keyboard.nix ./system/launchd.nix + ./system/nvram.nix ./system/patches.nix ./system/shells.nix ./system/version.nix diff --git a/modules/system/activation-scripts.nix b/modules/system/activation-scripts.nix index 67d69bed7..68e01b592 100644 --- a/modules/system/activation-scripts.nix +++ b/modules/system/activation-scripts.nix @@ -69,6 +69,7 @@ in ${cfg.activationScripts.networking.text} ${cfg.activationScripts.keyboard.text} ${cfg.activationScripts.fonts.text} + ${cfg.activationScripts.nvram.text} ${cfg.activationScripts.postActivation.text} diff --git a/modules/system/nvram.nix b/modules/system/nvram.nix new file mode 100644 index 000000000..efc9c9980 --- /dev/null +++ b/modules/system/nvram.nix @@ -0,0 +1,40 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.system; + + mkNvramVariables = + lib.attrsets.mapAttrsToList + (name: value: "nvram ${lib.escapeShellArg name}=${lib.escapeShellArg value}") + cfg.nvram.variables; +in + +{ + meta.maintainers = [ + lib.maintainers.samasaur or "samasaur" + ]; + + options = { + system.nvram.variables = lib.mkOption { + type = with lib.types; attrsOf str; + default = {}; + internal = true; + example = { + "StartupMute" = "%01"; + }; + description = lib.mdDoc '' + Non-volatile RAM variables to set. Removing a key-value pair from this + list will **not** return the variable to its previous value, but will + no longer set its value on system configuration activations. + ''; + }; + }; + + config = { + system.activationScripts.nvram.text = '' + echo "setting nvram variables..." >&2 + + ${builtins.concatStringsSep "\n" mkNvramVariables} + ''; + }; +} From ee53e5785c437aa2e836c6ce3b9fbf3936bf511e Mon Sep 17 00:00:00 2001 From: Sam <30577766+Samasaur1@users.noreply.github.com> Date: Tue, 27 Feb 2024 17:22:41 -0800 Subject: [PATCH 2/2] `system.startup.chime`: init --- modules/module-list.nix | 1 + modules/system/startup.nix | 31 +++++++++++++++++++++++++++++++ 2 files changed, 32 insertions(+) create mode 100644 modules/system/startup.nix diff --git a/modules/module-list.nix b/modules/module-list.nix index 66440a1ae..b9959c0cb 100644 --- a/modules/module-list.nix +++ b/modules/module-list.nix @@ -38,6 +38,7 @@ ./system/nvram.nix ./system/patches.nix ./system/shells.nix + ./system/startup.nix ./system/version.nix ./time ./networking diff --git a/modules/system/startup.nix b/modules/system/startup.nix new file mode 100644 index 000000000..ecbef4606 --- /dev/null +++ b/modules/system/startup.nix @@ -0,0 +1,31 @@ +{ config, lib, pkgs, ... }: + +let + cfg = config.system.startup; +in + +{ + meta.maintainers = [ + lib.maintainers.samasaur or "samasaur" + ]; + + options = { + system.startup.chime = lib.mkOption { + type = with lib.types; nullOr bool; + default = null; + example = false; + description = lib.mdDoc '' + Whether to enable the startup chime. + + By default, this option does not affect your system configuration in any way. + However, this means that after it has been set once, unsetting it will not + return to the old behavior. It will allow the setting to be controlled in + System Settings, though. + ''; + }; + }; + + config = { + system.nvram.variables."StartupMute" = lib.mkIf (cfg.chime != null) (if cfg.chime then "%00" else "%01"); + }; +}