Repository navigation
Conversation
|
Wouldn't it be sufficient to log the output of the activation script? |
i'll test
in journalctl so nothing special |
|
@roberth but only logging the activation will not log started/stopped units :/ It's probably best to start logging just before the switch-to-configuration.pl call |
|
@dasJ You're right. It should including switching, which is more than activation. |
|
in the temp commit the systemd-cat output is but only if --fast is used i think the cause is # Re-execute nixos-rebuild from the Nixpkgs tree.
# FIXME: get nixos-rebuild from $flake.
if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast && -z $flake ]]; then
if p=$(nix-build --no-out-link --expr 'with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild' "${extraBuildFlags[@]}"); then
export _NIXOS_REBUILD_REEXEC=1
exec "$p/bin/nixos-rebuild" "${origArgs[@]}"
exit 1
fi
fispecifically the i'll add |
|
fixed it. apply this patch to test it
diff --git a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
index 5ca0a847d05..21276ce8187 100755
--- a/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
+++ b/pkgs/os-specific/linux/nixos-rebuild/nixos-rebuild.sh
@@ -327,7 +327,7 @@ fi
# Re-execute nixos-rebuild from the Nixpkgs tree.
# FIXME: get nixos-rebuild from $flake.
if [[ -z $_NIXOS_REBUILD_REEXEC && -n $canRun && -z $fast && -z $flake ]]; then
- if p=$(nix-build --no-out-link --expr 'with import <nixpkgs/nixos> {}; config.system.build.nixos-rebuild' "${extraBuildFlags[@]}"); then
+ if p=$(nix-build --no-out-link --expr 'with import ./nixos/. {}; config.system.build.nixos-rebuild' "${extraBuildFlags[@]}"); then
export _NIXOS_REBUILD_REEXEC=1
exec "$p/bin/nixos-rebuild" "${origArgs[@]}"
exit 1current journal output lmk if you can spot other commands which outputs should be logged |
c83b8de to
08d65ac
Compare
|
@l0b0 hi, you're good at bash so could you review or suggest improvements? |
can be viewed with journalctl -t nixos-rebuild
08d65ac to
3f691c7
Compare
|
the output of rebuild now looks like this, there's a newline between the building and the switch-to-configuration for some reason, but it may actually be good because now those parts are better separated journal output looks like |
| user services need to be started manually as they aren't detected | ||
| by the activation script at the moment. | ||
|
|
||
| output is logged to the systemd journal and can be viewed with <command>journalctl -t nixos-rebuild</command>. |
There was a problem hiding this comment.
"output" should probably be "Output".
| # msg something | ||
| msg() { | ||
| if command -v systemd-cat &>/dev/null && systemctl &>/dev/null; then | ||
| echo -e "$@" | tee >(systemd-cat -t nixos-rebuild) |
There was a problem hiding this comment.
Is -e a good idea here? What if some arbitrary command output contains any backslashes? echo is also problematic since it accepts flags and even accepts different flags based on the shell. For example, if the first argument is -n:
$ messages=('-n' 'foo') && echo "${messages[@]}" | xxd
00000000: 666f 6f foo
Basically, you might want to use printf '%s\n' "$@" instead.
There was a problem hiding this comment.
I think the above printf should use "$*" (single arg) instead of "$@" (multiple args).
There was a problem hiding this comment.
Why? It's almost always a bad idea to use $*, as explained in for example What is the difference between $* and $@? and for arg in $*.
There was a problem hiding this comment.
I'd have to test it, but I thought the printf format string had to match the number of arguments?
There was a problem hiding this comment.
printf will reuse the format string repeatedly as long as there are arguments to process, for example:
$ printf '%s\n' 'foo bar' 'baz'
foo bar
baz
Conversely, if there are too few arguments it will fill in an empty string, for example:
$ printf '%s-%s-%s\n' 'foo bar' 'baz'
foo bar-baz-
Relevant to this is that "$@" expands to no arguments if the argument list is empty, but "$*" expands to an argument no matter what:
$ arg_count() {
> echo $#
> }
$ arg_count "$@"
0
$ arg_count "$*"
1
|
|
||
| # msg something | ||
| msg() { | ||
| if command -v systemd-cat &>/dev/null && systemctl &>/dev/null; then |
There was a problem hiding this comment.
command -v might be better as type. Also, what is the purpose of the systemctl command here? If it's just to check whether that command exists, it's pretty slow. You might want to use type systemctl.
| ;; | ||
| --install-grub) | ||
| echo "$0: --install-grub deprecated, use --install-bootloader instead" >&2 | ||
| msg "$0: --install-grub deprecated, use --install-bootloader instead" |
There was a problem hiding this comment.
This changes the semantics, since the message is no longer sent to stderr. You could either keep the redirect here, or use $1 in msg to indicate the target file descriptor, as in printf '%s\n' "$@" >&"$1".
| fi | ||
| copyToTarget "$pathToConfig" | ||
| targetHostCmd nix-env -p "$profile" --set "$pathToConfig" | ||
| targetHostCmd nix-env -p "$profile" --set "$pathToConfig" 2>&1 | msgPipe |
There was a problem hiding this comment.
Do we not want to keep stdout and stderr separate for logging purposes? I think the journal treats them differently.
There was a problem hiding this comment.
Would making a msgErr and msgErrPipe be the best solution?
There was a problem hiding this comment.
That would work. But at this point maybe an exec which redirects stdout and stderr to separate systemd-cat commands would be a good way to capture all the output rather than only some commands?
|
Instead of instrumenting the commands and messages printed in the script itself, why don’t we wrap it? |
|
@Profpatsch mostly to avoid logging the build log, which is excessive duplication and not something that can be relied on either, as logs of cached builds won't be duplicated into the system log anyway. Perhaps a good option is make the script to wrap itself (or redirect its output with |
Ah you mean the nix output is already accessible with |
can be viewed with journalctl -t nixos-rebuild
Motivation for this change
This will help with debugging
maybe helps with issues such as #146727
Things done
tested with
nix build ".#nixos-rebuild" && sudo ./result/bin/nixos-rebuild switchand
sandbox = trueset innix.conf? (See Nix manual)nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD". Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/)nixos/doc/manual/md-to-db.shto update generated release notes