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

modules: introduce hostctl (static dns for development) #75

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

blaggacao
Copy link
Contributor

hostctl module allows to temporarily set static dns entries for development per project

[hostctl]
enable = true
dns."test.domain.local" = "172.0.0.1"
dns."shared.domain.link-local" = "169.254.0.5"

What we get:

$ nix develop
warning: Git tree '/home/blaggacao/ghq/github.com/numtide/devshell' is dirty
[hostctl] Update static dns entries...
[sudo] password for blaggacao:
[hostctl] +----------+--------+-------------+--------------------------+
[hostctl] | PROFILE  | STATUS |     IP      |          DOMAIN          |
[hostctl] +----------+--------+-------------+--------------------------+
[hostctl] | devshell | on     | 169.254.0.5 | shared.domain.link-local |
[hostctl] | devshell | on     | 172.0.0.1   | test.domain.local        |
[hostctl] +----------+--------+-------------+--------------------------+
🔨 Welcome to devshell

[dns]

  hostctl       - Your dev tool to manage /etc/hosts like a pro!

[formatters]

  nixpkgs-fmt   - Nix code formatter for nixpkgs

[general commands]

  hello         - prints hello
  menu          - prints this menu

[linters]

  golangci-lint - golang linter

[utilites]

  hub           - github utility

$

extra/dns/hostctl.nix Outdated Show resolved Hide resolved
extra/dns/hostctl.nix Outdated Show resolved Hide resolved
Comment on lines +31 to +32
# TODO: Uninstall when leaving the devshell
# trap uninstall EXIT
Copy link
Contributor

Choose a reason for hiding this comment

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

This seems hard to get right, particularly because when the user runs two dev-shells and exits one.

Modifying the system is a bit heavy-handed for a development shell. I was secretly hoping for an unprivileged solution when I saw this PR. Perhaps (userns) containers are a more appropriate solution for most use cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

There is indeed a long term heavily politically involved solution to this: https://github.com/apetresc/nss-hostslocal. That would require lobbying for changing the way how linux system generally resolve hostfiles these days.

This particular PR is not going to get merged for this reason.

However, in a dev team setting, where you can exert certain powers over an individual's machine, this is a solution that (somewhat) works.

David Arnold and others added 2 commits May 12, 2021 14:05
Co-authored-by: Robert Hensing <[email protected]>
Co-authored-by: Robert Hensing <[email protected]>
@zimbatm
Copy link
Member

zimbatm commented Dec 13, 2021

Do you think this PR is worth pursuing? It would need to have some tests.

@blaggacao
Copy link
Contributor Author

It might. I can try to free some time in the next few month, please keep nudging in case I'm not reactive 😄

@bobvanderlinden
Copy link

Have you considered using something like userhosts? https://github.com/figiel/hosts I packaged it in the past for the purpose of using it inside a shell.

It uses ldpreload to override a number of the DNS resolving functions. It doesn't need root and is basically set/reset using envvars.

That said, at the moment it doesn't support osx. Also, if you have a webbrowser open already, it won't pick up the new hosts, as they are only available within the shell.

@bobvanderlinden
Copy link

I created #225 based on libuserhosts as a different implementation of configuring hosts entries.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants