Go `osRelease` not detected in `runCommand` derivation

I use the following simple derivation

pkgs.runCommand "chezmoi-test" {preferLocalBuild = true;} ''
  ${cfg.package}/bin/chezmoi execute-template "{{ .chezmoi.osRelease }}''

which returns in the log an empty map[] meaning the template {{ .chezmoi.osRelease }} which should report the osRelease did not succeed I suppose.

When I run this on my system

chezmoi execute-template "{{ .chezmoi.osRelease }}''

I get

map[bugReportURL:https://github.com/NixOS/nixpkgs/issues buildID:23.11.20231104.85f1ba3 documentationURL:https://nixos.org/learn.html homeURL:https://nixos.org/ id:nixos logo:nix-snowflake name:NixOS prettyName:NixOS 23.11 (Tapir) supportURL:https://nixos.org/community.html version:23.11 (Tapir) versionCodename:tapir versionID:23.11]%

I guess I need to make /etc/release available inside the runCommand.
How does that work?

That’s because /etc/os-release is not in the build sandbox, and for good reason. Derivations are supposed to be reproducible, and os-release is system-specific (or at least OS-specific). It’s an impurity that would cause the derivation to build differently on different machines.

Whatever it is that needs os-release, it should either A) be changed to not need it, B) be provided a dummy value somehow in the sandbox, or C) be run in a VM in the build (see runInLinuxVM).

Ah thats why a chezmoi (dotfile install) will never work the way I look at:

Because it runs in the sandbox and chezmoi cannot act on these used variables inside the dotfile templates…

So I guess the only way is to proberly do that in home.activation. Right?

I don’t really know anything about chezmoi… but tbh I wonder why you would need it if you’re using home-manager?

Because I want to keep all config files for now inside chezmoi, which is an easier tool to deploy them.
Transfering all dotfiles into a nix approach is vast amount of work and the benefits ok, Windows then does not work (but who needs to use this shit anyway…)…
Do deploy the dot file I only need chezmoi and not nix… is that a fair point? Maybe sometime later…