Hyprland error with Home Manager and Flakes

I’m a beginner and wanted to try Home Manager with flakes, I used the template configs from this repo. I configured the flake to manage the configuration.nix and the home.nix to use only nixos-rebuild switch, then tried to use Hyprland with flakes and import the module to Home Manager, but it gives me an error related to hyprland.conf saying “Existing file …/hypr/hyprland.conf is in the way of …” when I try to do the nixos-rebuild switch.

Here is the file tree:

.
├── flake.lock
├── flake.nix
├── home
│   ├── apps
│   │   ├── firefox
│   │   │   └── firefox.nix
│   │   ├── hyprland
│   │   │   └── hyprland.nix
│   │   └── waybar
│   │       ├── style.css
│   │       └── waybar.nix
│   ├── default.nix
│   ├── misc
│   │   └── wallpapers
│   │       └── wallpaper.png
│   └── scripts
│       ├── playerctl.sh
│       └── volume
├── home-manager
│   └── home.nix
├── modules
│   ├── home-manager
│   │   └── default.nix
│   └── nixos
│       └── default.nix
├── nixos
│   ├── configuration.nix
│   └── hardware-configuration.nix
├── overlays
│   └── default.nix
└── pkgs
    └── default.nix

My configuration.nix:

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

{
  imports =
    [ # Include the results of the hardware scan.
      ./hardware-configuration.nix
      inputs.home-manager.nixosModules.home-manager
    ];

  nixpkgs = {
    # You can add overlays here
    overlays = [
      # Add overlays your own flake exports (from overlays and pkgs dir):
      outputs.overlays.additions
      outputs.overlays.modifications
      outputs.overlays.unstable-packages

      # You can also add overlays exported from other flakes:
      # neovim-nightly-overlay.overlays.default

      # Or define it inline, for example:
      # (final: prev: {
      #   hi = final.hello.overrideAttrs (oldAttrs: {
      #     patches = [ ./change-hello-to-hi.patch ];
      #   });
      # })
    ];
    # Configure your nixpkgs instance
    config = {
      # Disable if you don't want unfree packages
      allowUnfree = true;
    };
  };

  nix = let
    flakeInputs = lib.filterAttrs (_: lib.isType "flake") inputs;
  in {
    settings = {
      # Enable flakes and new 'nix' command
      experimental-features = "nix-command flakes";
      # Opinionated: disable global registry
      flake-registry = "";
      # Workaround for https://github.com/NixOS/nix/issues/9574
      nix-path = config.nix.nixPath;
    };
    # Opinionated: disable channels
    #channel.enable = false;

    # Opinionated: make flake registry and nix path match flake inputs
    #registry = lib.mapAttrs (_: flake: {inherit flake;}) flakeInputs;
    #nixPath = lib.mapAttrsToList (n: _: "${n}=flake:${n}") flakeInputs;
  };

  # Bootloader.
  boot.loader.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  boot.initrd.luks.devices."luks-2a23b25c-f966-49a7-bd0b-fd56274e81f7".device = "/dev/disk/by-uuid/2a23b25c-f966-49a7-bd0b-fd56274e81f7";
  networking.hostName = "nixos"; # Define your hostname.
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.

  # Configure network proxy if necessary
  # networking.proxy.default = "http://user:password@proxy:port/";
  # networking.proxy.noProxy = "127.0.0.1,localhost,internal.domain";

  # Enable networking
  networking.networkmanager.enable = true;

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

  # Configure keymap in X11
  services.xserver.xkb = {
    layout = "us";
    variant = "";
  };

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users = {
     # Add users
     my-user = {
        isNormalUser = true;
	description = "my-user";
	extraGroups = [ "networkmanager" "wheel" ];
	openssh.authorizedKeys.keys = [
        # TODO: Add your SSH public key(s) here, if you plan on using SSH to connect
	];
	packages = with pkgs; [];
     };
  };

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
  #  vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
  #  wget
  git
  vim
  wget
  ];
  

  programs.hyprland.enable = true;
  environment.sessionVariables.NIXOS_OZONE_WL = "1";
  
  home-manager = {
    useUserPackages = true;
    extraSpecialArgs = { inherit inputs outputs; };
    users = {
      # Import your home-manager configuration
      my-user = import ../home-manager/home.nix;
    };
  };

  programs.zsh.enable = true;
  users.users.my-user.shell = pkgs.zsh;


  # Some programs need SUID wrappers, can be configured further or are
  # started in user sessions.
  # programs.mtr.enable = true;
  # programs.gnupg.agent = {
  #   enable = true;
  #   enableSSHSupport = true;
  # };

  # List services that you want to enable:

  # Enable the OpenSSH daemon.
  # services.openssh.enable = true;

  # Open ports in the firewall.
  # networking.firewall.allowedTCPPorts = [ ... ];
  # networking.firewall.allowedUDPPorts = [ ... ];
  # Or disable the firewall altogether.
  # networking.firewall.enable = false;

  # This value determines the NixOS release from which the default
  # settings for stateful data, like file locations and database versions
  # on your system were taken. It‘s perfectly fine and recommended to leave
  # this value at the release version of the first install of this system.
  # Before changing this value read the documentation for this option
  # (e.g. man configuration.nix or on https://nixos.org/nixos/options.html).
  system.stateVersion = "24.11"; # Did you read the comment?
}

My flake.nix:

{
  description = "My nix flake configuration to manage the system";
    
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs/nixos-24.11"; # NixOS release channel
    nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixos-unstable"; # NixOS unstable channel
    home-manager.url = "github:nix-community/home-manager/release-24.11"; # Home Manager release channel
    hyprland.url = "github:hyprwm/Hyprland";
  };
  
  outputs = { self, nixpkgs, home-manager, hyprland, ... } @inputs: 
    let 
    	inherit (self) outputs;
    	# Supported systems for your flake packages, shell, etc.
    	systems = [
	   "aarch64-linux"
	   "i686-linux"
	   "x86_64-linux"
	   "aarch64-darwin"
	   "x86_64-darwin"
	];
	# This is a function that generates an attribute by calling a function you
	# pass to it, with each system as an argument
	forAllSystems = nixpkgs.lib.genAttrs systems;
   in {
        # Your custom packages
        # Accessible through 'nix build', 'nix shell', etc
        packages = forAllSystems (system: import ./pkgs nixpkgs.legacyPackages.${system});
        # Formatter for your nix files, available through 'nix fmt'
        # Other options beside 'alejandra' include 'nixpkgs-fmt'
        formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);

        # Your custom packages and modifications, exported as overlays
        overlays = import ./overlays {inherit inputs;};
        # Reusable nixos modules you might want to export
        # These are usually stuff you would upstream into nixpkgs
        nixosModules = import ./modules/nixos;
        # Reusable home-manager modules you might want to export
        # These are usually stuff you would upstream into home-manager
        homeManagerModules = import ./modules/home-manager;

	# NixOS configuration entrypoint
	# Available through 'nixos-rebuild --flake .#your-hostname'
	nixosConfigurations = {
	  nixos = nixpkgs.lib.nixosSystem {
	     specialArgs = {inherit inputs outputs;};
              modules = [
	        # > Our main nixos configuration file <
		./nixos/configuration.nix
              ];
           };
        };
   };
}

My home.nix:

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

{
  # You can import other home-manager modules here
  imports = [
    # If you want to use modules your own flake exports (from modules/home-manager):
    # outputs.homeManagerModules.example

    # Or modules exported from other flakes (such as nix-colors):
    # inputs.nix-colors.homeManagerModules.default
    inputs.hyprland.homeManagerModules.default

    # You can also split up your configuration and import pieces of it here:
    # ./nvim.nix
    ../home 
  ];
  
  nixpkgs = {
    # You can add overlays here
    overlays = [
      # Add overlays your own flake exports (from overlays and pkgs dir):
      outputs.overlays.additions
      outputs.overlays.modifications
      outputs.overlays.unstable-packages

      # You can also add overlays exported from other flakes:
      # neovim-nightly-overlay.overlays.default

      # Or define it inline, for example:
      # (final: prev: {
      #   hi = final.hello.overrideAttrs (oldAttrs: {
      #     patches = [ ./change-hello-to-hi.patch ];
      #   });
      # })
    ];
    # Configure your nixpkgs instance
    config = {
      # Disable if you don't want unfree packages
      allowUnfree = true;
    };
  };

  home = {
    username = "my-user";
    homeDirectory = "/home/my-user";
  };

  # Add stuff for your user as you see fit:
  # programs.neovim.enable = true;
  # home.packages = with pkgs; [ steam ];
  home.packages = [
     pkgs.tree
     pkgs.unstable.mako
     pkgs.unstable.zip
     pkgs.unstable.xz
     pkgs.unstable.unzip
     pkgs.unstable.brightnessctl
     pkgs.unstable.neovim
     pkgs.unstable.pamixer
     pkgs.unstable.font-awesome
     pkgs.unstable.powerline-fonts
     pkgs.unstable.powerline-symbols
     pkgs.hyprpaper
     pkgs.iosevka
     pkgs.noto-fonts-cjk-sans
     (pkgs.nerdfonts.override { fonts = [ 
	"FiraCode"
	"NerdFontsSymbolsOnly"
	];})
  ];

  # configuration of zsh
  programs.zsh = {
    enable = true;
    enableCompletion = true;
    autosuggestion.enable = true;
    syntaxHighlighting.enable = true;
    shellAliases = {
      update = "sudo nixos-rebuild switch";
    };
    history = {
      size = 10000;
      path = "${config.xdg.dataHome}/zsh/history";
    };
    oh-my-zsh = {
      enable = true;
      theme = "robbyrussell";
    };
  };

  programs.kitty.enable = true; 
  #Optional, hint Electron apps to use Wayland:
  home.sessionVariables.NIXOS_OZONE_WL = "1";

  # Enable home-manager and git
  programs.home-manager.enable = true;
  programs.git.enable = true;

  # Nicely reload system units when changing configs
  systemd.user.startServices = "sd-switch";

  # https://nixos.wiki/wiki/FAQ/When_do_I_update_stateVersion
  home.stateVersion = "24.11";
}

My hyprland.nix that is imported as ../home in home.nix imports:

{ pkgs, lib, config, ...} :

{
   home.file.".config/hypr/hyprpaper.conf".text = ''
      preload = ${../../misc/wallpapers/wallpaper.png}
      wallpaper = ,${../../misc/wallpapers/wallpaper.png}
      ipc = off
   '';

   wayland.windowManager.hyprland = {
      enable = true;
      systemd.enable = true;
      extraConfig = let
      modifier = "SUPER";
      in lib.strings.concatStrings [
        '' '' 
         ... configuration
       '' ''
       ];};
}

And the error produced by running the command journalctl -xe --unit home-manager-my-user.service:

Dec 17 19:57:48 nixos hm-activate-my-user[128691]: Starting Home Manager activation
Dec 17 19:57:48 nixos hm-activate-my-user[128691]: Activating checkFilesChanged
Dec 17 19:57:48 nixos hm-activate-my-user[128691]: Activating checkLinkTargets
Dec 17 19:57:49 nixos hm-activate-my-user[128718]: Existing file '/home/my-user/.config/hypr/hyprland.conf' is in the way of '/nix/store/d8kd5dzlc6>
Dec 17 19:57:49 nixos hm-activate-my-user[128718]: Please do one of the following:
Dec 17 19:57:49 nixos hm-activate-my-user[128718]: - Move or remove the above files and try again.
Dec 17 19:57:49 nixos hm-activate-my-user[128718]: - In standalone mode, use 'home-manager switch -b backup' to back up
Dec 17 19:57:49 nixos hm-activate-my-user[128718]:   files automatically.
Dec 17 19:57:49 nixos hm-activate-my-user[128718]: - When used as a NixOS or nix-darwin module, set
Dec 17 19:57:49 nixos hm-activate-my-user[128718]:     'home-manager.backupFileExtension'
Dec 17 19:57:49 nixos hm-activate-my-user[128718]:   to, for example, 'backup' and rebuild.
Dec 17 19:57:49 nixos systemd[1]: home-manager-my-user.service: Main process exited, code=exited, status=1/FAILURE

I tried to delete the ~/.config/hypr directory and hyprland.conf file with no luck.

That bit creates a hypr directory for you, while the wayland.windowManager.hyprland module expects to exclusively manage it. You can’t do that.

Does the hyprpaper config actually need to be in that directory? If it does, you’ll have to take this upstream, it’s a bug.

2 Likes

I see, I think yes, that file has to be in hypr, but removing the directory and the lines of the home.file.".config/hypr/hyprpaper.conf".text, running nixos-rebuild switch, then adding again the lines of home.file.".config/hypr/hyprpaper.conf".text and running again nixos-rebuild switch appears to have solved the issue, even when I modify again the hyprland.nix contents. Thank you so much.

Another option is to use the home-manager hyprpaper settings, i.e… replace home.file.".config/hypr/hyprpaper.conf".text with something like:

    hyprpaper = {
      enable = true;
      settings = {
        ipc = "off";
        preload = ["${wallpaper_file}"];
        wallpaper = [ ",${wallpaper_file}"
        ];
      };
    };
1 Like

That also worked, thank you so much.