divnix / bud

EXPERIMENTAL -- A highly composable system ctl tool
MIT License
15 stars 12 forks source link

bud is unable to detect hostname on macOS #23

Open montchr opened 2 years ago

montchr commented 2 years ago

Moved from https://github.com/divnix/devos/issues/375 because this happens with every bud command I've tried.

Expected Behavior

On macOS/darwin systems, bud should detect my system's hostname.

Current Behavior

Running bud commands on macOS 11.6 results in an error caused by calling hostname with invalid options.

bud up --help

The output of bud up --help also indicates bud was not able to get a hostname, as the name is not included in the path mentioned in the usage section:

❯ bud up --help
hostname: illegal option -- -
usage: hostname [-fs] [name-of-host]
/nix/store/hzqrpf31gf060ka40hwpqpah79n54hgm-devshell-dir/bin/bud: line 8:  -1: substring expression < 0

Usage: up   Generate /path/to/repo/hosts//default.nix

Description:

bud --help

❯ bud --help
hostname: illegal option -- -
usage: hostname [-fs] [name-of-host]
/nix/store/hzqrpf31gf060ka40hwpqpah79n54hgm-devshell-dir/bin/bud: line 8:  -1: substring expression < 0

...

bud repl

❯ bud repl
hostname: illegal option -- -
usage: hostname [-fs] [name-of-host]
/nix/store/hzqrpf31gf060ka40hwpqpah79n54hgm-devshell-dir/bin/bud: line 8:  -1: substring expression < 0
Welcome to Nix version 2.4pre20210707_02dd6bb. Type :? for help.

Loading '/nix/store/q35fmyf6l8d5gc7khgmpqzj84q6l6wlj-repl.nix'...
Added 4 variables.

bud get (via devos)

DevOS' quick start guide suggests running the following command:

nix-shell https://github.com/divnix/devos/archive/master.tar.gz -A shell \
  --run "bud get master"

This also results in a similar error:

...
created 129 symlinks in user environment
building '/nix/store/izybzyn94b2plalg380jzqq4nnqllsyl-nixos-entrypoint.drv'...
fatal: not a git repository (or any of the parent directories): .git
hostname: illegal option -- -
usage: hostname [-fs] [name-of-host]
/nix/store/83cv4fcjj56sch8z0njlrrf8wiv8kim2-devshell-dir/bin/bud: line 8:  -1: substring expression < 0
11.09s user 30.55s system 5% cpu 13:06.38s total

Steps to Reproduce

On macOS, run any of the commands mentioned above.

Your Environment

I'm guessing Darwin's hostname utility behaves differently than it would on NixOS or another Linux system.

This might also apply to other systems using the BSD utilities?

❯ which hostname
/bin/hostname
❯ hostname --help
hostname: illegal option -- -
usage: hostname [-fs] [name-of-host]
nrdxp commented 2 years ago

are you trying to deploy NixOS systems from darwin, or what is the usecase here? Unfortunately we still don't have great nix-darwin support in general since we don't have any MacOS users on the core team.

blaggacao commented 2 years ago

The particular implementation is towards the end of: https://github.com/divnix/bud/blob/26ba27616647dcd08dac2ee818721bc748c4ac61/module.nix#L75-L88

We internally need to work with reverse DNS of the fqdn to "reliably" match hosts's to the host raking contract: nested folders are raked as reverse DNS, like so:

com
  example
    host1
    host2
net
  example
    host1
    host2

(sorry for that bash sequence)

montchr commented 2 years ago

are you trying to deploy NixOS systems from darwin, or what is the usecase here?

@nrdxp use case is working with a flake providing an output matching my current darwin host's hostname. The flake provides a set of configurations for nix-darwin and home-manager. Essentially just dotfiles. But I'd like to reuse these profiles on NixOS systems as I build them out (via VMs or Linodes). So at least on darwin, I'd only be using the commands that aren't NixOS-specific (e.g. bud repl or bud switch if it could be used with darwin-rebuild)

@blaggacao Thanks, that points me in the right direction. I'm going to assume I'm doing something kind of wrong in the process of setting up this darwin host, as I don't think I should have ended up hitting that call to hostname at all.

blaggacao commented 2 years ago

@montchr It should alwasy hit hostname unless you'd be running already from within the host that you (still) want to build.

That is: in the devshell, it should always try to figure out your current host via hostname.

Could you think of a BSD compatible implementation?

KarolisL commented 2 years ago

I think that hostname -f works on both BSD (at least on Darwin) and Linux. Wouldn't that work?