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

[RDY] networkmanager: enrich dispatcher PATH #39142

Merged
merged 1 commit into from Sep 2, 2018

Conversation

teto
Copy link
Member

@teto teto commented Apr 19, 2018

Motivation for this change

I needed to use some unavailable hooks.

Things done
  • Tested using sandboxing (nix.useSandbox on NixOS, or option build-use-sandbox in nix.conf on non-NixOS)
  • Built on platform(s)
    • NixOS
    • macOS
    • other Linux distributions
  • Tested via one or more NixOS test(s) if existing and applicable for the change (look inside nixos/tests)
  • Tested compilation of all pkgs that depend on this change using nix-shell -p nox --run "nox-review wip"
  • Tested execution of all binary files (usually in ./result/bin/)
  • Fits CONTRIBUTING.md.

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

copying path '/nix/store/21krp59jdnpsrsfsz9n2j9gsfpnmkldp-ppp-2.4.7' from 'https://cache.nixos.org'...
copying path '/nix/store/6bfx8hn1nf60alblrhlx2l5830s5akh1-spidermonkey-17.0.0-lib' from 'https://cache.nixos.org'...
copying path '/nix/store/v980g3k7af878018b8gzz2ag9ld4c7g1-openconnect-7.08' from 'https://cache.nixos.org'...
copying path '/nix/store/f3y26vvpjv00ha06jv2mzgz3mmdb6vqv-polkit-0.113' from 'https://cache.nixos.org'...
copying path '/nix/store/xq27y3drbw992axsgv9wnvswm9fqscqc-dhcp-4.3.6-P1' from 'https://cache.nixos.org'...
copying path '/nix/store/ylzj018n54j36lwywznp8g61sx7h6dmx-modem-manager-1.7.990' from 'https://cache.nixos.org'...
copying path '/nix/store/cvqf2xbi50y3k93hhddbiwhqj52bn13q-newt-0.52.20' from 'https://cache.nixos.org'...
copying path '/nix/store/gc291rc424d39fijqf2gfzfjj3a8dsn1-bluez-5.49' from 'https://cache.nixos.org'...
copying path '/nix/store/rx2lcyadfc387dv3vr1pnyj5zsqs3qqh-network-manager-1.10.6' from 'https://cache.nixos.org'...
/nix/store/rx2lcyadfc387dv3vr1pnyj5zsqs3qqh-network-manager-1.10.6

@teto teto changed the title networkmanager: exhaustive dispatchers enum [RDY] networkmanager: exhaustive dispatchers enum Apr 19, 2018
@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

copying path '/nix/store/dhqbvzjxs9867qgd798drgh88701i45n-libical-2.0.0' from 'https://cache.nixos.org'...
copying path '/nix/store/1bk9rmxlbq6ijdgm85v1rz03838db9m8-libmbim-1.16.0' from 'https://cache.nixos.org'...
copying path '/nix/store/zs5wvi0swwqi897wrmz87k7xdiddnvyn-stoken-v0.90' from 'https://cache.nixos.org'...
copying path '/nix/store/sagwrqi4dq6zyjb9v7pnjqj0nlph2jwn-vpnc-0.5.3-post-r550' from 'https://cache.nixos.org'...
copying path '/nix/store/smga586sis6f06jlzwa3flh6gfdzryg4-libqmi-1.20.0' from 'https://cache.nixos.org'...
copying path '/nix/store/pqd75laa0x4ykplyda1ys7w3lk044mpn-bluez-5.49' from 'https://cache.nixos.org'...
copying path '/nix/store/vlqhyjqslf0rgwrrjx62f9wfcb3707qj-openconnect-7.08' from 'https://cache.nixos.org'...
copying path '/nix/store/faq4wy0jcldh513l5vs50vkwyj643ljw-modem-manager-1.7.990' from 'https://cache.nixos.org'...
copying path '/nix/store/cbriipgs3h966v057iby6qmgapvwkvhk-network-manager-1.10.6' from 'https://cache.nixos.org'...
/nix/store/cbriipgs3h966v057iby6qmgapvwkvhk-network-manager-1.10.6

@teto
Copy link
Member Author

teto commented Apr 20, 2018

This is not necessarely related to my PR but might make me add a fix; it seems like on nixos-unstable, dispatched scripts are not run ?

Apr 20 16:48:24 client nm-dispatcher[544]: find-scripts: Cannot execute '/etc/NetworkManager/dispatcher.d/03userscript0001': not executable by owner.
Apr 20 16:48:24 client nm-dispatcher[544]: find-scripts: Cannot execute '/etc/NetworkManager/dispatcher.d/02overridedns': not owned by root.
Apr 20 16:48:24 client nm-dispatcher[544]: find-scripts: Cannot execute '/etc/NetworkManager/dispatcher.d/03userscript0002': not executable by owner.
Apr 20 17:06:57 client systemd[1]: Started Network Manager Script Dispatcher Service.
Apr 20 17:06:57 client nm-dispatcher[909]: find-scripts: Cannot execute '/etc/NetworkManager/dispatcher.d/03userscript0001': not executable by owner.
Apr 20 17:06:57 client nm-dispatcher[909]: find-scripts: Cannot execute '/etc/NetworkManager/dispatcher.d/02overridedns': not owned by root.
Apr 20 17:06:57 client nm-dispatcher[909]: find-scripts: Cannot execute '/etc/NetworkManager/dispatcher.d/03userscript0002': not executable by owner.
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: new request (0 scripts)
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: PATH=/no-such-path
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DAD_WAIT_TIME=0
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_TIME_OFFSET=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DOMAIN_NAME_SERVERS=192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_BROADCAST_ADDRESS=192.168.128.255
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_IP_ADDRESS=192.168.128.241
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_SUBNET_MASK=255.255.255.0
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DHCP_LEASE_TIME=3600
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DHCP_MESSAGE_TYPE=5
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_NEXT_SERVER=192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DHCP_REBINDING_TIME=3150
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_WPAD=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_SUBNET_MASK=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_EXPIRY=1524215217
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DHCP_SERVER_IDENTIFIER=192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_DHCP_RENEWAL_TIME=1800
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_HOST_NAME=client
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_MS_CLASSLESS_STATIC_ROUTES=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_NETWORK_NUMBER=192.168.128.0
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_BROADCAST_ADDRESS=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_ROUTERS=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_NTP_SERVERS=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_RFC3442_CLASSLESS_STATIC_ROUTES=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_STATIC_ROUTES=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_DOMAIN_NAME=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_ROUTERS=192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_HOST_NAME=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DHCP4_REQUESTED_DOMAIN_NAME_SERVERS=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP6_NUM_ROUTES=2
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP6_ROUTE_1=fe80::/64 :: 256
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP6_ROUTE_0=ff00::/8 :: 256
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP6_GATEWAY=::
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP6_NUM_ADDRESSES=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP6_ADDRESS_0=fe80::8e9b:4594:ead1:1648/64 ::
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP4_NUM_ROUTES=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP4_ROUTE_0=192.168.128.0/24 0.0.0.0 102
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP4_NAMESERVERS=192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP4_GATEWAY=192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP4_NUM_ADDRESSES=1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: IP4_ADDRESS_0=192.168.128.241/24 192.168.128.1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DEVICE_IP_IFACE=enp0s3
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: DEVICE_IFACE=enp0s3
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: CONNECTION_ID=Wired connection 1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: CONNECTION_UUID=0d27a662-b41f-37f7-a623-2c5c6164d2c0
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: environment: CONNECTION_DBUS_PATH=/org/freedesktop/NetworkManager/Settings/1
Apr 20 17:06:57 client nm-dispatcher[909]: req:1 'up' [enp0s3]: completed: no scripts
Apr 20 17:06:57 client NetworkManager[468]: <debug> [1524211617.5465] dispatcher: (9) succeeded but no scripts invoked



while the script is executable and owned by root

ls -l /etc/NetworkManager/dispatcher.d/03userscript0001                                                                                                                                                                                                            
lrwxrwxrwx 1 root root 56 Apr 20 16:48 /etc/NetworkManager/dispatcher.d/03userscript0001 -> /etc/static/NetworkManager/dispatcher.d/03userscript0001

In networkmanager module, scripts are dispatched via

etc.environment = ....
      ++ lib.imap1 (i: s: {
        inherit (s) source;
        target = "NetworkManager/dispatcher.d/${dispatcherTypesSubdirMap.${s.type}}03userscript${lib.fixedWidthNumber 4 i}";
      }) cfg.dispatcherScripts;

@teto
Copy link
Member Author

teto commented Apr 20, 2018

According to the manpage: NetworkManager will execute scripts in the /etc/NetworkManager/dispatcher.d directory or subdirectories in alphabetical order in response to network events. Each script should be a regular executable file owned by root. Furthermore, it must not be writable by group or other, and not setuid.. Seems like I have some setting making /etc/ 777 since I have a similar problem in #39189

@teto teto force-pushed the nm_dispatchers branch 2 times, most recently from edbd86d to 0635687 Compare April 26, 2018 09:57
@teto
Copy link
Member Author

teto commented Apr 26, 2018

I updated the patch to also enrich hooks PATH with coreutils !

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6/lib  /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6/libexec  /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6/bin  /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6/sbin
patching script interpreter paths in /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6
checking for references to /build in /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6...
moving /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6/sbin/* to /nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6/bin
shrinking RPATHs of ELF executables and libraries in /nix/store/12jziqi8k6frjkk11mqwnyih82pqaw8f-network-manager-1.10.6-dev
strip is /nix/store/j7d4mr0ikv974ig7yzhknpsq288js4bs-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/12jziqi8k6frjkk11mqwnyih82pqaw8f-network-manager-1.10.6-dev/lib
patching script interpreter paths in /nix/store/12jziqi8k6frjkk11mqwnyih82pqaw8f-network-manager-1.10.6-dev
checking for references to /build in /nix/store/12jziqi8k6frjkk11mqwnyih82pqaw8f-network-manager-1.10.6-dev...
/nix/store/6r4bc1vszsl3hykx8fj9y9ip2wbnkcbm-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/81pj22xg5sy7ymn9rkgd2yfd0g8yw9qv-network-manager-1.10.6

@teto
Copy link
Member Author

teto commented May 15, 2018

This seems to me like a pretty safe merge.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

these paths will be fetched (4.09 MiB download, 22.36 MiB unpacked):
  /nix/store/7hf8yjdmi21s96dhqvabx76pb64mf2pm-dhcp-4.3.6-P1
  /nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6
copying path '/nix/store/7hf8yjdmi21s96dhqvabx76pb64mf2pm-dhcp-4.3.6-P1' from 'https://cache.nixos.org'...
copying path '/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6' from 'https://cache.nixos.org'...
/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

@teto teto changed the title [RDY] networkmanager: exhaustive dispatchers enum [RDY] networkmanager: enrich dispatcher PATH May 16, 2018
@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/lib  /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/libexec  /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/bin  /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/sbin
patching script interpreter paths in /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6
checking for references to /build in /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6...
moving /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/sbin/* to /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/bin
shrinking RPATHs of ELF executables and libraries in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev
strip is /nix/store/jk6j4lh9v5mvjdbdc35sj0zffhhf6s56-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev/lib
patching script interpreter paths in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev
checking for references to /build in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev...
/nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

  /nix/store/ac968ffl4rq40jkrv6r5q8aa4mas1gw4-gtk-doc-1.28.drv
  /nix/store/83j497kq9blxh2ysfkl1ph5j3lclwqm6-polkit-0.113.drv
  /nix/store/hhz2in9c0i59k8cs0w10lbakw3wsiiyf-python3.6-pytest-3.5.0.drv
  /nix/store/glgyqh0j0divr2fh5qpk0ygm7xlkb0hm-python3.6-pycairo-1.15.4.drv
  /nix/store/lnc2a58vl9j0vqxnf5l6vs01x5w1f6r1-dhcp-4.3.6-P1.drv
  /nix/store/pb7922385jvvml9nqn6migsy632zh29z-python3.6-pygobject-3.26.1.drv
  /nix/store/r3i2p5y5yasfj82bx08cj9c669zp5kp1-modem-manager-1.7.990.drv
  /nix/store/jvwkisaimjzgz9hiayah02zws3k1wp32-network-manager-1.10.6.drv
waiting for locks or build slots...
/nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6

'';
};

type = mkOption {
type = types.enum (attrNames dispatcherTypesSubdirMap);
default = "basic";
description = ''
Dispatcher hook type. Only basic hooks are currently available.
Dispatcher hook type. Look up the hooks described at
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am confused. type is defined as enum, which supports only 3 types (removed comment suggests that 2 of them don't work):

  dispatcherTypesSubdirMap = {
    "basic" = "";
    "pre-up" = "pre-up.d/";
    "pre-down" = "pre-down.d/";
  };

But suggested link lists 12 of them!

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I got confused at first too, my first tackle at the PR added:

dispatcherTypesSubdirMap = {
   "basic" = "";
   "pre-up" = "pre-up.d/";
   "up" = "";
   "pre-down" = "pre-down.d/";
   "down" = "";
   "vpn-pre-up" = "pre-up.d/";
   "vpn-up" = "";
   "vpn-pre-down" = "pre-down.d/";
   "vpn-down" = "";
   "hostname" = "";
   "dhcp4-change" = "";
   "dhcp6-change" = "";
   "connectivity-change" = "";
 };```
but then as I got to deploy my script realized that the addition might be misleading since the scripts end up in the same folder and they must check themselves their second parameter value ( e.g., if `[ "$2"= "dhcp4-change"] then .... fi` to act only for dchp4 events) so I reverted the change

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ok, then maybe hide this option (make it internal, not deprecated)? I don't see any value in it except link in description.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It has value because some events call hooks only in the specific folders "pre-down.d/" / "pre-up.d/";

@@ -229,15 +229,19 @@ in {
source = mkOption {
type = types.path;
description = ''
A script.
Path to the hook script. Beware of the networkmanager dispatcher
service PATH (coreutils/iproute are available).
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

First sentence is fine. Second is redundant I think (it would be rather unexpected to NOT have coreutils available). Probably can be merged with description of type if it turns out that type option isn't actually supported.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

coreutils wasn't available until this PR so I was not sure it's sthg to be assumed for nixos.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, this is more of my personal preference. I'll try to explain why I think the previous situation was an actual bug.

When NixOS presents a types.lines option, it is still confusing not to have basic commands in default environment, but one can fix this with inline ${package}/bin/executable.

When NixOS presents a types.path option, it looks like that file/script can be used on it's own, and most probably it doesn't contain references to /nix/store/... executables, but rather relies on $PATH.

NixOS newcomers even think that user's or root's $PATH inherits into service's PATH, but then spend half a day to fix hostname: command not found (happend to me :( for some other NixOS options)


Also, second sentence refers to "networkmanager dispatcher service PATH" which is more of implementation detail. When you read NixOS manual, you won't find anywhere that "networkmanager dispatcher service PATH", only in NixOS source code. It is correct to refer to it only If it is abstracted to an option in networkmanager.* namespace.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree it's more of an implementation detail. I wish nixos systemd side of things were documented in nixpkgs too.

@danbst
Copy link
Contributor

danbst commented May 17, 2018

Also, while you are here, can you add some simple hook script as literal example?

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/lib  /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/libexec  /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/bin  /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/sbin
patching script interpreter paths in /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6
checking for references to /build in /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6...
moving /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/sbin/* to /nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6/bin
shrinking RPATHs of ELF executables and libraries in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev
strip is /nix/store/jk6j4lh9v5mvjdbdc35sj0zffhhf6s56-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev/lib
patching script interpreter paths in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev
checking for references to /build in /nix/store/1283cnpjmfwa0yg1085bbcn0n65nqwfy-network-manager-1.10.6-dev...
/nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6

@teto
Copy link
Member Author

teto commented May 21, 2018

I added a literalExample


# coreutils and iproute are in PATH too
logger "Device $DEVICE_IFACE coming up"
'';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The closing ''' for pkgs.writeText is missing

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

@danbst
Copy link
Contributor

danbst commented May 21, 2018

  1. Also, please, move the example to networking.networkmanager.dispatcherScripts. There is an implicit convention to make examples easy to copy-paste for newcomers. It isn't very obvious from manual that you require two sets of parenthesis for example to work...

See examples
https://nixos.org/nixos/options.html#networking.firewall.allowedtcpportranges
https://nixos.org/nixos/options.html#users.users

  1. I can't get it working. What's wrong with my setup?

/tmp/config.nix

{ pkgs, ... }: {

  users.extraUsers.root.initialPassword = "111";
  users.mutableUsers = false;

  networking.networkmanager.enable = true;
  networking.networkmanager.dispatcherScripts = [
    {
      source = pkgs.writeText "upHook" ''
        if [ "$2" != "up" ]; then
            logger "exit: event $2 != up"
        fi

        # coreutils and iproute are in PATH too
        logger "Device $DEVICE_IFACE coming up"
      '';
    }
  ];
}

I do run

rm -rf nixos.qcow2
NIX_PATH=nixpkgs=$PWD:nixos-config=/tmp/config.nix nixos-rebuild build-vm
/nix/store/vpizxjn70q7440i1nls2895q7fvr1xrq-nixos-vm/bin/run-nixos-vm

I have the script installed in /etc/NetworkManager/dispatcher.d/03userscript0001 with 544 mode.
I try to restart interface ifconfig eth0 down and up, but I don't see my hook logs in journalctl -u network-manager.service.

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

@teto
Copy link
Member Author

teto commented May 21, 2018

Is that what you expected for the example ? The message won't appear under the network-manager service but with the user name by default (you can change it with logger -t IIRC). Maybe as a first trial grep through journal -b0

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

@@ -224,21 +224,22 @@ in {
};

dispatcherScripts = mkOption {
example = [ {
source = pkgs.writeText "upHook" ''

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Almost good now! Except that pkgs.writeText will get executed/evaluated on manual build...
You can see yourself what happens: nix-build nixos/release.nix -A manual.x86_64-linux && firefox .../share/doc/nixos/index.html

networking.networkmanager.dispatcherScripts

    A list of scripts which will be executed in response to network events.

    Type: list of submodules

    Default: [ ]

    Example: [ { source = (build of upHook); type = "basic"; } ]

    Declared by:
    <nixpkgs/nixos/modules/services/networking/networkmanager.nix> 

This is why for any nontrivial types you have to set plaintext literalExample instead of example.

@danbst
Copy link
Contributor

danbst commented May 21, 2018

@teto Your're right! I've grepped through journaltcl and found that logs do work!

@teto
Copy link
Member Author

teto commented May 21, 2018

cool ! I moved the example after default as it is usually done. I generated the doc and here at least the alignement of braces is good.
I can squash but it might be safer to do it from github interface.
Thanks for your advice. I wish I could write tests but right now I don't have time. Maybe later as I tinker with networking stuff quite a bit.

'';
};

type = mkOption {
type = types.enum (attrNames dispatcherTypesSubdirMap);
default = "basic";
description = ''
Dispatcher hook type. Only basic hooks are currently available.
Dispatcher hook type. Look up the hooks described at
https://developer.gnome.org/NetworkManager/stable/NetworkManager.html
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One more, please. Change this to <xlink>, otherwise it isn't rendered as link

<link xlink:href="https://developer.gnome.org/NetworkManager/stable/NetworkManager.html">https://developer.gnome.org/NetworkManager/stable/NetworkManager.html</link>

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

Copy link
Contributor

@danbst danbst left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good now!
And thanks for quick feedback!

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/pmlaavq3szd1wlv5dzkfjb0r5plfjnb0-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/w8fmkfjqj5bxff9av6iiw1xrg4sirq1y-network-manager-1.10.6

@teto
Copy link
Member Author

teto commented May 29, 2018

@matthewbauer as you already helped me with the iproute change, I wonder if you could review and eventually merge it ? I've been using it with success for some time.

@teto teto mentioned this pull request Jun 10, 2018
8 tasks
@teto teto force-pushed the nm_dispatchers branch 2 times, most recently from 44601fd to d7a4e7d Compare July 13, 2018 02:23
@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

  /nix/store/vkh1f9088qjp4806gmv4vwnd72sqinly-bluez-5.50
copying path '/nix/store/vkh1f9088qjp4806gmv4vwnd72sqinly-bluez-5.50' from 'https://cache.nixos.org'...
copying path '/nix/store/9ncbrnv3840cacfwwg2vbvf2x0rws5zp-dnsmasq-2.78' from 'https://cache.nixos.org'...
copying path '/nix/store/chv1mzbhbzq72ghvmph592lkf4ij1xqk-libmbim-1.16.0' from 'https://cache.nixos.org'...
copying path '/nix/store/pn1p9maj7bdcsb017831sw53zgr3p98l-stoken-0.92' from 'https://cache.nixos.org'...
copying path '/nix/store/r5smvmvzdy5462hdrvpc5nfl86scplby-libqmi-1.20.0' from 'https://cache.nixos.org'...
copying path '/nix/store/nccbkbflrx2sglh62hjr482495n7riyr-openconnect-7.08' from 'https://cache.nixos.org'...
copying path '/nix/store/ia4l1iixi5xnaqkzbyk29m5nz0dck6d8-modem-manager-1.7.990' from 'https://cache.nixos.org'...
copying path '/nix/store/6hsqzxynq08ciqqzn2vb1fsj16v141zm-network-manager-1.10.6' from 'https://cache.nixos.org'...
/nix/store/6hsqzxynq08ciqqzn2vb1fsj16v141zm-network-manager-1.10.6

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

/nix/store/n5aq1djyviggc9frcaabzkzlrx0g7ac7-network-manager-1.10.6

@teto
Copy link
Member Author

teto commented Jul 13, 2018

rebased and squashed. Hope this can be merged.

@danbst
Copy link
Contributor

danbst commented Jul 13, 2018

cc @peterhoeg @Mic92 for review

First change is to override the nm-dispatcher systemd service so that
it puts coreutils (wc/env/...) and iproute in PATH.
Second change is to make sure userscripts have the execute bit.
@teto
Copy link
Member Author

teto commented Aug 7, 2018

rebased. Hope this can make it to the next release.

@GrahamcOfBorg
Copy link

Success on aarch64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

stripping (with command strip and flags -S) in /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2/lib  /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2/libexec  /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2/bin  /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2/sbin
patching script interpreter paths in /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2
checking for references to /build in /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2...
moving /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2/sbin/* to /nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2/bin
shrinking RPATHs of ELF executables and libraries in /nix/store/mwlkr8gxngi1a2l9kckgh9zads3629iv-network-manager-1.12.2-dev
strip is /nix/store/zrs21zqcchgyabjf4xfimncdq16njizc-binutils-2.30/bin/strip
stripping (with command strip and flags -S) in /nix/store/mwlkr8gxngi1a2l9kckgh9zads3629iv-network-manager-1.12.2-dev/lib
patching script interpreter paths in /nix/store/mwlkr8gxngi1a2l9kckgh9zads3629iv-network-manager-1.12.2-dev
checking for references to /build in /nix/store/mwlkr8gxngi1a2l9kckgh9zads3629iv-network-manager-1.12.2-dev...
/nix/store/w1gma7i2pybsc16v36cqgxhly7bzfyf6-network-manager-1.12.2

@GrahamcOfBorg
Copy link

Failure on x86_64-linux (full log)

Attempted: networkmanager

Partial log (click to expand)

       instance = g_object_ref (gdk_window_new (NULL, &attributes, 0));
                ^
  CCLD     notify
  CC       no-gtk-init.o
building of '/nix/store/7452ni8m8kzi698sq8xx5176rn7yx30g-gtk+3-3.22.30.drv' timed out after 3600 seconds
cannot build derivation '/nix/store/jnq02lq3vwblghv3la5pqpf2xiwbh029-stoken-0.92.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/q39hg34kmqrg548kwvsm8lfml33pxrka-openconnect-7.08.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/bqa90vsvzcvrlrw585xic149r9g4984h-fix-paths.patch.drv': 1 dependencies couldn't be built
cannot build derivation '/nix/store/s7xl8x7r9ynxi92fsklg0wdj003i8xwz-network-manager-1.12.2.drv': 1 dependencies couldn't be built
error: build of '/nix/store/s7xl8x7r9ynxi92fsklg0wdj003i8xwz-network-manager-1.12.2.drv' failed

@teto
Copy link
Member Author

teto commented Aug 31, 2018

@samueldr low priority PR which I only dare to bother you about because of https://discourse.nixos.org/t/nixos-18-09-jellyfish-to-be-forked-off-in-a-month/596/10 :D (feel free to ignore if you are time constrained). This PR allows to write network manager hooks which is very practical when dealing with advanced network configurations.

Copy link
Member

@samueldr samueldr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Most of the changes are documentation-related (descriptions, examples).

What's changed seems fine and hadn't caught the eyes of the other reviewers either.

@samueldr samueldr merged commit ca47cc9 into NixOS:master Sep 2, 2018
@teto teto deleted the nm_dispatchers branch September 3, 2018 03:38
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants