Comments (7)
$HOST
(as well as $HOSTNAME
) is not standard variable. In fact, there is no environment variables corresponding to hostname
I don't know why do you have it in your environment, but others don't have it. So I suggest to not use $HOST
in chezmoi
from chezmoi.
Exactly, you can't set hostnames through environment variables. If you want the value of an environment variable then you can use the env
template function.
from chezmoi.
Yes the description is very misleading. Sorry for that. The problem has nothing to do with $HOST or $HOSTNAME. I know that some people rely on it to avoid calling hostname too often, but let's forget these variables.
The problem is that cm execute-template '{{ .chezmoi.hostname }}'
just does not return the name of the machine. That is, it does not return the same result that hostname
does in some conditions. Theses conditions depending on /etc/hosts contents.
from chezmoi.
That is correct. It turns out that getting the hostname of a machine in a reliable way that works across multiple operating systems is hard.
If you want to use the output of hostname
on your machines then you can use the template:
{{ output "hostname" | trim }}
If you want to avoid calling hostname
every time then put this in your config file template:
[data]
hostname = {{ output "hostname" | trim | quote }}
and then use
{{ .hostname }}
in your templates.
from chezmoi.
First thanks for the trick, config file template are very powerful. I even cheated using chezmoi.hostname =
instead of hostname =
to avoid touching my templates and it is working.
For the bug, it seems this is a regression between version 2.31.0 and 2.46.1. I'll try to narrow it when I have a little bit more time (not a go expert). Maybe the order of the methods changed ...
Thanks for your help.
from chezmoi.
For the bug, it seems this is a regression between version 2.31.0 and 2.46.1. I'll try to narrow it when I have a little bit more time (not a go expert). Maybe the order of the methods changed ...
This is not going to be a regression, but an algorithmic change because of other bugs. There are some explicit changes made between those two versions (#3055, #3082, #3104).
As Tom says, this is hard and every source system does this slightly differently — even different Linux distributions do it slightly differently or may have different results in some contexts (e.g., inside Docker).
First thanks for the trick, config file template are very powerful. I even cheated using
chezmoi.hostname =
instead ofhostname =
to avoid touching my templates and it is working.
Don't do this. It’s not a supported behaviour and the contents of .chezmoi
should be treated as read only data and not updated during templating. We do not guarantee that this will work in the future and may make changes in the future that rebind the chezmoi runtime data before template execution that will break this.
from chezmoi.
That's clear, thanks.
from chezmoi.
Related Issues (20)
- autoPush not prompting for commit message HOT 3
- Initial templating with autoPush or autoCommit HOT 2
- "chezmoi update" prompts for password even though encrypted file has not changed HOT 6
- Powershell one-line install on Windows 11 error - "You cannot call a method on a null-valued expression" HOT 17
- One-line binary install script does not give an error when cannot establish HTTPS connection HOT 4
- `chezmoid apply` (and `dump`) cause a Go panic HOT 3
- Option for `.chezmoiexternal` to add files directly to target and not in source state HOT 3
- Option to include directories outside of Chezmoi's root HOT 1
- Add support for template prefix HOT 3
- Support `failure` hooks and scripts HOT 7
- `--follow` and `--recursive` add seem to conflict
- Extend re-add command to add new files
- .chezmoiignore thinks closing braces are a pattern HOT 3
- Trouble ignoring certain files
- `chezmoi edit-config-template` creates initial template with world-writable permissions HOT 2
- Using environment variable in onepasswordRead HOT 1
- Support chmod in attributes HOT 4
- Powershell one-line install on Windows 11 error - update script at https://get.chezmoi.io/ps1 HOT 1
- run time bug when `chezmoi doctor` invoked HOT 6
- Make accidental removal harder
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from chezmoi.