Adding date/time to a config option

I want to add the time a config was built to system.nixos.tags.

	configCreationTimeFile = ( 
				"date > $out"

I’m currently reading a file created by the above command. As nix works though, this evaluates to the same .drv everytime and hence doesn’t get reevaluated on build.

What should I do?

(I understand that a solution could potentially cause every nix-rebuild invocation to build (and only change that option) even if there were no changes, but I’m fine with that)

1 Like

I haven’t done this before but maybe something like

configCreationTimeFIle = pkgs.runCommand "config-creation-time" {
  currentTime = builtins.currentTime;
} "date -r $currentTime > $out"

Thanks, I didn’t know about builtins.currentTime I tried .date and .time in the repl then for some reason assumed nix might not have it…

1 Like

I didn’t know about it either, I just started the repl and typed builtins.<tab> and read through the list of results in the hopes that something like it would exist.

1 Like