summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLinnnus <[email protected]>2023-10-01 22:02:55 +0200
committerLinnnus <[email protected]>2023-10-01 22:02:55 +0200
commit33fe1f534fff335c19d510b21cbbc602fc704684 (patch)
tree98f11202e517ff8f0d44ce21135e63b218b68cc1
parent6d22256a85df7228a356a802dbc513c8abeeb2b7 (diff)
Move hosts/ahmed/disable-screen.nix into a proper module
-rw-r--r--hosts/ahmed/configuration.nix10
-rw-r--r--hosts/ahmed/disable-screen.nix51
-rw-r--r--modules/nixos/default.nix2
-rw-r--r--modules/nixos/disable-screen/default.nix64
4 files changed, 75 insertions, 52 deletions
diff --git a/hosts/ahmed/configuration.nix b/hosts/ahmed/configuration.nix
index d92c639..402c3ab 100644
--- a/hosts/ahmed/configuration.nix
+++ b/hosts/ahmed/configuration.nix
@@ -8,7 +8,6 @@
[
./hardware-configuration.nix
./ssh.nix
- ./disable-screen.nix
./linus.onl.nix
./notifications.linus.onl.nix
./graphics.nix
@@ -84,6 +83,15 @@
# Use as main driver temporarily.
# my.modules.graphics.enable = true;
+ disable-screen = {
+ enable = true;
+ # The path to the device.
+ device-path = "/sys/class/backlight/intel_backlight";
+
+ # The systemd device unit which corresponds to `device-path`.
+ device-unit = "sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\\x2deDP\\x2d1-intel_backlight.device";
+ };
+
# This value determines the NixOS release from which the default
# settings for stateful data, like file locations and database versions
# on your system were taken. It's perfectly fine and recommended to leave
diff --git a/hosts/ahmed/disable-screen.nix b/hosts/ahmed/disable-screen.nix
deleted file mode 100644
index dd5eb22..0000000
--- a/hosts/ahmed/disable-screen.nix
+++ /dev/null
@@ -1,51 +0,0 @@
-# This file defines some configuration options which disable the screen. This
-# is only relevant because this host is an old laptop running as a server.
-
-{ pkgs, config, lib, ... }:
-
-let
- # The path to the device.
- device-path = "/sys/class/backlight/intel_backlight";
-
- # The systemd device unit which corresponds to `device-path`.
- device-unit = "sys-devices-pci0000:00-0000:00:02.0-drm-card0-card0\\x2deDP\\x2d1-intel_backlight.device";
-in
-{
- # Disable sleep on lid close.
- services.logind =
- let
- lidSwitchAction = "ignore";
- in
- {
- lidSwitchExternalPower = lidSwitchAction;
- lidSwitchDocked = lidSwitchAction;
- lidSwitch = lidSwitchAction;
- };
-
- # Don't store screen brightness between boots. We always want to turn off the
- # screen.
- #
- # See: https://wiki.archlinux.org/title/backlight#Save_and_restore_functionality
- # See: https://github.com/NixOS/nixpkgs/blob/990398921f677615c0732d704857484b84c6c888/nixos/modules/system/boot/systemd.nix#L97-L101
- systemd.suppressedSystemUnits = [ "[email protected]" ];
-
- # FIXME: Figure out how to enable screen when on-device debugging is necessary.
- # Create a new service which turns off the display on boot.
- #
- # See: https://nixos.wiki/wiki/Backlight#.2Fsys.2Fclass.2Fbacklight.2F...
- # See: https://superuser.com/questions/851846/how-to-write-a-systemd-service-that-depends-on-a-device-being-present
- systemd.services.disable-screen =
- {
- requires = [ device-unit ];
- after = [ device-unit ];
- wantedBy = [ device-unit ];
-
- serviceConfig.Type = "oneshot";
- script = ''
- tee ${device-path}/brightness <<<0
- '';
- };
-
- warnings = lib.optional config.my.modules.graphics.enable
- "You have enabled a graphical environment but the screen is still being disabled";
-}
diff --git a/modules/nixos/default.nix b/modules/nixos/default.nix
index 9ad08e5..daea05f 100644
--- a/modules/nixos/default.nix
+++ b/modules/nixos/default.nix
@@ -7,4 +7,6 @@
## Other miscellaneous configuration bits. These may be useful to other you.
cloudflare-proxy = import ./cloudflare-proxy;
+
+ disable-screen = import ./disable-screen;
}
diff --git a/modules/nixos/disable-screen/default.nix b/modules/nixos/disable-screen/default.nix
new file mode 100644
index 0000000..b70d80d
--- /dev/null
+++ b/modules/nixos/disable-screen/default.nix
@@ -0,0 +1,64 @@
+# This file defines some configuration options which disable the screen. This
+# is only relevant because this host is an old laptop running as a server.
+
+{ lib, config, ... }:
+
+let
+ inherit (lib) mkEnableOption mkOption types;
+
+ cfg = config.disable-screen;
+in
+{
+ options.disable-screen = {
+ enable = mkEnableOption "disable screen";
+
+ device-path = mkOption {
+ description = "Path to the device in the `/sys` file system.";
+ type = types.str;
+ example = "/sys/class/backlight/intel_backlight";
+ };
+
+ device-unit = mkOption {
+ description = "The systemd device unit that corresponds to the device speciefied in `device-path`.";
+ type = types.str;
+ example = "sys-devices-pci...-intel_backligt.device";
+ };
+ };
+
+ config = {
+ # Disable sleep on lid close.
+ services.logind =
+ let
+ lidSwitchAction = "ignore";
+ in
+ {
+ lidSwitchExternalPower = lidSwitchAction;
+ lidSwitchDocked = lidSwitchAction;
+ lidSwitch = lidSwitchAction;
+ };
+
+ # Don't store screen brightness between boots. We always want to turn off the
+ # screen.
+ #
+ # See: https://wiki.archlinux.org/title/backlight#Save_and_restore_functionality
+ # See: https://github.com/NixOS/nixpkgs/blob/990398921f677615c0732d704857484b84c6c888/nixos/modules/system/boot/systemd.nix#L97-L101
+ systemd.suppressedSystemUnits = [ "[email protected]" ];
+
+ # FIXME: Figure out how to enable screen when on-device debugging is necessary.
+ # Create a new service which turns off the display on boot.
+ #
+ # See: https://nixos.wiki/wiki/Backlight#.2Fsys.2Fclass.2Fbacklight.2F...
+ # See: https://superuser.com/questions/851846/how-to-write-a-systemd-service-that-depends-on-a-device-being-present
+ systemd.services.disable-screen =
+ {
+ requires = [ cfg.device-unit ];
+ after = [ cfg.device-unit ];
+ wantedBy = [ cfg.device-unit ];
+
+ serviceConfig.Type = "oneshot";
+ script = ''
+ tee ${cfg.device-path}/brightness <<<0
+ '';
+ };
+ };
+}