NixOS Newbie Requiring a Little Help

Hi All

I am new to NixOS after many years of Arch and I need a little bit of help.

Two things I want to do but am struggling to understand and to actually happen.

1) I use dwm, I want feh to set the wallpaper. I have ~/.fehbg & set in my .Xinitrc with no effect, I have tried using .Xprofile and the dwmautostart feature with no luck. How do I get feh to set a wallpaper on login? Solved here.

2) I have an extremely long playlist in mpd that I want to use but mpd/ncmpcpp use such a long playlist.
I have in my mpd.conf the following, max_playlist_length "400000" but again, NixOs isn’t using the config file. How do I add this to my configuration.nix?
Sorted, here.

Here is my configuration.nix, no doubt it is a complete mess as I am sort of learning as I go.

# 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.systemd-boot.enable = true;
  boot.loader.efi.canTouchEfiVariables = true;

  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;

  # Set your time zone.
  time.timeZone = "Pacific/Auckland";

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

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

  # Enable the X11 windowing system.
  services.xserver.enable = true;
  services.xserver.windowManager.dwm.enable = true;
  services.picom.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 = "nz";
    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;
  };

  fileSystems."/run/media/dobbie/Music" =
  { device = "/dev/disk/by-label/MUSIC";
    fsType = "auto";
    options = [ "nofail" ];
  };
  # Enable touchpad support (enabled default in most desktopManager).
  # services.xserver.libinput.enable = true;
	
  services.udisks2.enable = true;
  programs.gnome-disks.enable = true;
  
  programs.xfconf.enable = true;
  programs.thunar.plugins = with pkgs.xfce; [
  thunar-archive-plugin
  thunar-volman
	];
	services.gvfs.enable = true; # Mount, trash, and other functionalities
	services.tumbler.enable = true; # Thumbnail support for images
	
  # Define a user account. Don't forget to set a password with ‘passwd’.
  users.users.dobbie = {
    isNormalUser = true;
    description = "Matthew Dobson";
    extraGroups = [ "networkmanager" "wheel" "audio" "video" "storage" "media" ];
    packages = with pkgs; [
      firefox
      dwm
      dmenu
      dunst
      slstatus
      slock
      st
      stdenv
      cmake
      ncmpcpp
      alacritty
      feh
      freetype
      ffmpeg
      gd
      gnumake
      gvfs
      gnome.gnome-disk-utility
      geany
      pavucontrol
      picom
      polkit_gnome
      unzip
      xclip
      xorg.libX11
      xorg.libX11.dev
      xorg.libxcb
      xorg.libXft
      xorg.libXinerama
      xorg.xinit
      xorg.xinput
      xfce.thunar
      easytag
      git
      harfbuzz
      eza
      maim
      mpd
      mpc-cli
      ncmpcpp
      oh-my-zsh
      fira-code-nerdfont
      zsh
      zsh-autosuggestions
      zsh-syntax-highlighting
      papirus-icon-theme
      materia-kde-theme
      wireplumber
      neofetch
      mpdscribble
      ntfs3g
      font-manager
    #  thunderbird
    ];
  };

    nixpkgs.overlays = [
	(final: prev: {
		dwm = prev.dwm.overrideAttrs (old: { src = /home/dobbie/Suckless/dwm ;});
	})
	(final: prev: {
		dmenu = prev.dmenu.overrideAttrs (old: { src = /home/dobbie/Suckless/dmenu ;});
	})
	(final: prev: {
		slstatus = prev.slstatus.overrideAttrs (old: { src = /home/dobbie/Suckless/slstatus ;});
	})
	(final: prev: {
		slock = prev.slock.overrideAttrs (old: { src = /home/dobbie/Suckless/slock ;});
	})
  ];

  users.defaultUserShell = pkgs.zsh;

  # Enable automatic login for the user.
  services.xserver.displayManager.autoLogin.enable = true;
  services.xserver.displayManager.autoLogin.user = "dobbie";

  # Music Player Daemon
  services.mpd = {
    enable = true;
    user = "dobbie";
    musicDirectory = "/run/media/dobbie/Music/";
    playlistDirectory = "/home/dobbie/.config/mpd/playlists";
    extraConfig = ''
      audio_output {
        type "pipewire"
        name "My PipeWire Output"
      }
    '';
    startWhenNeeded =
      true; # systemd feature: only start MPD service upon connection to its socket
  };
  systemd.services.mpd.environment = {
    # https://gitlab.freedesktop.org/pipewire/pipewire/-/issues/609
    XDG_RUNTIME_DIR =
      "/run/user/1000"; # User-id 1000 must match above user. MPD will look inside this directory for the PipeWire socket.
  };

  # ZSH
	programs = {
	zsh = {
    enable = true;
    shellAliases = {
    ll = "ls -l";
    update = "sudo nixos-rebuild switch";
    garbage = "sudo nix-collect-garbage -d";
    ls = "eza -al --color=always --group-directories-first";
    };
    autosuggestions.enable = true;
    syntaxHighlighting.enable = true;
    histSize = 10000;
    histFile = "/home/dobbie/.zsh_history";
    ohMyZsh = {
    enable = true;
    plugins = [ "git" "safe-paste" "history"  "globalias" "history-substring-search" ];
    theme = "robbyrussell";
    customPkgs = with pkgs; [
    nix-zsh-completions
      ];
    };
  };
  };

   systemd = {
  user.services.polkit-gnome-authentication-agent-1 = {
    description = "polkit-gnome-authentication-agent-1";
    wantedBy = [ "graphical-session.target" ];
    wants = [ "graphical-session.target" ];
    after = [ "graphical-session.target" ];
    serviceConfig = {
        Type = "simple";
        ExecStart = "${pkgs.polkit_gnome}/libexec/polkit-gnome-authentication-agent-1";
        Restart = "on-failure";
        RestartSec = 1;
        TimeoutStopSec = 10;
      };
  };
   extraConfig = ''
     DefaultTimeoutStopSec=10s
   '';
};

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

  # List packages installed in system profile. To search, run:
  # $ nix search wget
  environment.systemPackages = with pkgs; [

  ];

  # 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;
  
  fonts = {                                                  #This is depricated new sytax will
    fonts = with pkgs; [                                   #be enforced in the next realease
      noto-fonts
      noto-fonts-cjk
      noto-fonts-emoji
      font-awesome
      source-han-sans
      source-han-sans-japanese
      source-han-serif-japanese
      (nerdfonts.override { fonts = [ "Meslo" ]; })
    ];
    fontconfig = {
      enable = true;
      defaultFonts = {
	      monospace = [ "Meslo LG M Regular Nerd Font Complete Mono" ];
	      serif = [ "Noto Serif" "Source Han Serif" ];
	      sansSerif = [ "Noto Sans" "Source Han Sans" ];
      };
    };
};
  # 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.11"; # Did you read the comment?

}

Apologies for the seemingly simple questions, I have searched everywhere without really finding a solution, hence my post.

Thanks

What DM do you currently use? Just startx?

It differs depending on the DM because the Xorg spec is mildly insane. If you ever want a headache go read the xdm man page (which is the foundation of all display managers), try to compare it against xinit (which is what startx calls internally), and then wonder how we arrived at those being alternatives.

The mpd module you use starts mpd with a dynamically generated configuration file in /run: https://github.com/NixOS/nixpkgs/blob/d65bceaee0fb1e64363f7871bc43dc1c6ecad99f/nixos/modules/services/audio/mpd.nix#L242

This means your mpd.conf is ignored. Just put the contents of it in extraConfig, it will be added to the bottom of this template: https://github.com/NixOS/nixpkgs/blob/d65bceaee0fb1e64363f7871bc43dc1c6ecad99f/nixos/modules/services/audio/mpd.nix#L21

You probably don’t want to add these to your packages, by the way, for 99% of libraries you need to use a nix shell to actually get them to link. Development stuff belongs in a shell.nix or flake.nix specific to the project. This also applies to the various X libraries in there, and probably some other things I overlooked.

Also, in general, you probably want to use .enable options for the absolute majority of packages, there are a bunch in your list for which I think such exist (e.g. mpd and mpdscribble). There’s no need to install them twice, and sometimes doing so can cause things to break due to PATH ordering and overrides.

1 Like

Thanks for the reply, tips and advice so far.

I’m about to head to bed, but I will reply in the morning.

1 Like

For dwm, I use cool autostart to launch other programs, however all the commands become hardcoded.
I tested autostart and it also works, but it does not work very well with restartsig.

for the wallpaper I thought one could just place it in ~/.background-image and it should work?

Huh, fun, that in fact invokes feh in the DM-specific session script: https://github.com/NixOS/nixpkgs/blob/d65bceaee0fb1e64363f7871bc43dc1c6ecad99f/nixos/modules/services/x11/desktop-managers/default.nix#L79

That means it circumvents the startx vs DM issue, though it doesn’t solve autostart in general.

Also doubt it’d work with greetd or wayland.

Thanks for the reply, this worked for me.

Thank you to all who replied re: wallpaper.

Now onto mpd.

mpd issue is sorted. I was typically over thinking the steps.

I simply added:

restore_paused "yes"
max_playlist_length "400000"

And I am set.

Sorted for now. Thank you to @TLATER and @rjpc in particular.

1 Like

I’ll test it out on wayland to confirm.

So I added mpdscribble using services.mpdscribble.enable = true; but I strike the following issue:

Dec 24 07:35:29 nixos systemd[1]: Starting mpdscribble mpd scrobble client...
Dec 24 07:35:29 nixos systemd[1]: Started mpdscribble mpd scrobble client.
Dec 24 07:35:29 nixos mpdscribble[19475]: No audioscrobbler host configured in /run/mpdscribble/mpdscribble.conf
Dec 24 07:35:29 nixos systemd[1]: mpdscribble.service: Main process exited, code=exited, status=1/FAILURE
Dec 24 07:35:29 nixos systemd[1]: mpdscribble.service: Failed with result 'exit-code'.
warning: error(s) occurred while switching to the new configuration

I drop the required details into the folder mentioned above, same issue, it just gets deleted when rebuilding.

What am I missing here?

yeah, confirmed it doesn’t work with Wayland, of course.

Hmm, based on the error maybe you need to set this option in the mdpscribble service? https://github.com/NixOS/nixpkgs/blob/d65bceaee0fb1e64363f7871bc43dc1c6ecad99f/nixos/modules/services/audio/mpdscribble.nix#L107

see also NixOS Search

1 Like

Here, too, the issue is that you’re trying to configure the service with files somewhere on your host.

On NixOS, all configuration should stem from your configuration.nix. There are only few exceptions, typically GUI applications (e.g. your browser), but most things can be configured through configuration.nix, and for many it’s difficult to do it any other way.

Add the required details using the various services.mpdscribble.* options:

services.mpdscribble = {
  enable = true;
  host = "localhost";
}

That said, the configuration might not be the problem. Looks like the defaults should just work most of the time - are you sure your mpd allows these connections? Anything from its logs (journalctl --boot -eu mpd.service)?

1 Like

HI Gents, I feel I have wasted all your time. I will revisit this when I am more competent with Nix.

Very much appreciate the fantastic replies.

Cheers

1 Like

I’d like to revise this @TLATER :

What DM do you currently use? Just startx?

It differs depending on the DM because the Xorg spec is mildly insane. If you ever want a headache go read the xdm man page (which is the foundation of all display managers), try to compare it against xinit (which is what startx calls internally), and then wonder how we arrived at those being alternatives.

I’m using dwm with lightdm. I normally use startx on my Arch box, never used autologin with a DM before and I really am struggling to either use the correct search terms or just find the right bits to help.

How do I autostart anything using LightDM.

Again, apologies Gents for such seemingly basic questions but NixOS has really thrown me.

I am a slow learner it seems.

Well, the problem is that this isn’t a NixOS problem; you’re both learning how to use NixOS and how display managers work at the same time (on top of likely a bunch of other things). This isn’t trivial, and even if it was, we’re here to help, don’t apologize!

Check this response I gave to another thread asking a similar question: Trying to setup clock and wallpaper in dwm with the default login manager - #2 by TLATER

2 Likes

Thanks again for the reply. Once I am through the family stuff for Christmas I will revisit this one.

Talk soon, cheers.

2 Likes

Thanks again to all that have helped. I have spent the day tinkering and am mostly there.

1 Like