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

home-manager: check FQDN for '--flake .' attribute #5462

Merged
merged 1 commit into from
May 29, 2024

Conversation

gauravjuvekar
Copy link
Contributor

Description

Since nixpkgs commit 993baa587c4b82e791686f6ce711bcd4ee8ef933, networking.hostName is not allowed to be a FQDN.

Add hostname --fqdn to the default flake attribute names that are searched.

If

netorking.hostname = "hostname";
networking.domain = "example.com";

is set in the system NixOS configuration, this allows defining

homeConfigurations."username@hostname.example.com" = ...

and still use

home-manager switch --flake .

instead of having to type out

home-manager switch --flake .#$(whoami)@$(hostname --fqdn)

Checklist

  • Change is backwards compatible.

    • Technically no if someone happens to have both homeConfigurations."username@hostname" and homeConfigurations."username@hostname.example.com".
  • Code formatted with ./format.

  • Code tested through nix-shell --pure tests -A run.all or nix develop --ignore-environment .#all using Flakes.

  • Test cases updated/added. See example.

  • Commit messages are formatted like

    {component}: {description}
    
    {long description}
    

    See CONTRIBUTING for more information and recent commit messages for examples.

  • If this PR adds a new module

    • Added myself as module maintainer. See example.

Maintainer CC

Since nixpkgs commit 993baa587c4b82e791686f6ce711bcd4ee8ef933,
`networking.hostName` is not allowed to be a FQDN.

Add `hostname --fqdn` to the default flake attribute names that are
searched.

If

    netorking.hostname = "hostname";
    networking.domain = "example.com";

is set in the system NixOS configuration, this allows defining

    homeConfigurations."username@hostname.example.com" = ...

and still use

    home-manager switch --flake .

instead of having to type out

    home-manager switch --flake .#$(whoami)@$(hostname --fqdn)
@gauravjuvekar gauravjuvekar changed the title home-manager: check FQDN for 'switch --flake .' home-manager: check FQDN for '--flake .' attribute May 28, 2024
@rycee rycee merged commit 1b58925 into nix-community:master May 29, 2024
2 of 3 checks passed
@rycee
Copy link
Member

rycee commented May 29, 2024

Thanks, looks good! Merged to master now 🙂

@gauravjuvekar gauravjuvekar deleted the fqdn branch May 30, 2024 02:03
@ilyagr
Copy link

ilyagr commented May 30, 2024

After this PR (I believe), I'm getting the following error on Mac OS:

$ uname -a
Darwin macaw.local 23.5.0 Darwin Kernel Version 23.5.0: Wed May  1 20:14:38 PDT 2024; root:xnu-10063.121.3~5/RELEASE_ARM64_T6020 arm64 arm Darwin
$ home-manager switch --impure
hostname: illegal option -- -
usage: hostname [-fs] [name-of-host]
Starting Home Manager activation
Activating checkFilesChanged
Activating checkLaunchAgents
Activating checkLinkTargets
Activating writeBoundary
Activating installPackages
nix profile remove /nix/store/b6g3p868a8lkzdq7rnf12nj9njm4szca-home-manager-path
removing 'home-manager-path'
Activating linkGeneration
Cleaning up orphan links from /Users/ilyagr
No change so reusing latest profile generation 98
Creating home file links in /Users/ilyagr
Activating onFilesChange
Activating setupLaunchAgents

Update: Don't be too alarmed, the error does not prevent home-manager switch from working. It's merely an annoyance, the command still works after showing the error.

(I am not sure how to find out the exact commit of home-manager I'm using, but I started seeing the error recently, I believe after I updated home-manager today, and this PR looks extremely suspicious)

@gauravjuvekar
Copy link
Contributor Author

gauravjuvekar commented May 30, 2024

Yep, this PR is the likely cause.
I'll change it to hostname -f as seems like macos doesn't support the long style option name --fqdn (based on the usage: line)

@gauravjuvekar
Copy link
Contributor Author

#5471

@bryango
Copy link
Contributor

bryango commented Jul 24, 2024

If the hostname is not set in /etc/hosts, the command may fail with:

$ hostname -f
hostname: Unknown host

This shows up in the home-manager switch printout and is mildly annoying. Could it be changed to:

hostname -f 2>/dev/null

to suppress this inconsequential warning? Thank you!

@gauravjuvekar
Copy link
Contributor Author

Ack, I'll make a PR some time this week. Could you file a separate issue for this and tag me?

@bryango bryango mentioned this pull request Jul 25, 2024
2 tasks
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