Using NixOS as a daily driver

For my 1 year linux challenge i decided todo it over NixOS. What is NixOS? Well lets just pull that from nixos themselves.

That sounds good and all but what does it mean? It means that your entire system is defined in a config file. This includes everything from users, desktop managers, file systems, etc. You just define how you want your system and it does it.

Example Config
{ config, pkgs, ... }

boot.initrd.availableKernelModules = [ "ehci_pci" "ahci" "firewire_ohci" "xhci_pci" "usb_storage" "usbhid" "sd_mod" "sr_mod" "sdhci_pci" ];

nix.maxJobs = lib.mkDefault 8;

fileSystems."/" =
    { device = "/dev/disk/by-uuid/707667f2-d30e-4d11-b692-bbd3a98ce3ab";
      fsType = "ext4";
    };

boot.loader.grub = {
  enable = true;
  version = 2;
  device = "/dev/sdb";
};

networking = {
  hostName = "Nixos-Zeta";
  networkmanager.enable = true;
};

time.timeZone = "America/Chicago";

sound.enable = true;
hardware.pulseaudio.enable = true;

environment.systemPackages = with pkgs; [
  exa chromium python3 git gnumake gnome3.gnome-screenshot gcc unrar
];

services = {
 
  xserver = {
    enable = true;
    layout = "us";
    libinput.enable = true;

    windowManager = {
      default = "i3";
      i3.enable = true;
      i3.extraPackages = with pkgs; [
        lm_sensors
        rofi
        i3lock
        i3blocks
      ];
    };

    displayManager = {
      gdm.enable = true;
    };
  };
};

users.groups.foo.gid = 1337;

users.users.dje4321 = {
  isNormalUser = true;
  uid = 1337;
  home = "/home/foo";
  description = "Test User";
  extraGroups = [ "wheel" "networkmanager" "foo" "video" "leds" ];
};

system.nixos.stateVersion = "18.09";

Above is a example config for a system. You can see how every aspect of the system can be controlled. This can get rather complex but will give you almost absolute control on how the system is defined. Some of the things you can do is setup sshd in your initrd incase your remote machine wont boot into the main os. Another thing you can do is just run a command once your initrd has finished mounting drives.

Nixos has 2 major pros that makes it stand out above the rest. Its atomic so parts of the system can just be added and removed without leaving much of a trace and it has reproducible builds. These two combined allows you to just keep a configuration and modify it at will and know what that your system can always roll back to a previous state.

Nixos manages being atomic by keeping packages in /nix/store. Everything from the kernel, glibc, bash, etc is kept there. packages have a specific name scheming of (HASH)-(NAME)-(VERSION) so something like binutils would be 4mf2xm9p32lzrim927yk92xhx35yaz62-binutils-2.30. From there anything that is installed system-wide is linked to /run/current-system. So if we were to look at the ls command, then we could find it at /run/current-system/sw/bin/ls but that is linked to /nix/store/4mf2xm9p32lzrim927yk92xhx35yaz62-binutils-2.30/bin/ls

There is one huge glaring problem with managing packages this way. That problem is that prebuilt binaries dont work because everything from the interpreter to libraries are not where they are expected. There is no /lib where a program can expect to find the libraries it needs. There are solutions to this but they are imperfect at best. ive been working on my own solution but even that has its own problems.

If you want to know more practical and philosophical knowledge on nixos then i would reccomend looking at both the manual and this amazing talk. I encourage you to try nixos in a VM and see what kind of power it can have when it comes to managing your system

https://nixos.org/nixos/manual/

4 Likes

I like the way the way this sounds upto the point of the alternative package management that sounds like it may be PITA in getting certain things to run … still will have to try it out .

Package management is definitely different, but it’s not that much of a pain.

@Dje4321 it looks like nixos is similar to Gentoo in that you can build everything from source if you want. Do you know if there’s a simple method to disable binary packages?

I wish kickstart on RHEL was that granular.

1 Like

ofc theres a simple method. its nixos =P. you can also pull a gentoo and run your own build service that your machines will use to pull their packages from. Bit advanced for most people though

nix.binaryCaches = [];

2 Likes

Might want to do that considering the number of systems I have at my disposal.

1 Like

The wiki will get you started

https://nixos.wiki/wiki/Distributed_build
https://nixos.org/nix/manual/#chap-distributed-builds

2 Likes

I wonder if they have proxmox or ovirt built for nixos, and if they don’t, I’d be interested in building them.

its not that bad. you can just ask for a certain package to be installed and it handles it. Also packages can be installed ad-hoc like any other distro if that also suits your needs

My thought exactly. If you could roll out hypervisors off of a config file like that, and have them fully pre-configured, that would be pretty amazing.

1 Like

you can actually spin up vms based on a config for servers.

https://nixos.org/nixops/

2 Likes

Yeah, but I’m looking for something that uses kvm/libvirt. That appears to only use virtualbox.

We’re actually looking at implementing that.

Also, it would be nice if they supported openstack

thats just the example =P
supports everthing from amazons EC2 to virtualbox and even digitial ocean

https://nixos.org/releases/nixops/latest/manual/manual.html#idm140737318329504

1 Like

The page you linked previously didn’t include OpenStack or Libvirt on their list.

#documentation

1 Like

scroll down to the bottom of the page and select nixops manual

Yeah, I’m lazy and have some expectation of continuity.

That said, I’m not complaining, just being grumpy because reasons.

its ok. its nixos. the documentation makes the learning curve look like a cliff

2 Likes

Whats the current state of Nix, was looking to build and sign containers if someone knows of a good example?

Current state of nix? Very good, very good. Documentation has been becoming increasingly more accessible as more new users have been jumping on board. Even if it is a bit funny some of the yt videos ive seen that advertise it as basically a way of easily customizing vim. If you can get used to your entire universe being functions, it can serve you well.

I spend more time running docker containers then building them, but from what I have seen and what people have told me the tools are very, very robust. The manual for nix has a whole section dedicated to ‘dockertools’ . It has an example in the manual, and here are a few projects that use them.

/edit → not use to this site, for some reason I thought this post was from Oct of this year, not Oct of 2021. Mybadnow //_ //