Fix time-zone combinator
Most software that wants to know the timezone reads the symlink in `/etc/localtime`. A previous update broke this assumption when attempting to fix the combinator to work on non-NixOS systems. This change should fix the time-zone combinator in both NixOS and non-NixOS systems.
This commit is contained in:
parent
700189112f
commit
45c2b47d71
3 changed files with 51 additions and 1 deletions
|
|
@ -2,6 +2,7 @@ image: nixos/25.05
|
|||
environment:
|
||||
NIX_CONFIG: "experimental-features = nix-command flakes"
|
||||
tasks:
|
||||
- setup: "sudo ln -s /etc/zoneinfo/EST /etc/localtime"
|
||||
- test-jail-nix: "cd jail.nix/tests && nix run .#runTests"
|
||||
- check-format: "cd jail.nix/tests && nix run .#checkFmt"
|
||||
- build-website: "cd jail.nix/website && nix build -L .#default"
|
||||
|
|
|
|||
|
|
@ -860,7 +860,12 @@ rec {
|
|||
doc = ''
|
||||
Exposes your timezone.
|
||||
'';
|
||||
__functor = _: include-once "time-zone" (runtime-deep-ro-bind "/etc/localtime");
|
||||
__functor =
|
||||
_:
|
||||
include-once "time-zone" (compose [
|
||||
(unsafe-add-raw-args "--ro-bind \"$(realpath /etc/localtime)\" \"$(readlink /etc/localtime)\"")
|
||||
(unsafe-add-raw-args "--symlink \"$(readlink /etc/localtime)\" /etc/localtime")
|
||||
]);
|
||||
};
|
||||
|
||||
network = {
|
||||
|
|
|
|||
|
|
@ -194,3 +194,47 @@ spec = parallel $ inTestM $ do
|
|||
])
|
||||
|]
|
||||
`shouldOutput` "some-value"
|
||||
|
||||
describe "time-zone" $ do
|
||||
it "forwards timezones on nixos systems" $ do
|
||||
[i|
|
||||
let
|
||||
tz = "EST";
|
||||
fakeEtc = pkgs.runCommand "fake-etc" {} ''
|
||||
mkdir -p $out/etc
|
||||
ln -s ${pkgs.tzdata}/share/zoneinfo $out/etc/zoneinfo
|
||||
'';
|
||||
withFakeTimeZoneOnNixos = program:
|
||||
jail program.name program (c: [
|
||||
# This is a bit convoluted, but this recreates the symlink chain that is present on nixos systems
|
||||
(c.add-pkg-deps [ fakeEtc ])
|
||||
(c.unsafe-add-raw-args "--symlink ${fakeEtc}/etc /etc/static")
|
||||
(c.unsafe-add-raw-args "--symlink /etc/static/zoneinfo /etc/zoneinfo")
|
||||
(c.unsafe-add-raw-args "--symlink /etc/zoneinfo/${tz} /etc/localtime")
|
||||
]);
|
||||
in
|
||||
withFakeTimeZoneOnNixos (
|
||||
jail "print-time-zone" (sh "date '+%Z'") (c: [
|
||||
c.time-zone
|
||||
])
|
||||
)
|
||||
|]
|
||||
`shouldOutput` "EST\n"
|
||||
|
||||
it "forwards timezones on non-nixos systems" $ do
|
||||
[i|
|
||||
let
|
||||
tz = "EST";
|
||||
withFakeTimeZoneOnNixos = program:
|
||||
jail program.name program (c: [
|
||||
(c.unsafe-add-raw-args "--ro-bind ${pkgs.tzdata}/share/zoneinfo /etc/zoneinfo")
|
||||
(c.unsafe-add-raw-args "--symlink /etc/zoneinfo/${tz} /etc/localtime")
|
||||
]);
|
||||
in
|
||||
withFakeTimeZoneOnNixos (
|
||||
jail "print-time-zone" (sh "date '+%Z'") (c: [
|
||||
c.time-zone
|
||||
])
|
||||
)
|
||||
|]
|
||||
`shouldOutput` "EST\n"
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue