Code Monkey home page Code Monkey logo

Comments (7)

ErrrorMaxx avatar ErrrorMaxx commented on June 9, 2024

$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.

twpayne avatar twpayne commented on June 9, 2024

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.

al0git avatar al0git commented on June 9, 2024

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.

twpayne avatar twpayne commented on June 9, 2024

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.

al0git avatar al0git commented on June 9, 2024

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.

halostatue avatar halostatue commented on June 9, 2024

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 of hostname = 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.

al0git avatar al0git commented on June 9, 2024

That's clear, thanks.

from chezmoi.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.