mirror of
https://github.com/nix-community/home-manager
synced 2024-12-25 03:09:47 +01:00
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
1 changed files with 11 additions and 4 deletions
|
@ -106,10 +106,17 @@ function setFlakeAttribute() {
|
||||||
local name="${FLAKE_ARG#*#}"
|
local name="${FLAKE_ARG#*#}"
|
||||||
;;
|
;;
|
||||||
*)
|
*)
|
||||||
local name="$USER@$(hostname)"
|
local name="$USER"
|
||||||
if [ "$(nix eval "$flake#homeConfigurations" --apply "x: x ? \"$name\"")" = "false" ]; then
|
# Check both long and short hostnames; long first to preserve
|
||||||
name="$USER"
|
# pre-existing behaviour in case both happen to be defined.
|
||||||
fi
|
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
|
esac
|
||||||
export FLAKE_CONFIG_URI="$flake#homeConfigurations.\"$name\""
|
export FLAKE_CONFIG_URI="$flake#homeConfigurations.\"$name\""
|
||||||
|
|
Loading…
Reference in a new issue