Ln: failed to create symbolic link '/nix/store/***-user-units/xdg-desktop-portal-gtk.service' : File exists

Hi
I’ve recently tried to install via flake the Zen browser, but since then trying I get the following error when rebuilding (using sudo nixos-rebuild switch --flake /etc/nixos/#default --impure):

error: builder for '/nix/store/qapc7iiazgzd3i61i2gklm3w9qigp7ba-user-units.drv' failed with exit code 1;
       last 1 log lines:
       > ln: failed to create symbolic link '/nix/store/yhc097ggn5bga30fdpxaba8l55s5mv3n-user-units/xdg-desktop-portal-gtk.service': File exists
       For full logs, run 'nix log /nix/store/qapc7iiazgzd3i61i2gklm3w9qigp7ba-user-units.drv'.
error: 1 dependencies of derivation '/nix/store/j7zdnw18y88n1kzqjckl60nj3axd3a87-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/y8hwz6j8nvknvilay0z1lzkq6jpm5l9h-nixos-system-nixos-24.11.20241001.27e30d1.drv' failed to build

nix log /nix/store/qapc7iiazgzd3i61i2gklm3w9qigp7ba-user-units.drv doesn’t give any additionnal informations.

Since then I have removed anything related to the Zen browser, so it’s probably not related since the problem persist.

The only lines related to xdg-desktop-portal in my confirguration.nix are:

  xdg.portal.enable = true;
  xdg.portal.extraPortals = [pkgs.xdg-desktop-portal-gtk];

Removing them doesn’t change anything, only change is when i put xdg.portal.enable to false, as gnome already declare it at true.

I’ve tried:

  • sudo nix-collect-garbage -d
  • nix store delete /nix/store/***-user-units/xdg-desktop-portal-gtk.service
  • sudo nixos-rebuild switch --flake /etc/nixos/#default --impure --repair

Without any success sadly.
Internet did not found any similar problems.

While I’ve been using Linux for some time now, I am very new to NixOS, and to be honest, quite lost.

nix-shell -p nix-info --run "nix-info -m" outputs:

 - system: `"x86_64-linux"`
 - host os: `Linux 6.6.52, NixOS, 24.11 (Vicuna), 24.11.20240929.06cf0e1`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.18.8`
 - nixpkgs: `/nix/store/r2hk87rfvc5fpfbl2bj64a3x7mcq9f6c-source`

Any help would be appreciated!

Some general advice:

  • garbage collection is not a troubleshooting tool in general, it simply makes rebuilds take longer
  • deleting store paths - same thing, and it won’t work if the path is “live” (i.e. if the path wouldn’t get caught by garbage collection, then deleting the store path this way won’t work either)
  • avoid --impure. --repair is fine if there’s corruption on your disk but probably won’t help here

If you’re truly stuck, rather than trying the steps above, you’re welcome to ask here, but please - share your config, we cannot guess what you have in your config.

1 Like

Thanks a lot for the advices, --impure was there because my home-confirguration was in my home directory, I think Im gonna change that.

Yeah sorry, here is my configuration.nix

# Edit this configuration file to define what should be installed on
# your system.  Help is available in the configuration.nix(5) man page
# and in the NixOS manual (accessible by running ‘nixos-help’).

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

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

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

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

  # Stylix
  stylix.image = "/home/apoleon/Téléchargements/wallpaper.jpg";

  # Hyprland
  programs.hyprland = {
    enable = true;
    xwayland.enable = true;
  };

  xdg.portal.enable = true;
  xdg.portal.extraPortals = [pkgs.xdg-desktop-portal-gtk];

  environment.sessionVariables = {
    # If your cursor becomes invisible
    WLR_NO_HARDWARE_CURSORS = "1";
    # Hint electron apps to use wayland
    NIXOS_OZONE_WL = "1";
  };

  hardware = {
      #Opengl
      graphics.enable = true;

      #Most wayland compositors need this
      nvidia.modesetting.enable = true;
  };

  # Set your time zone.
  time.timeZone = "Europe/Paris";

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

  i18n.extraLocaleSettings = {
    LC_ADDRESS = "fr_FR.UTF-8";
    LC_IDENTIFICATION = "fr_FR.UTF-8";
    LC_MEASUREMENT = "fr_FR.UTF-8";
    LC_MONETARY = "fr_FR.UTF-8";
    LC_NAME = "fr_FR.UTF-8";
    LC_NUMERIC = "fr_FR.UTF-8";
    LC_PAPER = "fr_FR.UTF-8";
    LC_TELEPHONE = "fr_FR.UTF-8";
    LC_TIME = "fr_FR.UTF-8";
  };

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

  # Enable the GNOME Desktop Environment.
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.desktopManager.gnome.enable = true;

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

  # Configure console keymap
  console.keyMap = "fr";

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

  # Enable sound with pipewire.
  hardware.pulseaudio.enable = false;
  security.rtkit.enable = true;
  services.pipewire = {
    enable = true;
    alsa.enable = true;
    alsa.support32Bit = true;
    pulse.enable = true;
    # If you want to use JACK applications, uncomment this
    #jack.enable = true;

    # use the example session manager (no others are packaged yet so this is enabled by default,
    # no need to redefine it in your config for now)
    #media-session.enable = true;
  };

  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.apoleon = {
    isNormalUser = true;
    description = "simon";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
    #  thunderbird
    ];
  };

home-manager = {
  # also pass inputs to home-manager modules
  extraSpecialArgs = {inherit inputs;};
  users = {
    "apoleon" = import /home/apoleon/nixos/home.nix;
  };
};

  #FISH?
  programs.fish = {
    enable = true;
    shellInit = "
      set -g fish_greeting
      # Alternative (blocks terminal for 0-3ms)
      cat ~/.cache/wal/sequences

      fastfetch \n
      starship init fish | source
    ";
    shellAliases = {
      "..." = "cd ../..";
      "home-manual" = "man home-configuration.nix";
      "rebuild" = "sudo nixos-rebuild switch --flake /etc/nixos/#default --impure";
      "cleanup" = "sudo nix-collect-garbage --delete-older-than";
      "update" = "cd /etc/nixos && sudo nix flake update";
    };
  };

  # Install firefox.
  programs.firefox.enable = true;

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

  programs.steam = { enable = true; remotePlay.openFirewall = true; dedicatedServer.openFirewall = true; }; 

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
   vscode
   discord
   alacritty
   fastfetch
   amberol
   waybar
   mako
   libnotify
   kitty
   rofi-wayland
   hyprcursor
   swww
   wofi

   inputs.rose-pine-hyprcursor.packages.${pkgs.system}.default

   jetbrains.clion
   cmake
   gcc
   nerdfonts
   git

   pywal
   htop

   inputs.zen-browser.packages."${system}".default
  ];

  # 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;

  services.xserver.displayManager.setupCommands = ''
  ${pkgs.numlockx}/bin/numlockx on
'';

  # 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.05"; # Did you read the comment?

}

my hardware-configuration.nix:

# Do not modify this file!  It was generated by ‘nixos-generate-config’
# and may be overwritten by future invocations.  Please make changes
# to /etc/nixos/configuration.nix instead.
{ config, lib, pkgs, modulesPath, ... }:

{
  imports =
    [ (modulesPath + "/installer/scan/not-detected.nix")
    ];

  boot.initrd.availableKernelModules = [ "xhci_pci" "ahci" "nvme" "usb_storage" "sd_mod" ];
  boot.initrd.kernelModules = [ ];
  boot.kernelModules = [ "kvm-intel" ];
  boot.extraModulePackages = [ ];

  fileSystems."/" =
    { device = "/dev/disk/by-uuid/bbd4ea75-1050-4fc8-87af-b89836cc0873";
      fsType = "ext4";
    };

  fileSystems."/boot" =
    { device = "/dev/disk/by-uuid/EE07-C881";
      fsType = "vfat";
      options = [ "fmask=0077" "dmask=0077" ];
    };
  
  fileSystems."/data" = 
    {
      device = "/dev/disk/by-uuid/EEFC7C72FC7C3745";
      fsType = "ntfs";
    };

  swapDevices = [
    {
      device = "/data/swapfile";
      size = 3 * 1024; # 3.5G
    }
  ];

  # Enables DHCP on each ethernet and wireless interface. In case of scripted networking
  # (the default) this is the recommended approach. When using systemd-networkd it's
  # still possible to use this option, but it's recommended to use it in conjunction
  # with explicit per-interface declarations with `networking.interfaces.<interface>.useDHCP`.
  networking.useDHCP = lib.mkDefault true;
  # networking.interfaces.enp3s0.useDHCP = lib.mkDefault true;
  # networking.interfaces.wlp4s0.useDHCP = lib.mkDefault true;

  nixpkgs.hostPlatform = lib.mkDefault "x86_64-linux";
  hardware.cpu.intel.updateMicrocode = lib.mkDefault config.hardware.enableRedistributableFirmware;
}

My flake.nix:

{
  description = "Nixos config flake";

  inputs = {
    nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";

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

      hyprland.url = "git+https://github.com/hyprwm/Hyprland?submodules=1";

      hyprland-plugins = {
        url = "github:hyprwm/hyprland-plugins";
        inputs.hyprland.follows = "hyprland";
      };

     stylix.url = "github:danth/stylix";

     rose-pine-hyprcursor.url = "github:ndom91/rose-pine-hyprcursor";
     
     zen-browser.url = "github:MarceColl/zen-browser-flake";

  };

  outputs = { self, nixpkgs, ... }@inputs: {
    nixosConfigurations.default = nixpkgs.lib.nixosSystem {
      specialArgs = {inherit inputs;};
      modules = [
        ./configuration.nix
        inputs.home-manager.nixosModules.default
        inputs.stylix.nixosModules.stylix
      ];
    };
  };
}

Thanks for the reply!

Are you trying to have GNOME and plasma enabled simultaneously? If so: Build failure: adding xdg-desktop-portal-gtk conflicts with GNOME's implementation · Issue #345733 · NixOS/nixpkgs · GitHub

1 Like

While I was not trying to have both GNOME and plasma enabled, I was using both GNOME and Hyprland together for about a month, and had switched 1 or 2 days ago to the flake version of hyprland, see here.

What seems working to avoid this error from appearing is actually removing the flake version of hyprland, and disabling Hyprland:

  programs.hyprland = {
    enable = false;
    xwayland.enable = true;
  };

I am gonna try to see how to enable it again, but for now, I am okay with GNOME.

Thanks a lot for your precious help!

I bumped the same issue (exactly with Hyprland + GNOME), and there is a fix proposed for this:

As it’s still pending merge as of writing, I went ahead adding an overlay something like below, which helped for me:

# Fix GNOME xdg-desktop-portal
# Ref: https://github.com/NixOS/nixpkgs/pull/345979
# Once this is merged, I shouldn't need this.

final: prev:

{
  xdg-desktop-portal-gtk = prev.xdg-desktop-portal-gtk.overrideAttrs (old: rec {
    buildInputs = [
      prev.glib
      prev.gtk3
      prev.xdg-desktop-portal
      prev.gsettings-desktop-schemas # settings exposed by settings portal
      prev.gnome-desktop
      prev.gnome-settings-daemon # schemas needed for settings api (mostly useless now that fonts were moved to g-d-s, just mouse and xsettings)
    ];
    mesonFlags = [];
  });
}
1 Like

Hi,

Thanks for adding this. I’m not quite getting it to apply in my flake – do I need to set some input to the commit sha of the PR?

Thanks,
John

I got it to work with my nixpkgs pointing to the master branch. I think nixpkgs-unstable has the PR merged by now?
https://status.nixos.org

If you are having issues with the upgrade, you may want to add the overlay I mentioned above to see if that fixes

I’m also on the unstable channel and experiencing the same issue.

$ nix-channel --list
nixos https://channels.nixos.org/nixos-unstable

I’ve tried the following commands to update my system:

$ nix-channel --update 
$ nix flake update

Unfortunately, the error persists:

$ sudo nixos-rebuild switch --flake $HOME/.nixos #<hostname>
// ....
error: builder for '/nix/store/1d8h2f4zf1pp26m1fxlykqvk8gmb4p1q-user-units.drv' failed with exit code 1;
       last 1 log lines:
       > ln: failed to create symbolic link '/nix/store/ilk7rr1bip8b5vd90grk8fpkjhb74ngr-user-units/xdg-desktop-portal-gtk.service': File exists
       For full logs, run 'nix log /nix/store/1d8h2f4zf1pp26m1fxlykqvk8gmb4p1q-user-units.drv'.
error: 1 dependencies of derivation '/nix/store/jw5n2yh6xlqgli6sm436h31w7s2dyfwa-etc.drv' failed to build
error: 1 dependencies of derivation '/nix/store/87zbjmr1byf0m1mpcjkdbl1azc0kyp4z-nixos-system-monchi-24.11.20241004.bc947f5.drv' failed to build
error: Recipe `rebuild` failed on line 5 with exit code 1

To rebuild, I disabled GNOME by setting:

services.xserver.desktopManager.gnome.enable = false;

This allowed me to rebuild successfully, but when I try to re-enable GNOME, the error reoccurs.

Could you please provide more details on how to apply the overlay you mentioned to resolve this issue?

Thank you in advance!

Just for the record i run in the same Problem with
Sway enabled
so far i found only gnome and sway in my config disabling sway lett me update the system

I was able to fix the build error by pointing nixpkgs to the master branch like this in flake.nix:

nixpkgs = {
  url = "https://github.com/NixOS/nixpkgs/archive/refs/heads/master.zip";
};

For now, we may have to wait until the changes are merged into nixpkgs-unstable.

You can use url = "github:nixos/nixpkgs/master";

Looking at https://status.nixos.org, nixos-unstable was only cut a few hours ago, so it may have not included this fix. You may want to check the commit reference in the flake lock, and see if it’s past the commit xdg-desktop-portal-gtk: Enable all default portals unconditionally · NixOS/nixpkgs@7f2a6f1 · GitHub