diff --git a/nixos/modules/config/timezone.nix b/nixos/modules/config/locale.nix
similarity index 62%
rename from nixos/modules/config/timezone.nix
rename to nixos/modules/config/locale.nix
index b15948f6e2e..6f056588187 100644
--- a/nixos/modules/config/timezone.nix
+++ b/nixos/modules/config/locale.nix
@@ -9,6 +9,8 @@ let
timezone = types.nullOr (types.addCheck types.str nospace)
// { description = "null or string without spaces"; };
+ lcfg = config.location;
+
in
{
@@ -37,12 +39,45 @@ in
};
};
+
+ location = {
+
+ latitude = mkOption {
+ type = types.float;
+ description = ''
+ Your current latitude, between
+ -90.0 and 90.0. Must be provided
+ along with longitude.
+ '';
+ };
+
+ longitude = mkOption {
+ type = types.float;
+ description = ''
+ Your current longitude, between
+ between -180.0 and 180.0. Must be
+ provided along with latitude.
+ '';
+ };
+
+ provider = mkOption {
+ type = types.enum [ "manual" "geoclue2" ];
+ default = "manual";
+ description = ''
+ The location provider to use for determining your location. If set to
+ manual you must also provide latitude/longitude.
+ '';
+ };
+
+ };
};
config = {
environment.sessionVariables.TZDIR = "/etc/zoneinfo";
+ services.geoclue2.enable = mkIf (lcfg.provider == "geoclue2") true;
+
# This way services are restarted when tzdata changes.
systemd.globalEnvironment.TZDIR = tzdir;
diff --git a/nixos/modules/module-list.nix b/nixos/modules/module-list.nix
index c775345ba4c..3d4c41bbbdb 100644
--- a/nixos/modules/module-list.nix
+++ b/nixos/modules/module-list.nix
@@ -20,6 +20,7 @@
./config/iproute2.nix
./config/krb5/default.nix
./config/ldap.nix
+ ./config/locale.nix
./config/malloc.nix
./config/networking.nix
./config/no-x-libs.nix
@@ -33,7 +34,6 @@
./config/system-environment.nix
./config/system-path.nix
./config/terminfo.nix
- ./config/timezone.nix
./config/unix-odbc-drivers.nix
./config/users-groups.nix
./config/vpnc.nix
@@ -820,6 +820,7 @@
./services/web-servers/varnish/default.nix
./services/web-servers/zope2.nix
./services/x11/extra-layouts.nix
+ ./services/x11/clight.nix
./services/x11/colord.nix
./services/x11/compton.nix
./services/x11/unclutter.nix
diff --git a/nixos/modules/rename.nix b/nixos/modules/rename.nix
index 4ae64222274..6228c95ae91 100644
--- a/nixos/modules/rename.nix
+++ b/nixos/modules/rename.nix
@@ -257,6 +257,20 @@ with lib;
(mkRenamedOptionModule [ "networking" "extraResolvconfConf" ] [ "networking" "resolvconf" "extraConfig" ])
(mkRenamedOptionModule [ "networking" "resolvconfOptions" ] [ "networking" "resolvconf" "extraOptions" ])
+ # Redshift
+ (mkChangedOptionModule [ "services" "redshift" "latitude" ] [ "location" "latitude" ]
+ (config:
+ let value = getAttrFromPath [ "services" "redshift" "latitude" ] config;
+ in if value == null then
+ throw "services.redshift.latitude is set to null, you can remove this"
+ else builtins.fromJSON value))
+ (mkChangedOptionModule [ "services" "redshift" "longitude" ] [ "location" "longitude" ]
+ (config:
+ let value = getAttrFromPath [ "services" "redshift" "longitude" ] config;
+ in if value == null then
+ throw "services.redshift.longitude is set to null, you can remove this"
+ else builtins.fromJSON value))
+
] ++ (flip map [ "blackboxExporter" "collectdExporter" "fritzboxExporter"
"jsonExporter" "minioExporter" "nginxExporter" "nodeExporter"
"snmpExporter" "unifiExporter" "varnishExporter" ]
diff --git a/nixos/modules/services/x11/clight.nix b/nixos/modules/services/x11/clight.nix
new file mode 100644
index 00000000000..6ec395bb05e
--- /dev/null
+++ b/nixos/modules/services/x11/clight.nix
@@ -0,0 +1,115 @@
+{ config, pkgs, lib, ... }:
+
+with lib;
+
+let
+ cfg = config.services.clight;
+
+ toConf = v:
+ if builtins.isFloat v then toString v
+ else if isInt v then toString v
+ else if isBool v then boolToString v
+ else if isString v then ''"${escape [''"''] v}"''
+ else if isList v then "[ " + concatMapStringsSep ", " toConf v + " ]"
+ else abort "clight.toConf: unexpected type (v = ${v})";
+
+ clightConf = pkgs.writeText "clight.conf"
+ (concatStringsSep "\n" (mapAttrsToList
+ (name: value: "${toString name} = ${toConf value};")
+ (filterAttrs
+ (_: value: value != null)
+ cfg.settings)));
+in {
+ options.services.clight = {
+ enable = mkOption {
+ type = types.bool;
+ default = false;
+ description = ''
+ Whether to enable clight or not.
+ '';
+ };
+
+ temperature = {
+ day = mkOption {
+ type = types.int;
+ default = 5500;
+ description = ''
+ Colour temperature to use during the day, between
+ 1000 and 25000 K.
+ '';
+ };
+ night = mkOption {
+ type = types.int;
+ default = 3700;
+ description = ''
+ Colour temperature to use at night, between
+ 1000 and 25000 K.
+ '';
+ };
+ };
+
+ settings = let
+ validConfigTypes = with types; either int (either str (either bool float));
+ in mkOption {
+ type = with types; attrsOf (nullOr (either validConfigTypes (listOf validConfigTypes)));
+ default = {};
+ example = { captures = 20; gamma_long_transition = true; ac_capture_timeouts = [ 120 300 60 ]; };
+ description = ''
+ Additional configuration to extend clight.conf. See
+ for a
+ sample configuration file.
+ '';
+ };
+ };
+
+ config = mkIf cfg.enable {
+ boot.kernelModules = [ "i2c_dev" ];
+ environment.systemPackages = with pkgs; [ clight clightd ];
+ services.dbus.packages = with pkgs; [ clight clightd ];
+ services.upower.enable = true;
+
+ services.clight.settings = {
+ gamma_temp = with cfg.temperature; mkDefault [ day night ];
+ } // (optionalAttrs (config.location.provider == "manual") {
+ latitude = mkDefault config.location.latitude;
+ longitude = mkDefault config.location.longitude;
+ });
+
+ services.geoclue2.appConfig."clightc" = {
+ isAllowed = true;
+ isSystem = true;
+ };
+
+ systemd.services.clightd = {
+ requires = [ "polkit.service" ];
+ wantedBy = [ "multi-user.target" ];
+
+ description = "Bus service to manage various screen related properties (gamma, dpms, backlight)";
+ serviceConfig = {
+ Type = "dbus";
+ BusName = "org.clightd.clightd";
+ Restart = "on-failure";
+ RestartSec = 5;
+ ExecStart = ''
+ ${pkgs.clightd}/bin/clightd
+ '';
+ };
+ };
+
+ systemd.user.services.clight = {
+ after = [ "upower.service" "clightd.service" ];
+ wants = [ "upower.service" "clightd.service" ];
+ partOf = [ "graphical-session.target" ];
+ wantedBy = [ "graphical-session.target" ];
+
+ description = "C daemon to adjust screen brightness to match ambient brightness, as computed capturing frames from webcam";
+ serviceConfig = {
+ Restart = "on-failure";
+ RestartSec = 5;
+ ExecStart = ''
+ ${pkgs.clight}/bin/clight --conf-file ${clightConf}
+ '';
+ };
+ };
+ };
+}
diff --git a/nixos/modules/services/x11/redshift.nix b/nixos/modules/services/x11/redshift.nix
index 4345a334808..55f8f75021b 100644
--- a/nixos/modules/services/x11/redshift.nix
+++ b/nixos/modules/services/x11/redshift.nix
@@ -5,6 +5,7 @@ with lib;
let
cfg = config.services.redshift;
+ lcfg = config.location;
in {
@@ -18,35 +19,6 @@ in {
'';
};
- latitude = mkOption {
- type = types.nullOr types.str;
- default = null;
- description = ''
- Your current latitude, between
- -90.0 and 90.0. Must be provided
- along with longitude.
- '';
- };
-
- longitude = mkOption {
- type = types.nullOr types.str;
- default = null;
- description = ''
- Your current longitude, between
- between -180.0 and 180.0. Must be
- provided along with latitude.
- '';
- };
-
- provider = mkOption {
- type = types.enum [ "manual" "geoclue2" ];
- default = "manual";
- description = ''
- The location provider to use for determining your location. If set to
- manual you must also provide latitude/longitude.
- '';
- };
-
temperature = {
day = mkOption {
type = types.int;
@@ -106,33 +78,19 @@ in {
};
config = mkIf cfg.enable {
- assertions = [
- {
- assertion =
- if cfg.provider == "manual"
- then (cfg.latitude != null && cfg.longitude != null)
- else (cfg.latitude == null && cfg.longitude == null);
- message = "Latitude and longitude must be provided together, and with provider set to null.";
- }
- ];
-
# needed so that .desktop files are installed, which geoclue cares about
environment.systemPackages = [ cfg.package ];
- services.geoclue2 = mkIf (cfg.provider == "geoclue2") {
- enable = true;
- appConfig."redshift" = {
- isAllowed = true;
- isSystem = true;
- };
+ services.geoclue2.appConfig."redshift" = {
+ isAllowed = true;
+ isSystem = true;
};
- systemd.user.services.redshift =
+ systemd.user.services.redshift =
let
- providerString =
- if cfg.provider == "manual"
- then "${cfg.latitude}:${cfg.longitude}"
- else cfg.provider;
+ providerString = if lcfg.provider == "manual"
+ then "${toString lcfg.latitude}:${toString lcfg.longitude}"
+ else lcfg.provider;
in
{
description = "Redshift colour temperature adjuster";
diff --git a/pkgs/applications/misc/clight/clightd.nix b/pkgs/applications/misc/clight/clightd.nix
new file mode 100644
index 00000000000..43ff1d73f78
--- /dev/null
+++ b/pkgs/applications/misc/clight/clightd.nix
@@ -0,0 +1,75 @@
+{ lib, stdenv, fetchFromGitHub
+, dbus, cmake, pkgconfig
+, glib, udev, polkit, libmodule
+, pcre, libXdmcp, utillinux, libpthreadstubs
+, enableDdc ? true, ddcutil
+, enableDpms ? true, libXext
+, enableGamma ? true, libXrandr
+, enableScreen ? true }:
+
+stdenv.mkDerivation rec {
+ pname = "clightd";
+ version = "3.4";
+
+ src = fetchFromGitHub {
+ owner = "FedeDP";
+ repo = "Clightd";
+ rev = version;
+ sha256 = "0g6kawizwfhvigkwm7rbfq6rg872xn8igy8n355w4d7mmcxk0jf8";
+ };
+
+ # dbus-1.pc has datadir=/etc
+ SYSTEM_BUS_DIR = "${placeholder "out"}/share/dbus-1/system-services";
+ # systemd.pc has prefix=${systemd.out}
+ MODULE_LOAD_DIR = "${placeholder "out"}/lib/modules-load.d";
+ # polkit-gobject-1.pc has prefix=${polkit.out}
+ POLKIT_ACTION_DIR = "${placeholder "out"}/share/polkit-1/actions";
+
+ postPatch = ''
+ sed -i "s@/etc@$out\0@" CMakeLists.txt
+ sed -i "s@pkg_get_variable(SYSTEM_BUS_DIR.*@set(SYSTEM_BUS_DIR $SYSTEM_BUS_DIR)@" CMakeLists.txt
+ sed -i "s@pkg_get_variable(MODULE_LOAD_DIR.*@set(MODULE_LOAD_DIR $MODULE_LOAD_DIR)@" CMakeLists.txt
+ sed -i "s@pkg_get_variable(POLKIT_ACTION_DIR.*@set(POLKIT_ACTION_DIR $POLKIT_ACTION_DIR)@" CMakeLists.txt
+ '';
+
+ cmakeFlags = with lib;
+ optional enableDdc "-DENABLE_DDC=1"
+ ++ optional enableDpms "-DENABLE_DPMS=1"
+ ++ optional enableGamma "-DENABLE_GAMMA=1"
+ ++ optional enableScreen "-DENABLE_SCREEN=1";
+
+ nativeBuildInputs = [
+ dbus
+ cmake
+ pkgconfig
+ ];
+
+ buildInputs = with lib; [
+ glib
+ udev
+ polkit
+ libmodule
+
+ pcre
+ libXdmcp
+ utillinux
+ libpthreadstubs
+ ] ++ optional enableDdc ddcutil
+ ++ optional enableDpms libXext
+ ++ optional enableGamma libXrandr;
+
+ postInstall = ''
+ mkdir -p $out/bin
+ ln -svT $out/lib/clightd/clightd $out/bin/clightd
+ '';
+
+ meta = with lib; {
+ description = "Linux bus interface that changes screen brightness/temperature";
+ homepage = https://github.com/FedeDP/Clightd;
+ platforms = platforms.linux;
+ license = licenses.gpl3;
+ maintainers = with maintainers; [
+ eadwu
+ ];
+ };
+}
diff --git a/pkgs/applications/misc/clight/default.nix b/pkgs/applications/misc/clight/default.nix
new file mode 100644
index 00000000000..829fd4e1223
--- /dev/null
+++ b/pkgs/applications/misc/clight/default.nix
@@ -0,0 +1,57 @@
+{ lib, stdenv, fetchFromGitHub
+, dbus, cmake, pkgconfig, bash-completion
+, gsl, popt, clightd, systemd, libconfig
+, withGeoclue ? true, geoclue2
+, withUpower ? true, upower }:
+
+stdenv.mkDerivation rec {
+ pname = "clight";
+ version = "3.1";
+
+ src = fetchFromGitHub {
+ owner = "FedeDP";
+ repo = "Clight";
+ rev = version;
+ sha256 = "0rzcr1x9h4llnmklhgzs9r7xwhsrw1qkqvfffkp8fs90nycaqx81";
+ };
+
+ # bash-completion.pc completionsdir=${bash-completion.out}
+ COMPLETIONS_DIR = "${placeholder "out"}/share/bash-completions/completions";
+ # dbus-1.pc has datadir=/etc
+ SESSION_BUS_DIR = "${placeholder "out"}/share/dbus-1/services";
+
+ postPatch = ''
+ sed -i "s@/usr@$out@" CMakeLists.txt
+ sed -i "s@/etc@$out\0@" CMakeLists.txt
+ sed -i "s@pkg_get_variable(COMPLETIONS_DIR.*@set(COMPLETIONS_DIR $COMPLETIONS_DIR)@" CMakeLists.txt
+ sed -i "s@pkg_get_variable(SESSION_BUS_DIR.*@set(SESSION_BUS_DIR $SESSION_BUS_DIR)@" CMakeLists.txt
+ '';
+
+ nativeBuildInputs = [
+ dbus
+ cmake
+ pkgconfig
+ bash-completion
+ ];
+
+ buildInputs = with lib; [
+ gsl
+ popt
+ upower
+ clightd
+ systemd
+ geoclue2
+ libconfig
+ ] ++ optional withGeoclue geoclue2
+ ++ optional withUpower upower;
+
+ meta = with lib; {
+ description = "A C daemon that turns your webcam into a light sensor";
+ homepage = https://github.com/FedeDP/Clight;
+ platforms = platforms.linux;
+ license = licenses.gpl3;
+ maintainers = with maintainers; [
+ eadwu
+ ];
+ };
+}
diff --git a/pkgs/development/libraries/libmodule/default.nix b/pkgs/development/libraries/libmodule/default.nix
new file mode 100644
index 00000000000..bcd20c3b407
--- /dev/null
+++ b/pkgs/development/libraries/libmodule/default.nix
@@ -0,0 +1,29 @@
+{ stdenv, fetchFromGitHub
+, cmake, pkgconfig }:
+
+stdenv.mkDerivation rec {
+ pname = "libmodule";
+ version = "4.2.0";
+
+ src = fetchFromGitHub {
+ owner = "FedeDP";
+ repo = "libmodule";
+ rev = version;
+ sha256 = "1qn54pysdm0q7v1gnisd43i5i4ylf8s8an77jk6jd8qimysv08mx";
+ };
+
+ nativeBuildInputs = [
+ cmake
+ pkgconfig
+ ];
+
+ meta = with stdenv.lib; {
+ description = "C simple and elegant implementation of an actor library";
+ homepage = https://github.com/FedeDP/libmodule;
+ platforms = platforms.linux;
+ license = licenses.mit;
+ maintainers = with maintainers; [
+ eadwu
+ ];
+ };
+}
diff --git a/pkgs/top-level/all-packages.nix b/pkgs/top-level/all-packages.nix
index 76a16cc5aa1..3e9e36311dc 100644
--- a/pkgs/top-level/all-packages.nix
+++ b/pkgs/top-level/all-packages.nix
@@ -12034,6 +12034,8 @@ in
libmodplug = callPackage ../development/libraries/libmodplug {};
+ libmodule = callPackage ../development/libraries/libmodule { };
+
libmpcdec = callPackage ../development/libraries/libmpcdec { };
libmp3splt = callPackage ../development/libraries/libmp3splt { };
@@ -17449,6 +17451,10 @@ in
cligh = python3Packages.callPackage ../development/tools/github/cligh {};
+ clight = callPackage ../applications/misc/clight { };
+
+ clightd = callPackage ../applications/misc/clight/clightd.nix { };
+
clipgrab = qt5.callPackage ../applications/video/clipgrab { };
clipmenu = callPackage ../applications/misc/clipmenu { };