home-manager: refine flake URI lookup
Depending on DHCP settings you might end up with different output from
running `hostname`. Eg, your local hostname is `mylaptop`, and your
home router is configured with a local domain of `.hoome.arpa`. In
this case:
$ hostname
mylaptop.home.arpa
$ hostname -s
mylaptop
If you then go to cafe which has its router configured with `.lan` as
its local domain. Then, if your DHCP settings accept the local domain
from the router,
$ hostname
myalaptop.lan
$ hostname -s
mylaptop
With the pre-existing behaviour, if you had a
`"me@mylaptop.home.arpa"` entry in `outputs.homeConfigurations`,
running `home-manager switch` would fail:
$ home-manager switch
error: flake 'git+file:///home/me/.config/nixpkgs' does not provide
attribute 'packages.aarch64-darwin.homeConfigurations."me".activationPackage',
'legacyPackages.aarch64-darwin.homeConfigurations."me".activationPackage'
or 'homeConfigurations."me".activationPackage'
After this commit, you can put configuration in a `"me@mylaptop"`
entry in `outputs.homeConfigurations`, and everything will work on
either network.
(cherry picked from commit e7eba9cc46
)
This commit is contained in:
parent
d965d248aa
commit
2bfcc6be42
|
@ -106,10 +106,17 @@ function setFlakeAttribute() {
|
|||
local name="${FLAKE_ARG#*#}"
|
||||
;;
|
||||
*)
|
||||
local name="$USER@$(hostname)"
|
||||
if [ "$(nix eval "$flake#homeConfigurations" --apply "x: x ? \"$name\"")" = "false" ]; then
|
||||
name="$USER"
|
||||
fi
|
||||
local name="$USER"
|
||||
# Check both long and short hostnames; long first to preserve
|
||||
# pre-existing behaviour in case both happen to be defined.
|
||||
for n in "$USER@$(hostname)" "$USER@$(hostname -s)"; do
|
||||
if [[ "$(nix eval "$flake#homeConfigurations" --apply "x: x ? \"$n\"")" == "true" ]]; then
|
||||
name="$n"
|
||||
if [[ -v VERBOSE ]]; then
|
||||
echo "Using flake homeConfiguration for $name"
|
||||
fi
|
||||
fi
|
||||
done
|
||||
;;
|
||||
esac
|
||||
export FLAKE_CONFIG_URI="$flake#homeConfigurations.\"$name\""
|
||||
|
|
Loading…
Reference in a new issue