Does my first-ever configuration.nix look alright?

I’m a first-time NixOS user. I’m liking it!

I’m not entirely sure about my first config. How does it look? Any obvious mistakes? Anything I should do differently?

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

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

  networking.hostName = "starnix"; # Define your hostname. # CUSTOMIZED
  # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
  networking.networkmanager.enable = true; # ADDED

  # The global useDHCP flag is deprecated, therefore explicitly set to false here.
  # Per-interface useDHCP will be mandatory in the future, so this generated config
  # replicates the default behaviour.
  networking.useDHCP = false;
  networking.interfaces.enp0s31f6.useDHCP = true;
  networking.interfaces.wlp1s0.useDHCP = true;

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

  # Select internationalisation properties.
  # CUSTOMIZED
  i18n = {
    consoleFont = "Lat2-Terminus16";
    consoleKeyMap = "us";
    defaultLocale = "en_US.UTF-8";
  };

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

  # ADDED, config for certain packages
  nixpkgs.config = {
    allowUnfree = true;

    # Firefox and Chromium settings from https://nixos.wiki/wiki/Chromium
    firefox = {
      enableGoogleTalkPlugin = true;
      enableAdobeFlash = true;
      enableGnomeExtensions = true;
    };
    chromium = {
      enablePepperFlash = true; # Chromium removed support for Mozilla (NPAPI) plugins so Adobe Flash no longer works 
    };

  };

  # List packages installed in system profile. To search, run:
  # $ nix search <term>
  # CUSTOMIZED
  environment.systemPackages = with pkgs; [
    wget curl vim_configurable neovim python37Packages.pynvim git libnotify zsh
    gimp zeromq gnome3.meld xvfb_run htop blender

    # see https://nixos.wiki/wiki/Chromium
    chromium firefox

    # Node.js, https://nixos.wiki/wiki/Node.js
    nodejs_latest

    # VS Code, open-source version without proprietary MS stuff, https://nixos.wiki/wiki/Vscode
    vscodium
  ];

  # 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.
  # CUSTOMIZED
  services.openssh.enable = true;

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

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

  # Enable sound.
  # CUSTOMIZED
  sound.enable = true;
  hardware.pulseaudio.enable = true;

  # Enable the X11 windowing system.
  services.xserver.enable = true; # CUSTOMIZED
  services.xserver.layout = "us"; # CUSTOMIZED
  # services.xserver.xkbOptions = "eurosign:e";

  # Enable touchpad support.
  services.xserver.libinput.enable = true; # CUSTOMIZED

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

  # Enable the Gnome Desktop Environment. https://nixos.wiki/wiki/Gnome
  # TODO try Wayland instead of X11. See here: https://github.com/NixOS/nixpkgs/issues/32806#issuecomment-449987334
  services.xserver.displayManager.gdm.enable = true;
  services.xserver.displayManager.gdm.wayland = false;
  services.xserver.desktopManager.gnome3.enable = true;

  # Define a user account. Don't forget to set a password with ‘passwd’.
  # CUSTOMIZED
  users.users.trusktr = {
    isNormalUser = true;
    extraGroups = [ "wheel" ]; # Enable ‘sudo’ for the user.
  };

  # This value determines the NixOS release with which your system is to be
  # compatible, in order to avoid breaking some software such as database
  # servers. You should change this only after NixOS release notes say you
  # should.
  system.stateVersion = "19.09"; # Did you read the comment?

}
2 Likes

everything depends on your use case :slight_smile:

Also, you may be interested in GitHub - nix-community/home-manager: Manage a user environment using Nix [maintainer=@rycee] as it will help you manage “user” configuration such as shells, dotfiles, etc.

2 Likes

@jonringer Is Home-Manager easy to use? I’ve heard mixed results.

@trusktr I don’t see any obvious errors, except Los_Angeles. :rofl: If you wish, you can combine some of those more, but that’s a personal preference.

1 Like

I’ve only ever heard people rant about how wonderful it is. Blog posts, discourse, IRC?

1 Like

My config has my wheel user with these extraGroups also

extraGroups = [ 
  "wheel"
  "networkmanager" # this is actually in the nixos documentation on networkmanager
  "video"
  "audio"
]; 

The useDHCP part is interesting to me, why did you need it?
IIRC, the networkmanager module in NixOS explicitly does useDHCP = false and handles that stuff itself.

1 Like

I’m pretty sure this should work totally perfect in 19.09. Have you had problems using wayland and Gnome on 19.09?

I’m curious about how I’ve written the config rather than what stuff I’ve actually installed. Would you recommend writing any parts differently?

I saw that. Looks interesting and I’d like to check it out after I get the hang of vanilla stuff first, before it “fails catastrophically” (as it says in the README) on me without me knowing what happened.

For now, I have a setup.sh script that builds my home folder and dotfiles on Windows, Linux flavors (the normal FHS type), and macOS. So for now I’d like to learn about Nix by using it at the system level, and not worry about managing my home folder with just yet.

Haha, funny. (That’s a joke right?). I’m in Oakland. :slight_smile:

Ah, I knew someone would say this. Mind showing an example?

Ah thanks, I missed that part. That explains why it asked me to enter my sudo password when trying to connect to WiFi.

Ah, nice to know. See, as a brand new first-time NixOS user, I simply had no idea. It isn’t obvious for a total beginner.

What I had done was take the default config generated by nixos-generate-config, which already had those DHCP lines, then I simply added the networkmanager line, but I didn’t know that network manager would do that.

So basically, if I add networkmanager, should I just remove all the DHCP-related lines?

I haven’t tried it yet. The thing is, if my system and all the programs I need work great on X11, why should I switch to Wayland? If you don’t mind going into more detail on this, I opened another thread specifically about this at Newb question: Any caveats with Gnome + Wayland? Is it worth moving to Wayland instead of X11?

EDIT: You already replied there. Thanks. :slight_smile:

Other than what other people have commented, not really. Nix is pretty declarative, so there’s usually one obvious way to configure your stuff.

One think i did notice is that you’re using vim_configurable directly, but its usually meant to be used like this

{ config, pkgs, ... }:
let 
 my_vim = pkgs.vim_configurable.customize {
  # `name` specifies the name of the executable and package
  name = "vim-with-plugins";

  vimrcConfig.customRC = ''
    set hidden
  '';
}
in
...
environment.systemPackages [ ... my_vim .. ];

again, home-manager has a nice way to declare this https://github.com/rycee/home-manager/blob/d677556e62ab524cb6fcbc20b8b1fb32964db021/modules/programs/vim.nix

He’s just being modest and giving no expectation of being responsible if something goes wrong. It’s worked wonderfully for myself and many othoers

If it works, it works.
However, most distributions have very specific ways of installing packages (apt, yum, etc.), and doesn’t work well on other flavors, nixos included. I would still recommend a nix native solution

1 Like

There are several you COULD combine more, but it’s really personal preference. :man_shrugging: Here’s an example:

services.xserver = {
  enable = true;
  layout = "us";
  libinput.enable = true;
  desktopManager = {
    plasma5.enable = true;
    gnome3.enable = true;
  };
  displayManager.gdm = {
    enable = true;
    wayland = false;
  };
};

That’s interesting, though at the moment I’m relying heavily on my dotfiles and .vimrc to work across Windows, Linux, and macOS, and my vimrc is almost 2k lines long so it may be a while before I try to port that (if ever).

Nix isn’t hard to install in any Linux distro, right? It might be something for me to look into later, if I can run it in Linux, Windows, and macOS. Running inside of Termux for Android (a Debian-like apt-managed environment) might be nice too.

1 Like

Fair, but this would also probably pair well with home-manager again. Here’s my setup:

# home.nix
{ config, lib, pkgs, ... }:
{
...
  programs.neovim = (import ./vim.nix) pkgs;
...
}
# vim .nix
pkgs:
{
  enable = true;
  viAlias = true;
  vimAlias = true;
  plugins = with pkgs.vimPlugins; [
    fzf-vim
    fzfWrapper
    LanguageClient-neovim
    lightline-vim
    nerdtree
    supertab
    tabular
    vim-better-whitespace
    vim-multiple-cursors
    vim-surround
    #vimproc
    #vimproc-vim

    # themes
    wombat256

    # language packages
    # Haskell
    vim-hoogle
    neco-ghc
    haskell-vim
    hlint-refactor-vim
    ghc-mod-vim

    # Nix
    vim-nix

    # Csharp
    vim-csharp

    # Powershell
    vim-ps1

    # Python
    semshi
  ];

  extraConfig = ''
   " bashrc content
  '';
}

you could do:

    extraConfig = builtins.readFile ./.bashrc;

and still re-use your bashrc

yes, after doing curl https://nixos.org/nix/install | sh, you should have access to the nix commands. But you can’t use modules (configuration.nix by extension) on other distro’s. However, I think home-manager still works, but I can’t confirm as I use NixOS for everything :frowning: (or :slight_smile:)

When I write something like that, is it concatenating new options into the existing options?

What do you mean by “you can’t use modules (configuration.nix by extension) on other distro’s.”? (I’m still too new to understand). So using nix on other distros has certain limitations that I don’t have in NixOS?

configuration.nix is used to configure your system as a whole (systemd services, users, groups, kernel version, etc.), it’s not really targeted as “user-level” configuration (shells, user-specific utilities, dotfiles, etc.) which is why home-manager exists :slight_smile:

Most distro’s and NixOS configurations will be very opinionated about what services are running, so they are mutually exclusive.

Essentially:
NixOS → uses configuration.nix → configures the machine
home-manager → uses ~/.config/nixpkgs/home.nix → configures a user’s environment.

further reading: https://nixos.wiki/wiki/Module NixOS 23.11 manual | Nix & NixOS

So you mean, we can not use nix to install system-wide stuff on other distros, only to manage the home folder?

I don’t have much experience in this area, as I use NixOS as my daily driver. But you should be able to use the nix cli which includes nix-env to install packages in a similar manner to apt and other package managers.

The main benefit to using nix over other package managers is the ability to specify your system and settings in a declarative manner. And the abstractions in the configuration generally compose well in which you have a high assurance that your system “works”. Not to mention that these get “checkpointed” in profiles which allows you to iterate setups and not brick your system.

The options get set, and when generating the necessary configuration these values get referenced to create the desired environment, here’s what the gdm settings are actually doing: https://github.com/NixOS/nixpkgs/blob/e4134747f5666bcab8680aff67fa3b63384f9a0f/nixos/modules/services/x11/display-managers/gdm.nix#L124

For concatenating values, yes, this is exactly what it’s doing. values are “safely” merged NixOS 23.11 manual | Nix & NixOS

2 Likes

Functionally, there’s zero difference between how you wrote it, and how I wrote it. It’s exactly the same thing. It’s a personal style thing. :man_shrugging:

1 Like

My audio and video seems to work in Gnome desktop. What are those groups for?

The following from "programs.foo.enable = true" vs "systemPackages=[foo]" is confusing - #9 by jonringer was helpful:

So, that’s something I need to do, is figure which things I have in systemPackages that I should instead install with configuration options like programs.foo.enable = true.