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

RFE(nixos): Add generic target for internet accessibility #70960

Closed
danbst opened this issue Oct 11, 2019 · 9 comments
Closed

RFE(nixos): Add generic target for internet accessibility #70960

danbst opened this issue Oct 11, 2019 · 9 comments
Labels
0.kind: enhancement Add something new 0.kind: question Requests for a specific question to be answered 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS

Comments

@danbst
Copy link
Contributor

danbst commented Oct 11, 2019

I have a laptop, which connects to WiFi-router. The connection takes some time (up to 30s). I also have a service which depends on internet access (backup). On laptop lid-close/open, when backup timer fires during latop sleep, I have backup process started, but it fails immediately because internet is not yet accessible.

Would be great to have a systemd target (like network-online.target) that can be used in wants = [ "internet-accessible.target" ];, to simplify service definition. This target is non-trivial to implement correctly.

Or, if this is too specialized, what is a better solution? Keep restarting backup process until succeeded?

@danbst danbst added 0.kind: enhancement Add something new 0.kind: question Requests for a specific question to be answered 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS labels Oct 11, 2019
@doronbehar
Copy link
Contributor

It seems there is a network-online.target:

$ systemctl cat network-online.target
# /nix/store/y7lzgdv8qxmhca6nvdr4j1vrvx9vxxa3-systemd-243/example/systemd/system/network-online.target
#  SPDX-License-Identifier: LGPL-2.1+
#
#  This file is part of systemd.
#
#  systemd is free software; you can redistribute it and/or modify it
#  under the terms of the GNU Lesser General Public License as published by
#  the Free Software Foundation; either version 2.1 of the License, or
#  (at your option) any later version.

[Unit]
Description=Network is Online
Documentation=man:systemd.special(7)
Documentation=https://www.freedesktop.org/wiki/Software/systemd/NetworkTarget
After=network.target

# /nix/store/j24s99wahlrx5s4g8l5mm5ikf37wa1bh-system-units/network-online.target.d/overrides.conf
[Unit]

Did you try using it?

There's also the networking.localCommands option: https://nixos.org/nixos/options.html#network+local+commands

@flokli
Copy link
Contributor

flokli commented Oct 14, 2019

Yes, network-online.target would be the right target for that.

@flokli flokli closed this as completed Oct 16, 2019
@danbst
Copy link
Contributor Author

danbst commented Oct 29, 2019

@flokli no, network-online.target isn't running on laptop "resume". It runs only during boot. Though I don't know, maybe this is a bug it shouldn't behave like that.

@danbst danbst reopened this Oct 29, 2019
@doronbehar
Copy link
Contributor

doronbehar commented Oct 29, 2019 via email

@danbst
Copy link
Contributor Author

danbst commented Oct 29, 2019

@doronbehar I don't understand you.

So the situation is like this. During startup systemd reaches network-online.target, but at this point internet may not be accessible. For example, I have NetworkManager+Gnome Shell, and I have to type in login-password to get access to keyring, which has password for my WiFi. This all happens after multi-user.target, so it happens after network-online.target

After laptop sleep-resume, WiFi needs some time (up to 15-20 sec) to actually reconnect to my router, so network-online.target should have better internet checks than requires = [ "resume.target" ];.

It may be that network-online.target works best with networkd, and doesn't work with NetworkManager. I can change this issue name if that is the case.

@doronbehar
Copy link
Contributor

Well then this is not an issue with Systemd but with your specific network manager. Different networking managers will require different workarounds to make such a systemd target. I once had implemented a script that really monitors my network but for connman.

My opinion in this matter, is that this is not a NixOS specific issue, but a general Linux "we never agree on anything" type of issue. NetworkManager sure has an API you should be able to abuse and craft a script that will suit your needs.

@flokli
Copy link
Contributor

flokli commented Oct 29, 2019

I agree - I don't see this as a NixOS-specific issue. Encouraging a discussion upstream might be a way to go to, but it's hard to do right.

How do you define "being online"? Is it the existence of an IPv4 (and IPv6?) default route? What about Captive Portals? Enterprise Networks requiring proxies? What should happen if that state changes during script execution?

I'd recommend making your script tolerant to non-available network, and make it retry gracefully (or let it fail, but let systemd take care of retrying). Your script might know best which endpoints it tries to reach, and whether the connection succeeded or not.

@danbst
Copy link
Contributor Author

danbst commented Oct 29, 2019

If the consesus is that such a generic systemd target is hard-to-impossible to implement, then I agree, issue should be closed (workarounds may be specified in nixos.wiki page). Maybe let's hear more opinions, and close RFE if noone objects in, say, 6 months?

How do you define "being online"?

ping w3.org should not fail: DNS works and www is reachable.

@danbst
Copy link
Contributor Author

danbst commented Mar 21, 2020

duplicate of #35567

@danbst danbst closed this as completed Mar 21, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
0.kind: enhancement Add something new 0.kind: question Requests for a specific question to be answered 6.topic: nixos Issues or PRs affecting NixOS modules, or package usability issues specific to NixOS
Projects
None yet
Development

No branches or pull requests

3 participants