Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: extra arguments for Home Manager #507

Merged
merged 2 commits into from
Jul 24, 2023

Conversation

SteveLauC
Copy link
Member

Standards checklist:

  • The PR title is descriptive.
  • I have read CONTRIBUTING.md
  • The code compiles (cargo build)
  • The code passes rustfmt (cargo fmt)
  • The code passes clippy (cargo clippy)
  • The code passes tests (cargo test)
  • Optional: I have tested the code myself
    • I also tested that Topgrade skips the step where needed

If you developed a feature or a bug fix for someone else and you do not have the
means to test it, please tag this person here.


What does this PR do

  1. Add a config entry, enabling users to add extra arguments to Home Manager, closes NixOS Home-Manager Flake support #497

@SteveLauC
Copy link
Member Author

@NovaViper Here is a buiid for x86_64-unknown-linux-musl(executable on NixOS, seems like you are a NixOS user), would you like to give it a test?

@NovaViper
Copy link

NovaViper commented Jul 23, 2023

Hey sorry for the delay! I just got around to setting up NixOS again, however I can't figure out how to get the package working because of a cargo hash mismatch.. I'm unsure of how to resolve it because the cargo lock itself hasn't changed but I think the updates made in the main branch in the last few days may have changed it?

my override settings

    topgrade = prev.topgrade.overrideAttrs (oldAttrs: rec {
      version = "12.0.0";
      src = final.fetchFromGitHub {
        owner = "SteveLauC";
        repo = "topgrade";
        rev = "42188af02b9073598af284fe6aeac095c354fec1";
        sha256 = "04vdbfngp4aw2bdqqlqa2l8xw1lng967iwbpmrg7mcq6x8r30f1c";
      };
      /*cargoDeps = oldAttrs.cargoDeps.overrideAttrs (attrs: {
        inherit src;
        outputHash = "";
      });*/
    });

The error

       > Cargo.lock is not the same in /build/topgrade-12.0.0-vendor.tar.gz
       >
       > To fix the issue:
       > 1. Set cargoHash/cargoSha256 to an empty string: `cargoHash = "";`
       > 2. Build the derivation and wait for it to fail with a hash mismatch
       > 3. Copy the "got: sha256-..." value back into the cargoHash field
       >    You should have: cargoHash = "sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=";
       >
       For full logs, run 'nix log /nix/store/xivivah7a058j8iflbkx3aby9f3r4s63-topgrade-12.0.0.drv'.

@SteveLauC
Copy link
Member Author

Hey sorry for the delay! I just got around to setting up NixOS again, however I can't figure out how to get the package working because of a cargo hash mismatch.. I'm unsure of how to resolve it because the cargo lock itself hasn't changed but I think the updates made in the main branch in the last few days may have changed it?

my override settings


    topgrade = prev.topgrade.overrideAttrs (oldAttrs: rec {

      version = "12.0.0";

      src = final.fetchFromGitHub {

        owner = "SteveLauC";

        repo = "topgrade";

        rev = "42188af02b9073598af284fe6aeac095c354fec1";

        sha256 = "04vdbfngp4aw2bdqqlqa2l8xw1lng967iwbpmrg7mcq6x8r30f1c";

      };

      /*cargoDeps = oldAttrs.cargoDeps.overrideAttrs (attrs: {

        inherit src;

        outputHash = "";

      });*/

    });

The error


       > Cargo.lock is not the same in /build/topgrade-12.0.0-vendor.tar.gz

       >

       > To fix the issue:

       > 1. Set cargoHash/cargoSha256 to an empty string: `cargoHash = "";`

       > 2. Build the derivation and wait for it to fail with a hash mismatch

       > 3. Copy the "got: sha256-..." value back into the cargoHash field

       >    You should have: cargoHash = "sha256-XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX=";

       >

       For full logs, run 'nix log /nix/store/xivivah7a058j8iflbkx3aby9f3r4s63-topgrade-12.0.0.drv'.

Emm, I know that NixOS is immutable, but do you have to test it via nix? Downloading the binary and executing it should work?

@NovaViper
Copy link

NovaViper commented Jul 23, 2023

That did it! I ran it with the binrary and it did input the arguments into the command but did it in such a way that it made the script crash with this error:

── 21:13:29 - home-manager ─────────────────────────────────────────────────────
/etc/profiles/per-user/novaviper/bin/home-manager: unknown option '--flake ./Desktop/nix-config'
Run '/etc/profiles/per-user/novaviper/bin/home-manager --help' for usage help
home-manager failed:
   0: Command failed: `/etc/profiles/per-user/novaviper/bin/home-manager switch '--flake ./Desktop/nix-config'`
   1: `/etc/profiles/per-user/novaviper/bin/home-manager` failed: exit status: 1

Location:
   src/steps/os/unix.rs:453

My Configuration

[commands]
"Run garbage collection on Nix store" = "nix-collect-garbage"

[linux]
nix_arguments = "--flake ./Desktop/nix-config"

[misc]
cleanup = true
home_manager_arguments = "--flake ./Desktop/nix-config"
pre_sudo = true
skip_notify = false

Also I do have a suggestion real quick, would it be possible to move the home manager arguments line to be under the linux settings instead of misc? Would make sense since the nix arguments are under that category

@SteveLauC
Copy link
Member Author

Not familiar with nix, seems the error is complaining about that "--flake" and "./Desktop/nix-config" should be two arguments instead of one.

Executing "home-manager switch --flake ./Desktop/nix-config" in your shell will work, right?

And, suggestion received:)

@NovaViper
Copy link

NovaViper commented Jul 23, 2023

Not familiar with nix, seems the error is complaining about that "--flake" and "./Desktop/nix-config" should be two arguments instead of one.

Executing "home-manager switch --flake ./Desktop/nix-config" in your shell will work, right?

Executing the command with it surrounded by " " like "home-manager switch --flake ./Desktop/nix-config" makes my shell complain that it's not a file. But I ran the command like this home-manager switch --flake './Desktop/nix-config', home-manager switch --flake "./Desktop/nix-config" makes it run. I think it's just a simple truncation issue with bash/zsh that's making it go crazy

And, suggestion received:)

Thank you! 👍🏾

@SteveLauC
Copy link
Member Author

SteveLauC commented Jul 23, 2023

Would u like to try this in your shell:

$ home-manager switch '--flake' './Desktop/nix-config'

And, from your configuration file, it seems nix_arguments does not have such an issue:

$ nix some-command '--flake ./Desktop/nix-config'

kinda weird...

@NovaViper
Copy link

Would u like to try this in your shell:

$ home-manager switch '--flake' './Desktop/nix-config'

This works!

And, from your configuration file, it seems nix_arguments does not have such an issue:

$ nix some-command '--flake ./Desktop/nix-config'

kinda weird...

Actually, when I run it like this nixos-rebuild switch '--flake ./Desktop/nix-config' (this is the command used to rebuild the NixOS config), it also results in the same errors like with running it the same way with home manager. Additionally when running it like with the other cases '--flake' 'directory-path', --flake 'directory-path', "--flake" "directory-path" and --flake "directory-path", runs fine

@SteveLauC
Copy link
Member Author

Then the configuration entry should be an array of string:

[linux]
home_mamager_arguments = ["--flake", "file"]

@SteveLauC
Copy link
Member Author

@NovaViper
Copy link

NovaViper commented Jul 24, 2023

New build: https://github.com/SteveLauC/topgrade/releases/tag/home-manager-extra-args

@NovaViper Welcome to give it a try:)

EDIT
Ah my mistake, I had the arguments in the wrong place, giving it another test now.

EDIT 2
It works perfectly! Thanks for getting this added!

@NovaViper
Copy link

Huh, one pecuilar thing is now when I run it also, it runs the oh-my-zsh script instead of zplug (even though I don't have oh-my-zsh, I run zplug instead)

@SteveLauC
Copy link
Member Author

Huh, one pecuilar thing is now when I run it also, it runs the oh-my-zsh script instead of zplug (even though I don't have oh-my-zsh, I run zplug instead)

Would you like to elaborate on this? I don't quite get it :<

@NovaViper
Copy link

Huh, one pecuilar thing is now when I run it also, it runs the oh-my-zsh script instead of zplug (even though I don't have oh-my-zsh, I run zplug instead)

Would you like to elaborate on this? I don't quite get it :<

Ah wait, this also happens with the latest version (v12.0.1). It seems like the commands thinks my system is running the oh-my-zsh framework since I'm using ZSH; but I'm actually running Zplug (oh-my-zsh isn't installed on my system at all). So it should be running the zplug step instead of the oh-my-zsh one.

@SteveLauC
Copy link
Member Author

SteveLauC commented Jul 24, 2023

I get it.

Would you like to provide the output of

$ topgrade --verbose --dry-run

and

$ echo $ZSH

here

@SteveLauC
Copy link
Member Author

And, for this oh-my-zsh issue, opening another issue for it would be great.

Since this patch solves your problem, I will merge it.

@SteveLauC SteveLauC merged commit 635bfce into topgrade-rs:master Jul 24, 2023
8 checks passed
@SteveLauC SteveLauC deleted the nix-home-manager branch July 24, 2023 05:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

NixOS Home-Manager Flake support
2 participants