Skip to content

Commit

Permalink
Merge pull request #892 from Samasaur1/startup-chime
Browse files Browse the repository at this point in the history
`system.startup.chime`: init
  • Loading branch information
Enzime committed Mar 2, 2024
2 parents 70d162d + ee53e57 commit 8a15cb3
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 0 deletions.
2 changes: 2 additions & 0 deletions modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,10 @@
./system/etc.nix
./system/keyboard.nix
./system/launchd.nix
./system/nvram.nix
./system/patches.nix
./system/shells.nix
./system/startup.nix
./system/version.nix
./time
./networking
Expand Down
1 change: 1 addition & 0 deletions modules/system/activation-scripts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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}
Expand Down
40 changes: 40 additions & 0 deletions modules/system/nvram.nix
Original file line number Diff line number Diff line change
@@ -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}
'';
};
}
31 changes: 31 additions & 0 deletions modules/system/startup.nix
Original file line number Diff line number Diff line change
@@ -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");
};
}

0 comments on commit 8a15cb3

Please sign in to comment.