r-darwish / topgrade

Upgrade everything
GNU General Public License v3.0
3.36k stars 160 forks source link

Nix step fails when nix is not part of a Nix profile #866

Closed korrat closed 2 years ago

korrat commented 2 years ago

What did you expect to happen?

After installing Nix and running topgrade, I expected Nix to be upgraded.

What actually happened?

Instead, I got the following error message when running the Nix step.

$ topgrade --only nix

―― 15:40:22 - Nix ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
error: directory '/usr/bin' does not appear to be part of a Nix profile

Additional details

$ topgrade --dry-run --only nix

―― 15:40:10 - Nix ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
Dry running: /usr/bin/sudo -i nix upgrade-nix
Dry running: /usr/bin/nix-channel --update
Dry running: /usr/bin/nix-env --upgrade

―― 15:40:10 - Summary ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
nix: OK

The first command in the above listing is the problem: it only works if the nix binary is part of a Nix profile, which it isn't on my system since I installed nix through pacman. I don't have much experience with Nix yet, so I'm not sure how it identifies whether a given directory is a profile or not.

For my case, allowing to disable the nix upgrade-nix command through the configuration would be a viable workaround.

 2022-03-05T15:05:38.204Z DEBUG topgrade::config > Configuration at /home/korrat/.config/topgrade.toml
 2022-03-05T15:05:38.204Z DEBUG topgrade::config > Loaded configuration: ConfigFile { pre_commands: Some({}), post_commands: None, commands: Some({}), git_repos: None, predefined_git_repos: None, disable: Some([Flutter]), ignore_failures: None, remote_topgrades: None, remote_topgrade_path: None, ssh_arguments: None, git_arguments: None, tmux_arguments: None, set_title: None, assume_yes: None, yay_arguments: None, no_retry: None, run_in_tmux: None, cleanup: None, notify_each_step: None, accept_all_windows_updates: None, bashit_branch: None, only: None, composer: Some(Composer { self_update: None }), brew: Some(Brew { greedy_cask: None }), linux: Some(Linux { yay_arguments: None, arch_package_manager: None, show_arch_news: None, trizen_arguments: None, dnf_arguments: None, apt_arguments: None, enable_tlmgr: None, redhat_distro_sync: None, rpm_ostree: None, emerge_sync_flags: None, emerge_update_flags: None }), git: Some(Git { max_concurrency: None, arguments: None, repos: None, pull_predefined: None }), windows: Some(Windows { accept_all_updates: None, self_rename: None, open_remotes_in_new_terminal: None }), npm: None, vim: None, firmware: None, vagrant: None, flatpak: None }
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Detected "/usr/bin/notify-send" as "notify-send"
 2022-03-05T15:05:38.204Z DEBUG topgrade         > Version: 8.2.0
 2022-03-05T15:05:38.204Z DEBUG topgrade         > OS: x86_64-unknown-linux-gnu
 2022-03-05T15:05:38.204Z DEBUG topgrade         > Args { inner: ["topgrade", "--only", "nix", "--verbose"] }
 2022-03-05T15:05:38.204Z DEBUG topgrade         > Binary path: Ok("/usr/bin/topgrade")
 2022-03-05T15:05:38.204Z DEBUG topgrade         > Self Update: false
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Detected "/usr/bin/git" as "git"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Cannot find "doas"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Detected "/usr/bin/sudo" as "sudo"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Cannot find "pwsh"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Cannot find "powershell"
 2022-03-05T15:05:38.204Z DEBUG topgrade::runner > Step "nix"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Detected "/usr/bin/nix" as "nix"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Detected "/usr/bin/nix-channel" as "nix-channel"
 2022-03-05T15:05:38.204Z DEBUG topgrade::utils  > Detected "/usr/bin/nix-env" as "nix-env"

―― 16:05:38 - Nix ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
 2022-03-05T15:05:38.204Z DEBUG topgrade::steps::os::unix > Multi user nix: true
 2022-03-05T15:05:38.204Z DEBUG topgrade::executor        > Running "/usr/bin/sudo" "-i" "nix" "upgrade-nix"
error: directory '/usr/bin' does not appear to be part of a Nix profile
 2022-03-05T15:05:43.526Z DEBUG topgrade::runner          > Step "nix" failed: exit status: 1
 2022-03-05T15:05:43.526Z DEBUG topgrade::terminal        > Desktop notification: nix failed
 2022-03-05T15:05:38.204Z DEBUG topgrade::steps::os::unix > Multi user nix: true
 2022-03-05T15:05:38.204Z DEBUG topgrade::executor        > Running "/usr/bin/sudo" "-i" "nix" "upgrade-nix"
error: directory '/usr/bin' does not appear to be part of a Nix profile
 2022-03-05T15:05:43.526Z DEBUG topgrade::runner          > Step "nix" failed: exit status: 1
 2022-03-05T15:05:43.526Z DEBUG topgrade::terminal        > Desktop notification: nix failed

Retry? (y)es/(N)o/(s)hell
 2022-03-05T15:12:48.803Z DEBUG topgrade::utils           > Path "/home/korrat/.config/emacs" doesn't exist
 2022-03-05T15:12:48.803Z DEBUG topgrade::utils           > Path "/home/korrat/.emacs.d" doesn't exist
 2022-03-05T15:12:48.803Z DEBUG topgrade::steps::git      > /home/korrat/.ideavimrc does not exists
 2022-03-05T15:12:48.803Z DEBUG topgrade::steps::git      > /home/korrat/.intellimacs does not exists
 2022-03-05T15:12:48.803Z DEBUG topgrade::steps::git      > /home/korrat/dotfiles/roles/zsh/files/.zshrc is a file. Checking /home/korrat/dotfiles/roles/zsh/files
 2022-03-05T15:12:48.803Z DEBUG topgrade::steps::git      > Checking if /home/korrat/dotfiles/roles/zsh/files is a git repository
 2022-03-05T15:12:48.806Z TRACE topgrade::executor        > Output of "/usr/bin/git" "rev-parse" "--show-toplevel": Output { status: ExitStatus(unix_wait_status(0)), stdout: "/home/korrat/dotfiles\n", stderr: "" }
 2022-03-05T15:12:48.806Z DEBUG topgrade::steps::git      > /home/korrat/.config/fish does not exists
 2022-03-05T15:12:48.806Z DEBUG topgrade::steps::git      > /home/korrat/.config/openbox does not exists
 2022-03-05T15:12:48.806Z DEBUG topgrade::steps::git      > /home/korrat/.config/bspwm does not exists
 2022-03-05T15:12:48.806Z DEBUG topgrade::steps::git      > Checking if /home/korrat/.config/i3 is a git repository
 2022-03-05T15:12:48.808Z TRACE topgrade::executor        > Output of "/usr/bin/git" "rev-parse" "--show-toplevel": Output { status: ExitStatus(unix_wait_status(32768)), stdout: "", stderr: "fatal: Kein Git-Repository (oder irgendeines der Elternverzeichnisse): .git\n" }
 2022-03-05T15:12:48.808Z DEBUG topgrade::steps::git      > /home/korrat/.config/sway does not exists

―― 16:12:48 - Summary ――――――――――――――――――――――――――――――――――――――――――――――――――――――――――
nix: FAILED
 2022-03-05T15:12:48.811Z DEBUG topgrade::terminal        > Desktop notification: Topgrade finished with errors
Lord-Valen commented 2 years ago

As a workaround, disabling the Nix step and using a custom command ("Nix" = "/usr/bin/nix-channel --update && /usr/bin/nix-env --upgrade") will preserve the intent of the Nix step. Adding an option for whether Nix is part of a profile seems like a more permanent solution, but some logic that determines whether nix is part of a profile and then decides whether nix upgrade-nix should be used is preferred.

r-darwish commented 2 years ago

I don't use Nix so I'd be happy if someone can specify what needs to be done in order to determine whether the step should be skipped or not.

Lord-Valen commented 2 years ago

Use nix-env to check if nix is installed in a profile. Maybe also use it to check for a newer version of nix, so that we aren't upgrading to the same version? https://www.mankier.com/1/nix-env#Operation_--query

SuperSandro2000 commented 2 years ago

If nix-env --query does not list something like nix-2.8.0 nix upgrade-nix should not be run.

$ nix-env -q
nix-2.8.0
nix-bash-completions-0.6.8
nss-cacert-3.77