Problems configuring home-manager and home.nix according to tutorials on the web

home.nix:

{ config, pkgs, ... }:

{
  home.homeDirectory = "/home/ox0v0xo";
  home.username = "ox0v0xo";

  home.packages = with pkgs; [
    neofetch
  ];

  programs.git = {
    enable = true;
    userName = "ox0v0xo";
    userEmail = "3874005664@qq.com";
  };

  # Home Manager Version
  home.stateVersion = "24.11";

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

flake.nix:

{
  description = "ox0v0xo's NixOS flake.nix";

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

  outputs = inputs@{ self, nixpkgs, home-manager, ... }: {
    nixosConfigurations = {

      JINX = nixpkgs.lib.nixosSystem {
        system = "x86_64-linux";
        modules = [
          ./configuration.nix
          home-manager.nixosModules.home-manager {
            home-manager.useGlobalPkgs = true;
            home-manager.useUserPackages = true;
            home-manager.users.ox0v0xo = import ./home.nix;
          }
        ];
      };

    };
  };
}

configuration.nix:

{ config, pkgs, inputs, ... }:

{
  imports =
    [
      ./hardware-configuration.nix
    ];

  # Use the systemd-boot EFI boot loader
  boot.loader.efi.canTouchEfiVariables = true;
  boot.loader.systemd-boot.enable = true;

  # Set your time zone.
  time.timeZone = "Asia/Shanghai";

  # Select internationalisation properties
  i18n.defaultLocale = "en_US.UTF-8";

  # Define your hostname.
  networking.hostName = "JINX";

  # Enable networking
  networking.networkmanager.enable = true;

  # Enable the X11 windowing system.
  services.xserver.enable = true;

  # Enable the KDE Plasma Desktop Environment.
  services.displayManager.sddm.enable = true;
  services.xserver.desktopManager.plasma5.enable = true;

  # Enable CUPS to print documents.
  services.printing.enable = true;

  # Enable sound with pipewire.
  services.pipewire = {
    enable = true;
    pulse.enable = true;
  };

 # Enable the OpenSSH daemon.
  services.openssh = {
    enable = true;
    settings = {
      PasswordAuthentication = true;
      PermitRootLogin = "yes";
      Port = 22;
      X11Forwarding = true;
    };
  };

  # flake.nix
  nix.settings.experimental-features = [ "nix-command" "flakes" ];

  # Allow unfree packages
  nixpkgs.config.allowUnfree = true;

  # Nix Package
  environment.systemPackages = with pkgs; [
    curl
    fastfetch
    git
    tree
    wget
  ];

  # System Version
  system.stateVersion = "24.11";
}

All three files are under /etc/nixos/.

Just delete that line. The NixOS support module sets it already using your NixOS config (as well as home.username), you do not need to define this.

1 Like

Appreciate! It works!

Thanks for the detailed answer. I really appreciate you always linking additional information for novice users like me.

When I saw this question I thought the same but was a bit confused as users.users..home is supposed to default to /var/empty (which kind of makes sense after thinking about it a bit more) but after looking at the code it is clear now.

1 Like

I tried to make changes to reproduce the problem and found that this may be caused by another reason.

I remove the ‘configuration.nix’ about ‘Define User’ and then run 'sudo nixos-rebuild switch ’ then the problem occurs.

  # I deleted them by mistake.
  users.users.ox0v0xo = {
    isNormalUser = true;
    description = "ox0v0xo";
    extraGroups = [ "networkmanager" "wheel" ];
  };
error: The option `home-manager.users.ox0v0xo.home.homeDirectory' has conflicting definition values:
       - In `/nix/store/8vz84mqgnm1gz5yk7hgnnb5gir5hjxas-source/flake.nix': "/home/ox0v0xo"
       - In `/nix/store/0s5bx5a9565ialdjc688dar6lpz9d6bz-source/nixos/common.nix': "/var/empty"
       Use `lib.mkForce value` or `lib.mkDefault value` to change the priority on any of these definitions.

Yes, because this means that your user is not configured, which means that the default home directory becomes /var/empty. This then means that the value from your home config conflicts with the NixOS config, and you get that warning.

If you set up your user, however, the value changes to /home/<username> with higher priority, and therefore no error is shown.

Either way, you should be removing that home.homeDirectory for a home-manager config on NixOS - if only to prevent confusing errors.

1 Like