NixOS for the confused – Part II

Ahoy! It is time for us to get fancy. In order to do so, we're going to do the most ill-advised thing there is: We're installing and configuring Hyprland. Nothing like some experimental, beta shit to keep us in our toes. Did it crash because of something we did? Did it crash because this thing is as stable as one of them rope bridges you find in the middle of the jungle? We might never know. But, hey! Fuck it. Let's do it anyway.

The story so far is that we've created our initial flake.nix file, and did a bit of dinking around with our configuration.nix and our home.nix. Swell. How do we go about installing Hyprland? And't don't come at me with this Gnome bullshit.

jk. There's a really good post about Nix-ifying your Gnome installs here. HOWEVER... we're not here for that, are we? Best thing you can do is install NixOS without any Window Manager at all, and coax our flake.nix into doing your bidding. So, let's add some stuff to our config. Put this in your flakie/flake.nix where the modules for nixosConfigurations live:

hyprland.nixosModules.default
{programs.hyprland.enable = true;}

Ok, back up a bit. It was originally like this:

modules = [
            ./nixos/configuration.nix
          ];

It should look like this now:

modules = [
            ./nixos/configuration.nix
            hyprland.nixosModules.default
            {programs.hyprland.enable = true;}
          ];

Go to our flakies directory, try to rebuild this thing with the usual sudo nixos-rebuild --flake .#luffy, and see what transpires. Wait a fucking minute! We are using a Flake within a Flake here! Our NixOS simply does not know what the hell you're talking about. See, the problem here is that we're referencing a bunch of stuff that doesn't even exist yet. Our Flake doesn't know how to deal with hyprland.nixosModules.default. Yet. Let's fix that real quick. The Hyprland wiki is kind enough to throw a bone to us NixOS weirdos. It gives us the instructions to install Hyprland a bunch of different ways, but we want the NixOS from the Flake version. To get things to build properly, we need to tell NixOS where to get the Flake we want to use, and tell our Flake that Hyprland is now a “thing” we have. Let's add this line to the inputs:

hyprland.url = "github:hyprwm/Hyprland";

It tells NixOS “Hey, for this Hyprland we're installing, use the flake the good folks from Hyprland pushed to their Github repo. Not nixpkgs. Hyprland Github repo. Capisce?” Next, we change the outputs to include hyprland. Think of this as kinda sorta declaring a variable. Our outputs line should look like this:

outputs = { self, nixpkgs, home-manager, hyprland, ... }@inputs: {

We added hyprland to the list. The whole flake.nix should look like this:

{
     description = "My Flakie";

     inputs = {
         nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
         home-manager.url = "github:nix-community/home-manager";
         home-manager.inputs.nixpkgs.follows = "nixpkgs";
         hardware.url = "github:nixos/nixos-hardware";
         hyprland.url = "github:hyprwm/Hyprland";
     };

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

        homeConfigurations = {
            "brunoc@robin" = home-manager.lib.homeManagerConfiguration {
                pkgs = nixpkgs.legacyPackages.x86_64-linux;
                extraSpecialArgs = { inherit inputs; };
                modules = [
                    ./home-manager/home.nix
                    ];
                };
            };
     };
 }

Now go ahead and try to build with sudo nixos-rebuild switch --flake .#luffy. If everything goes according to the plan, if you type Hyprland in your terminal, Hyprland should start.

Coolio! What the fuck was that, though? Even though Hyprland can be installed via Nixpkgs, we, in our infinite wisdom, decided to use the Flake provided by the Hyprland gang (✌️) instead. Why? Because it basically installs everything we need in one sitting. Neat! We kinda have a graphical interface now. With, what? 5 additional lines to our flake.nix? Not bad at all. It looks like shit, though. Fret not! We'll prettify this thing in Part III. Part II files are in the usual place. See ya soon, Cola Gangsters.

Discuss...