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] iproute: copy files in /etc #39536

Merged
merged 2 commits into from May 15, 2018
Merged

[RDY] iproute: copy files in /etc #39536

merged 2 commits into from May 15, 2018

Conversation

teto
Copy link
Member

@teto teto commented Apr 26, 2018

When doing source routing/multihoming, it's practical to give names to routing
tables. The absence of the rt_table file in /etc make this impossible.
This patch recreates these files on rebuild so that they can be modified
by the user

Motivation for this change

see #38638.

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: iproute

Partial log (click to expand)

/nix/store/wk7fql3ag8aq1n2zy5v7r25h2cjnfqr0-iproute2-4.16.0

@GrahamcOfBorg
Copy link

Success on x86_64-linux (full log)

Attempted: iproute

Partial log (click to expand)

/nix/store/07jzv5nwz5p1rn7nmw9fnf9gikir7ivg-iproute2-4.16.0

@@ -119,6 +119,12 @@ in

system.activationScripts.stdio = ""; # obsolete

system.activationScripts.iproute2 = ''
cp -R ${pkgs.iproute}/etc/iproute2 /etc
Copy link
Member

Choose a reason for hiding this comment

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

but does this not overwrite any modification done by the user?

Copy link
Member

Choose a reason for hiding this comment

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

I that case, would it not be better to have config options for those files? This feels wrong. The files should either be managed by nix or not touched like that at all..

Copy link
Member

Choose a reason for hiding this comment

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

I agree with that.

Copy link
Member Author

Choose a reason for hiding this comment

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

once iproute is installed, users expect ip route list table main to work but if iproute can't find the file than it breaks this expection. While the file can be modified, it does have default. Maybe iproute should be patched look somewhere else than /etc/iproute2 (like in /var/run) but some sort of default should exist. To prevent overwriting user changes, the activationScript could write it only if it does'nt already exist.

@teto
Copy link
Member Author

teto commented Apr 28, 2018 via email

@matthewbauer
Copy link
Member

Hm... Does iproute follow any environment variables to change the location of these things?

@teto
Copy link
Member Author

teto commented May 9, 2018

nope but you can configure an alternate path to look for on compilation (like /var/run).

@matthewbauer
Copy link
Member

matthewbauer commented May 9, 2018

Maybe we should just patch it to look in /run/current-system/sw/etc. That would avoid the cp call.

To have /etc/iproute2 installed in /run/current-system/sw, you will need to add it to patchsToLink here:

environment.pathsToLink =
[ "/bin"
"/etc/xdg"
"/etc/gtk-2.0"
"/etc/gtk-3.0"
"/lib" # FIXME: remove and update debug-info.nix
"/sbin"
"/share/applications"
"/share/desktop-directories"
"/share/doc"
"/share/emacs"
"/share/icons"
"/share/menus"
"/share/mime"
"/share/nano"
"/share/org"
"/share/themes"
"/share/vim-plugins"
"/share/vulkan"
"/share/kservices5"
"/share/kservicetypes5"
"/share/kxmlgui5"
];

@teto
Copy link
Member Author

teto commented May 9, 2018

For my specific scenario, the file is modified dynamically depending on network conditions. If a network pops up, it will create its own routing table alias in /etc/iproute2/rt_tables. So the file needs to be writable (ideally reset on boot), I don't think I can do this with pathsToLink.

@matthewbauer
Copy link
Member

Ok. This would probably make sense as a module then. It definitely should not be done by default. Or at least not until other users start complaining about the missing routing tables.

@teto teto force-pushed the iproute branch 2 times, most recently from e9371da to 18cfb6a Compare May 11, 2018 08:46
@teto
Copy link
Member Author

teto commented May 11, 2018

I made it a module, I can merge it with the networking module if need be.

buildFlags = [
"CONFDIR=/etc/iproute2"
"CONFDIR=/run/iproute2"
Copy link
Member

Choose a reason for hiding this comment

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

You can share this with the module by using something like config.iproute2.confdir or "/etc/iproute2"

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 was looking for a way to unify the setting too but not sure how to do it. I just tried sthg but it fails. Any suggestion ? Thanks for your patience

Copy link
Member

Choose a reason for hiding this comment

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

Yes I think you would do this like:

"CONFDIR=${config.iproute2.confdir or "/run/iproute2"}"

& then add config as an arg.

Also add to your module implementation:

nixpkgs.config.iproute2.confdir = "/run/iproute2"

Copy link
Member Author

@teto teto May 11, 2018

Choose a reason for hiding this comment

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

just making sure:

  • does it have to be a toplevel config.iproute2 or is the current config.networking.iproute2 ok ?
  • I already have confDir as an option. isn't that enough ?

@teto
Copy link
Member Author

teto commented May 12, 2018

@matthewbauer is that conform to what you requested, if yes feel free to squash & merge.
many packets depend on iproute so I am interested in having this small change upstream.

buildFlags = [
"CONFDIR=/etc/iproute2"
"CONFDIR=${config.networking.iproute2.confDir or "/run/iproute2"}"
Copy link
Member

Choose a reason for hiding this comment

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

Can you verify if this works? That is can you change confDir and get a different value passed to buildFlags? I'm not 100% on this but I think you need to directly pass it with nixpkgs.config in your module (see https://github.com/NixOS/nixpkgs/blob/release-18.03/nixos/modules/misc/nixpkgs.nix#L92-L106). Nixpkgs & NixOS have different config sets which can be confusing.

Copy link
Member

Choose a reason for hiding this comment

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

IMHO this requires a change log entry.

I am also not so sure if changing the default to /run is a good decision. If someone needs this the configuration will be set to whatever the user wants and the default behavior should not be altered if not used.

Am I missing something?

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 this can be cool to have as a changelogentry. How would I do that ? other PR ? what document ?
I don't see a usecase either to let the user set the path (he would lose the cache) so I am tempted to remove the confDir = mkOption { but the paths between the module and the package must be in sync so I would let the nixpkgs.config.iproute2.confDir. If the user can't choose confDir, then we need to agree on the default. /etc/iproute2 is the common one but I guess /run/iproute2 matches dynamic files better. I am fine either way.

Copy link
Member

Choose a reason for hiding this comment

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

Ok yeah just using /run/iproute2 makes sense.

Copy link
Member Author

Choose a reason for hiding this comment

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

do you want me to hardcode it or current Pr is fine ?

Copy link
Member

Choose a reason for hiding this comment

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

It's fine now

Copy link
Member Author

Choose a reason for hiding this comment

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

many thanks for shepharding.

@teto
Copy link
Member Author

teto commented May 12, 2018

I tested it and the changes took effect. I squashed all.

@teto teto changed the title iproute: copy files in /etc [RDY] iproute: copy files in /etc May 14, 2018
teto added 2 commits May 15, 2018 21:55
When doing source routing/multihoming, it's practical to give names to routing
tables. The absence of the rt_table file in /etc make this impossible.
This patch recreates these files on rebuild so that they can be modified
by the user see NixOS#38638.

iproute2 is modified to look into config.networking.iproute2.confDir instead of
/etc/iproute2.
@teto
Copy link
Member Author

teto commented Jun 8, 2018

That sounds better, I don't think we need to have a configurable path. But I think this should be done by nixos so the module may still make sense. While I am just interested in rt_tables the other files in etc/iproute2/ should be copied too.
Is there a way to do this

environment.etc."iproute2/rt_tables" = {
  text = (lib.fileContents "${pkgs.iproute}/etc/iproute2/rt_tables") + '' any extras '';
  mode = "0644";
};

but for the whole ${pkgs.iproute}/etc/iproute2 folder ?

@andir
Copy link
Member

andir commented Jun 8, 2018 via email

@teto
Copy link
Member Author

teto commented Jun 10, 2018

doesn't seem simpler than the current cp -R.
To sum up the requested change would be to default back to /etc/iproute2 (and even remove the configurability). @volth feel free to open a PR, else I can do it.

@teto
Copy link
Member Author

teto commented Jun 10, 2018

What is that multihoming module ? I see your point in having the file generated.

As for myself I use networkmanage hooks to achieve dynamic multihoming #39142 so I would need mode = "0644";

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

5 participants