Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add localtime package and nixos module
Simple daemon for keeping system timezone up-to-date via geoclue2. Sadly i3 status needs to be restarted for timezone changes. (cherry picked from commit d64ba1c) Signed-off-by: Domen Kožar <domen@dev.si>
- Loading branch information
1 parent
4f75e27
commit b7c8134
Showing
4 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
{ config, lib, pkgs, ... }: | ||
|
||
with lib; | ||
|
||
let | ||
cfg = config.services.localtime; | ||
in { | ||
options = { | ||
services.localtime = { | ||
enable = mkOption { | ||
default = false; | ||
description = '' | ||
Enable <literal>localtime</literal>, simple daemon for keeping the system | ||
timezone up-to-date based on the current location. It uses geoclue2 to | ||
determine the current location and systemd-timedated to actually set | ||
the timezone. | ||
''; | ||
}; | ||
}; | ||
}; | ||
|
||
config = mkIf cfg.enable { | ||
services.geoclue2.enable = true; | ||
|
||
security.polkit.extraConfig = '' | ||
polkit.addRule(function(action, subject) { | ||
if (action.id == "org.freedesktop.timedate1.set-timezone" | ||
&& subject.user == "localtimed") { | ||
return polkit.Result.YES; | ||
} | ||
}); | ||
''; | ||
|
||
users.users = [{ | ||
name = "localtimed"; | ||
description = "Taskserver user"; | ||
}]; | ||
|
||
systemd.services.localtime = { | ||
description = "localtime service"; | ||
wantedBy = [ "multi-user.target" ]; | ||
partOf = [ "geoclue.service "]; | ||
|
||
serviceConfig = { | ||
Restart = "on-failure"; | ||
# TODO: make it work with dbus | ||
#DynamicUser = true; | ||
Nice = 10; | ||
User = "localtimed"; | ||
PrivateTmp = "yes"; | ||
PrivateDevices = true; | ||
PrivateNetwork = "yes"; | ||
NoNewPrivileges = "yes"; | ||
ProtectSystem = "strict"; | ||
ProtectHome = true; | ||
ExecStart = "${pkgs.localtime}/bin/localtimed"; | ||
}; | ||
}; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
{ stdenv, go, systemd, polkit, fetchFromGitHub, m4 }: | ||
|
||
stdenv.mkDerivation { | ||
name = "localtime-2017-11-07"; | ||
|
||
src = fetchFromGitHub { | ||
owner = "Stebalien"; | ||
repo = "localtime"; | ||
rev = "2e7b4317c723406bd75b2a1d640219ab9f8090ce"; | ||
sha256 = "04fyna8p7q7skzx9fzmncd6gx7x5pwa9jh8a84hpljlvj0kldfs8"; | ||
}; | ||
|
||
buildInputs = [ go systemd polkit m4 ]; | ||
|
||
makeFlags = [ "PREFIX=$(out)" ]; | ||
|
||
meta = { | ||
description = "A daemon for keeping the system timezone up-to-date based on the current location"; | ||
homepage = https://github.com/Stebalien/localtime; | ||
platforms = stdenv.lib.platforms.linux; | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters