ToyVo / nh_darwin

Yet another nix cli helper
European Union Public License 1.2
22 stars 5 forks source link

hostname ending in .local does not work #12

Closed bonds closed 2 months ago

bonds commented 2 months ago

Before installing I used darwin-rebuild switch --flake . and it worked fine:

building the system configuration...
Password:
user defaults...
setting up user launchd services...
applying custom icons...
setting up /Applications/Nix Apps...
setting up pam...
applying patches...
setting up /etc...
system defaults...
setting up launchd services...
reloading nix-daemon...
waiting for nix-daemon
configuring networking...
setting up /Library/Fonts/Nix Fonts...
setting nvram variables...

Then I tried nh_darwin and I got an error:

╰─❯ nh_darwin os switch .
> Building Darwin configuration
fetching git input 'git+file:///Users/scott'
error: flake 'git+file:///Users/scott?dir=.config/nix' does not provide attribute 'packages.aarch64-darwin.darwinConfigurations.""accismus.local"".config.system.build.toplevel', 'legacyPackages.aarch64-darwin.darwinConfigurations.""accismus.local"".config.system.build.toplevel' or 'darwinConfigurations.""accismus.local"".config.system.build.toplevel'
┏━ 1 Errors:
┃ error: flake 'git+file:///Users/scott?dir=.config/nix' does not provide attribute 'package…
┣━━━
┗━ ∑ ⚠ Exited with 1 errors reported by nix at 19:16:27 after 0s
Error:
   0: Command exited with status Exited(1)

Location:
   src/commands.rs:170

from my flake.nix:

    darwinConfigurations = {
      "accismus" = nix-darwin.lib.darwinSystem {
        specialArgs = {inherit inputs outputs;};
        modules = [
          ./laptop
          darwin-custom-icons.darwinModules.default
          lix-module.nixosModules.default
          # nh_darwin.nixDarwinModules.default
          nh_darwin.nixDarwinModules.prebuiltin
        ];
        # Set Git commit hash for darwin-version.
        system.configurationRevision = self.rev or self.dirtyRev or null;
      };
    };

and

$ hostname
accismus.local

So...maybe nix-darwin knows to ignore the .local in the hostname but nh doesn't? Not sure what the workaround is...I can't seem to remove the .local from my hostname in macos, so for now I'm just falling back to darwin-rebuild.

bestlem commented 2 months ago

The issue here I would guess is that you put quotes around your machine name. e.g. the line

"accismus" = nix-darwin.lib.darwinSystem {

Try without the "" there

bonds commented 2 months ago

Huh, that worked. :) Thank you!

bestlem commented 2 months ago

I think this is just a workaround. I think nh ought to have dealt with this. If it should that is a bug/feature for the upstream nh not nh_darwin.

thecaralice commented 2 months ago

The actual reason is that on macOS gethostname call returns the FQDN, causing nh_darwin to read that. However, darwin-rebuild calls scutil --get LocalHostName which returns just the hostname part.

ToyVo commented 2 months ago

Github shows the pull request as closed, but I did cherry-pick @thecaralice's commit. I rebased on upstream before seeing their PR and didn't want to force them to resolve conflicts. @bonds update your input to get the feature.

bonds commented 2 months ago

It works! Thanks @ToyVo !