Help moving away from home.nix to flake.nix

Hi all,

I use Nix + Home Manager on a different GNU/Linux flavor.

I started my learning of Nix Flakes and came out with the following simple flake.nix , which isn’t working, and I can’t understand what is wrong:

{
  # Description of the flake
  description = "CLI apps and tools";

  # Define inputs (Nix packages and channels)
  inputs = {
    # Nixpkgs channel with unstable version
    nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
    # Home Manager from community repository
    home-manager = {
      url = "github:nix-community/home-manager";
      inputs.nixpkgs.follows = "nixpkgs";
    };
  };

  # Define outputs (build results)
  outputs = { self, pkgs, home-manager }: {
      # Home Manager configuration
      homeManagerConfig = {
        config, pkgs, ... }: {
          # User information
          home.username = "cig0";
          home.homeDirectory = "/home/cig0";
          home.stateVersion = "24.05";

          # Enable Home Manager and set options
          programs.home-manager.enable = true;
          # ... (Uncomment other programs and configurations as needed)

          # Install desired packages
          home.packages = with pkgs; [
            # ... (Add desired packages from your current config)
            #ansible # Using Universal Blue's package
            argocd
            atuin
            awscli2
            bat
            bitlbee
            bitlbee-discord
            borgbackup
            btop
            chezmoi
            cargo
            chit
            cosign
            crc
            delta
            discordo
            difftastic
            dnstracer
            du-dust
            dua
            duf
            dysk
            eksctl
            exiftool
            fd
            fdupes
            fx
            fzf
            gh
            git-lfs
            glab
            glances
            go
            goaccess
            golangci-lint
            golangci-lint-langserver
            gopls
            grpcurl
            gum
            httpie
            hugo
            hyperfine
            inetutils
            inxi
            iotop
            k9s
            kind
            krew
            kube-bench
            kubecolor
            kubectl
            kubernetes-helm
            kubeswitch
            lazygit
            lf
            lftp
            lnav
            lynis
            lurk
            mc
            minikube
            moar
            ncdu
            neofetch
            #neovim # Using Fedora's package
            nerdctl
            nfstrace
            nixfmt
            nmap
            nodejs_latest
            nushell
            nvitop
            oath-toolkit
            oh-my-posh
            ocm
            odo
            ookla-speedtest
            opentofu
            packer
            podman-compose
            powertop
            python312Packages.yamllint
            qrscan
            ripgrep
            rust-analyzer
            rust-petname
            rustc
            rustfmt
            rustscan
            rustycli
            s-tui
            shellcheck
            sops
            strace
            strace-analyzer
            tcpdump
            telepresence2
            terraformer
            tesseract
            tf-summarize
            tflint
            tfsec
            tfswitch
            todoist
            tokei
            translate-shell
            ugrep
            vagrant
            vdpauinfo
            vt-cli
            weechat
            wiki-tui
            wl-clipboard
            yamlfmt
            zola
            zoxide
          ];

          # Enable generic Linux environment variables
          targets.genericLinux.enable = true;
        };
      };
}

I intend to split the flake into other flakes to install the tooling and set environments based on the hostname. However, I first need to get this flake working!

This is the error message I’m getting when nix build .:

       … while updating the flake input 'pkgs'

       error: cannot find flake 'flake:pkgs' in the flake registries

Thanks!

The immediate issue you’re facing is that the arguments to the function assigned to outputs should match the names provided in the inputs section. So in your case if you change that from pkgs to nixpkgs it should get past that error. There may be others that you encouter after that though.

I just noticed I never got back to you :man_facepalming:

Thanks a ton for your help. Yesterday, I finally bit the bullet and started migrating one of my systems (my laptop) to NixOS. It was only after reading this topic that I realized now how much I was missing by using Nix only as a mere CLI apps provider :sweat_smile:

NixOS is incredible; I can’t get enough of it. And, of course, kudos to the whole community: the vibe around here and /r/NixOS is excellent, and resources like https://search.nixos.org and https://nixos.wiki have proved incredibly useful for me when learning how to start configuring things :rocket:

I hope to see you around!

I see you’ve probably solved it by now. But in case it wasn’t obvious:

Referring to the home-manager manual on Flake usage for standalone home-manager usage,
and the template it suggests to use,

your code has the shape:

{
  ....
  outputs = { self, ... }: {
    homeManagerConfig = { config, pkgs, ... }: {
      ....
    }
  }
}

whereas the template has a shape something like:

{
  ....
  outputs = { self, ... }: {
    homeConfigurations = {
      jdoe = home-manager.lib.homeManagerConfiguration {
       modules = [
          ({ config, pkgs, ... }: {
           ....
          })
       ]
       ....
      }
    }
  }
}

You’re assigning a module to homeManagerConfig attribute of the outputs return value, but home manager is looking for homeConfigurations.jdoe for an application of home-manager.lib.homeManagerConfiguration (& you pass in your home manager module or home.nix to the modules argument of that application).

1 Like

No worries, glad that you’re getting things up and running. If you have any follow up questions feel free to post them here, I and I’m sure many other will be happy to help.

1 Like

Thanks a bunch for taking the time to drop this note! I haven’t had a chance to dig into it yet, but now that I’m rolling with NixOS, I’m all about doing things correctly. Your breakdown of the Home Manager setup makes total sense, and I’m stoked to check out that template you mentioned. I appreciate you pointing me in the right direction!