Mlocate package - updatedb can't find group 'mlocate'

I’m completely new to NixOS and have been adding packages to my configuration.nix file. I added pkgs.mlocate ran the rebuild command, attempted a sudo updatedb and received the output:

updatedb: can not find group 'mlocate'

When installing the package, shouldn’t the group have been created automatically?

Package installs don’t modify the system(afaik)apart of installing them, usually if they need more setup there’s often either a programs.xyz option or services.xyz

For mlocate NixOS Search Services.locate seems to be responsible

Enable the service and set services.locate.locate to pkgs.mlocate and it should setup the group mlocate as well

Thank you.
Does the services.locate.locate get added to my configuration.nix file?

Yes, and don’t forget services.locate.enable =true;

Got it. Thanks. I will try that out.

My configuration.nix didn’t like services.locate.locate. However, services.locate.enable = true; had no issues.

So far I haven’t been able to fix this.

Which nixos channel are you following / version 23.05 /unstable ?
Can u show us the config which didn’t work of the service

It looks to be 23.05. Here is my config:


# 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, ... }:

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

  # Bootloader.
  boot.loader.grub.enable = true;
  boot.loader.grub.device = "/dev/vda";
  boot.loader.grub.useOSProber = true;

  networking.hostName = "nixosvm"; # 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;

  # Set your time zone.
  time.timeZone = "America/New_York";

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

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

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

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

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

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

  # Enable sound with pipewire.
  sound.enable = true;
  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.ed = {
    isNormalUser = true;
    description = "ed";
    extraGroups = [ "networkmanager" "wheel" ];
    packages = with pkgs; [
      firefox
      kate
    #  thunderbird
    ];
  };

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

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [
    htop
    pkgs.avidemux
    pkgs.brave
    pkgs.discord
    pkgs.ffmpeg_6-full
    pkgs.findutils
    pkgs.git
    pkgs.handbrake
    pkgs.libsForQt5.kdenlive
    pkgs.lshw
    pkgs.makemkv
    pkgs.mlocate
    pkgs.ncdu
    pkgs.nextcloud-client
    pkgs.nmap
    pkgs.protonvpn-gui
    pkgs.onlyoffice-bin
    pkgs.rapid-photo-downloader
    pkgs.spice
    pkgs.spice-vdagent
    pkgs.tmate
    pkgs.tmux
    pkgs.virt-manager
    vim # Do not forget to add an editor to edit configuration.nix! The Nano editor is also installed by default.
    wget
  ];

  # 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:
   services.locate.enable = true;
   services.spice-vdagentd.enable = true;
   services.qemuGuest.enable = true;
  # 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 = "23.05"; # Did you read the comment?

}

services.locate.locate = pkgs.mlocate;

Does not work ? Which error do u get

Btw at environment.systemPackages = with pkgs; [

U can remove the pkgs. From that list since the with pkgs does that already :slight_smile:

Okay. Again, I am very new so I was not aware of setting services.locate.locate = pkgs.mlocate; Let me try that.
And let me confirm: So you are stating that when I set that above in the config that I can remove pkgs.mlocate from my system-wide packages list?

U could remove it from the system packages settings since the service module does that for you already yes, but I think I wasn’t clear enough with the tip, I meant to say that

environment.systemPackages = with pkgs; [
htop
pkgs.avidemux
pkgs.brave
pkgs.discord
pkgs.ffmpeg_6-full

Can be changed to

environment.systemPackages = with pkgs; [
htop
avidemux
brave
discord
ffmpeg_6-full

Hope that clears it up, its hard to explain on a phone :slight_smile:

Ah. I gotcha. Okay. Thanks for the information and assistance. You have been extremely helpful and I really appreciate your time in helping understand Nix better and fixing my problem.
It’s working now. No more errors.
To wrap up, for anyone in the future, I added the following two lines to my configuration.nix file to install mlocate:

   services.locate.enable = true;
   services.locate.locate = pkgs.mlocate;

I’ve tried this but every time I run locate, along mlocate or plocate, I’m met with:

locate: can not stat () /var/cache/locatedb: No such file or directory

Any idea why this happens or how to fix it?

Do you have the settings below in your config? It’s what worked for me.

   services.locate.enable = true;
   services.locate.locate = pkgs.mlocate;

Yes, I copied exactly those line into my config.nix file. It installs mlocate and locate, but using either one still gives me my aforementioned output.

Oh, and just further explain, any time I use locate command, it gives me that output I mentioned. locate is installed, it’s just not working for me when I run it.

When you configure the module, a systemd services is created that builds the index. It sounds like that hasn’t run yet (and thus no index).

Try running it manually once:

sudo systemctl start update-locatedb

1 Like

This worked!

Any idea how I can embedded this CL into my Config.nix file, so that way I wouldn’t have to do it in the future?

By default, the job will run every night and since the timer unit isn’t tagged Persistent = true, the missed job isn’t triggered automatically.

I have some other fixes to the locate module so I’ll do up a PR that addresses the Persistent issue as well.

tl;dr: unstable will soon have the proper fix.

1 Like