Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

clight: init #64309

Merged
merged 5 commits into from
Aug 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ let
timezone = types.nullOr (types.addCheck types.str nospace)
// { description = "null or string without spaces"; };

lcfg = config.location;

in

{
Expand Down Expand Up @@ -37,12 +39,45 @@ in
};

};

location = {

latitude = mkOption {
type = types.float;
description = ''
Your current latitude, between
<literal>-90.0</literal> and <literal>90.0</literal>. Must be provided
along with longitude.
'';
};

longitude = mkOption {
type = types.float;
description = ''
Your current longitude, between
between <literal>-180.0</literal> and <literal>180.0</literal>. 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
<literal>manual</literal> 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;

Expand Down
3 changes: 2 additions & 1 deletion nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -816,6 +816,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
Expand Down
14 changes: 14 additions & 0 deletions nixos/modules/rename.nix
Original file line number Diff line number Diff line change
Expand Up @@ -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" ]
Expand Down
115 changes: 115 additions & 0 deletions nixos/modules/services/x11/clight.nix
Original file line number Diff line number Diff line change
@@ -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
<literal>1000</literal> and <literal>25000</literal> K.
'';
};
night = mkOption {
type = types.int;
default = 3700;
description = ''
Colour temperature to use at night, between
<literal>1000</literal> and <literal>25000</literal> 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
<link xlink:href="https://github.com/FedeDP/Clight/blob/master/Extra/clight.conf"/> 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;
eadwu marked this conversation as resolved.
Show resolved Hide resolved
});

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}
'';
};
};
};
}
58 changes: 8 additions & 50 deletions nixos/modules/services/x11/redshift.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ with lib;
let

cfg = config.services.redshift;
lcfg = config.location;

in {

Expand All @@ -18,35 +19,6 @@ in {
'';
};

latitude = mkOption {
type = types.nullOr types.str;
default = null;
description = ''
Your current latitude, between
<literal>-90.0</literal> and <literal>90.0</literal>. Must be provided
along with longitude.
'';
};

longitude = mkOption {
eadwu marked this conversation as resolved.
Show resolved Hide resolved
type = types.nullOr types.str;
default = null;
description = ''
Your current longitude, between
between <literal>-180.0</literal> and <literal>180.0</literal>. 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
<literal>manual</literal> you must also provide latitude/longitude.
'';
};

temperature = {
day = mkOption {
type = types.int;
Expand Down Expand Up @@ -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;
eadwu marked this conversation as resolved.
Show resolved Hide resolved
in
{
description = "Redshift colour temperature adjuster";
Expand Down
75 changes: 75 additions & 0 deletions pkgs/applications/misc/clight/clightd.nix
Original file line number Diff line number Diff line change
@@ -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
];
};
}
Loading