nh icon indicating copy to clipboard operation
nh copied to clipboard

Do you really mean flakeref?

Open spikespaz opened this issue 8 months ago • 3 comments

The usage in help asks for a FLAKEREF argument.

Usage: nh home build [OPTIONS] <FLAKEREF> [-- <EXTRA_ARGS>...]

Arguments:
  <FLAKEREF>
          Flake reference to build

Here are two examples where I provide a flakeref in the style of home-manager and nixos-rebuild shorthand.

jacob@odyssey ~/d/odyssey (odyssey) [1]> nh home build path:.#jacob@odyssey
error: getting status of '/home/jacob/dotfiles.git/odyssey/path:.': No such file or directory
Error:
   0: Failed to parse nix-eval output:

Location:
   src/home.rs:204
jacob@odyssey ~/d/odyssey (odyssey) [1]> nh home build .#jacob@odyssey
warning: Git tree '/home/jacob/dotfiles.git/odyssey' is dirty
error: flake 'git+file:///home/jacob/dotfiles.git/odyssey' does not provide attribute 'packages.x86_64-linux.jacob@odyssey#homeConfigurations', 'legacyPackages.x86_64-linux.jacob@odyssey#homeConfigurations' or 'jacob@odyssey#homeConfigurations'
Error:
   0: Failed to parse nix-eval output:

Location:
   src/home.rs:204

Desperately, I try to provide the full attribute in said flakeref:

jacob@odyssey ~/d/odyssey (odyssey) [1]> nh home build path:.#homeConfigurations."jacob@odyssey"
error: getting status of '/home/jacob/dotfiles.git/odyssey/path:.': No such file or directory
Error:
   0: Failed to parse nix-eval output:

Location:
   src/home.rs:204

spikespaz avatar May 02 '25 18:05 spikespaz

Please send the output with --verbose

viperML avatar May 02 '25 20:05 viperML

I'm seeing the same thing.

home-manager switch --flake ~/dotfiles/nix-conf/home#dmorgan works, but:

 $ nh home switch ~/dotfiles/nix-conf/home#dmorgan --verbose                                                                                                                  
 > Building Home-Manager configuration                                                                                                                                        
 error: flake 'git+file:///Users/dmorgan/dotfiles?dir=nix-conf/home' does not provide attribute 'packages.aarch64-darwin.dmorgan', 'legacyPackages.aarch64-darwin.dmorgan' or 'dmorgan'                                                                                                                                                                      ┏━ 1 Errors:                                                                                                                                                                 
 ┃ error: flake 'git+file:///Users/dmorgan/dotfiles?dir=nix-conf/home' does not provide attribute 'packages.aarch64-darwin.dmorgan', 'legacyPackages.aarch64-darwin.dmorgan' or 'dmorgan'                                                                                                                                                                    ┣━━━                                                                                                                                                                         
 ┗━ ∑ ⚠ Exited with 1 errors reported by nix at 13:39:25 after 0s                                                                                                             
 Error:                                                                                                                                                                       
    0: Failed to build Home-Manager configuration                                                                                                                             
    1: Command exited with status Exited(1)                                                                                                                                   
                                                                                                                                                                              
 Location:                                                                                                                                                                    
    src/commands.rs:462  

Is this a problem with what I/we are doing, or is it a bug?

In case it helps, the flake looks like this:

{
  description = "Home Manager config";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
    nixpkgs-unstable.url = "github:nixos/nixpkgs/nixos-unstable";
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    sops-nix = {
      url = "github:Mic92/sops-nix";
      inputs.nixpkgs.follows = "nixpkgs";
    };
    darwin-system-certs = {
      url = "/private/etc/ssl/cert.pem";
      flake = false;
    };
  };

  outputs =
    { nixpkgs, nixpkgs-unstable, home-manager, sops-nix, ... }@inputs:
    let
      system = "aarch64-darwin";
      pkgs = nixpkgs.legacyPackages.${system};
      overlay-unstable = final: prev: {
        unstable = nixpkgs-unstable.legacyPackages.${system};
      };
    in
    {
      homeConfigurations."dmorgan" = home-manager.lib.homeManagerConfiguration {
        inherit pkgs;
        extraSpecialArgs = { inherit inputs system; };
        modules = [
          ({ config, pkgs, ...  }: { nixpkgs.overlays = [ overlay-unstable ]; })
          ./otm.nix
        ];
      };
    };
}

(I realise that at the moment, the #dmorgan isn't required, but I think it will be when I migrate more systems to this flake. nh home switch ~/dotfiles/nix-conf/home does work. I'm currently working to migrate various systems over to flakes, so may well be doing things wrong).

deejayem avatar Jul 24 '25 12:07 deejayem

@deejayem nh doesn't use nh home switch flake#username, but instead nh home switch flake -c username

viperML avatar Jul 26 '25 16:07 viperML