Trying to configure my system with home manager

Hi everyone! I’m new with Nix ecosystem.
I’m trying to config my new system using home-manager and flakes.

I try to following some tutorials and the manual of home-manager and nix.
To exemplify my situation:

I’m using Ubuntu; Installed Nix (2.22.1); home-manager (24.11-pre)
I created a new directory called dotfiles.
In this directory I have this files:

  • flake.nix
  • home.nix

My flake.nix has this content:

  description = "A simple flake";

  inputs = {
     nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
     home-manager.url = "github:nix-community/home-manager";
     home-manager.inputs.nixpkgs.follows = "nixpkgs";

  outputs = { self, nixpkgs, home-manager }: {

    defaultPackage.x86_64-linux = home-manager.defaultPackage.x86_64-linux;
    defaultPackage.x86_64-darwin = home-manager.defaultPackage.x86_64-darwin;

    homeConfigurations = {
       "myUsername" = home-manager.lib.homeManagerConfiguration {
        system = "x86_64";
        homeDirectory = "myHomeDirectory";
        username = "myUsername"; 
        modules = [ ./home.nix ];

Nice, now this is my home.nix content:

{ config, pkgs, ... }:

  # Home Manager needs a bit of information about you and the paths it should
  # manage.
  home.username = "MyUsername";
  home.homeDirectory = "myHomeDirectory";

  home.stateVersion = "24.05";

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = [

  # Home Manager is pretty good at managing dotfiles. The primary way to manage
  # plain files is through 'home.file'.
  home.file = {
    # # Building this configuration will create a copy of 'dotfiles/screenrc' in
    # # the Nix store. Activating the configuration will then make '~/.screenrc' a
    # # symlink to the Nix store copy.
    # ".screenrc".source = dotfiles/screenrc;

    # # You can also set the file content immediately.
    # ".gradle/".text = ''
    #   org.gradle.console=verbose
    #   org.gradle.daemon.idletimeout=3600000
    # '';

  home.sessionVariables = {
    EDITOR = "vim";

  # Let Home Manager install and manage itself.
  programs.home-manager.enable = true;


The problem is, when I try to run the command nix run . switch the output is that two strange messages:

warning: Git tree ‘/home/myHomeDirectory/dotfiles’ is dirty

No configuration file found. Please create one at /home/myHomeDirectory/.config/home-manager/home.nix

I running the command above inside of dotfiles directory, so in this place home.nix exists.

I tried to figure out what is happening without success. So if anyone could help me with that.

I’m guessing that you missed -- and --flake, nix run . -- switch --flake .

Where nix run . tells nix to run default package from flake in current directory
Turns out that default package in current directory will be your defaultPackage in flake.nix, and in your case is home-manager.

-- tell nix that nix command args ended and args after should be passed to whatever nix is trying to run (home-manager)
switch tells home-manager that you need to run switch command
--flake . that you want home-manager to switch to flake in current directory (could be a git or flake url instead). De default is a non flake in .config/home-manager/home.nix

to make it more clear this command should work:
nix run github:nix-community/home-manager -- switch --flake .
or if you have it in git

nix run github:nix-community/home-manager -- switch --flake github:MyUsername/dotfiles
nix run github:nix-community/home-manager -- switch --flake gitlab:MyUsername/dotfiles
nix run github:nix-community/home-manager -- switch --flake sourcehut:~MyUsername/dotfiles

Thanks! It works perfectly!