From 5ebe064a28984073b6363000dfe2b7eb6042a8e5 Mon Sep 17 00:00:00 2001
From: Oliver Davies <oliver@oliverdavies.dev>
Date: Tue, 19 Mar 2024 00:13:01 +0000
Subject: [PATCH] Simplify `nixos-*` justfile recipes

Make the hostname configurable for NixOS and remove the need to specify
the profile name when running `nixos-rebuild` commands as the hostname
can be used.
---
 flake.nix                   | 4 ++--
 justfile                    | 8 +++++---
 lib/nixos/configuration.nix | 5 +++--
 lib/nixos/default.nix       | 6 +++---
 4 files changed, 13 insertions(+), 10 deletions(-)

diff --git a/flake.nix b/flake.nix
index 50010444..f0e5e687 100644
--- a/flake.nix
+++ b/flake.nix
@@ -30,8 +30,8 @@
         lib = import ./lib { inherit inputs; };
 
         nixosConfigurations = {
-          apollo = mkNixos { desktop = true; };
-          nixedo = mkNixos { desktop = true; };
+          apollo = mkNixos { desktop = true; hostname = "apollo"; };
+          nixedo = mkNixos { desktop = true; hostname = "nixedo"; };
         };
 
         homeConfigurations = { wsl2 = mkWsl; };
diff --git a/justfile b/justfile
index 99ad584c..73db0a53 100644
--- a/justfile
+++ b/justfile
@@ -1,16 +1,18 @@
+profile := `hostname`
+
 _default:
     just --list
 
 check:
     nix flake check
 
-nixos-build profile:
+nixos-build:
     sudo nixos-rebuild build --flake ".#{{ profile }}"
 
-nixos-switch profile:
+nixos-switch:
     sudo nixos-rebuild switch --flake ".#{{ profile }}"
 
-nixos-test profile:
+nixos-test:
     sudo nixos-rebuild test --flake ".#{{ profile }}"
 
 update:
diff --git a/lib/nixos/configuration.nix b/lib/nixos/configuration.nix
index 9adf02ea..088a7f6a 100644
--- a/lib/nixos/configuration.nix
+++ b/lib/nixos/configuration.nix
@@ -1,4 +1,4 @@
-{ inputs, desktop ? false, self, }:
+{ inputs, desktop ? false, hostname, self }:
 { pkgs, ... }:
 let
   configure-gtk = pkgs.writeTextFile {
@@ -30,7 +30,8 @@ in {
     DefaultTimeoutStopSec=10s
   '';
 
-  # networking.hostName = hostname;
+  networking.hostName = hostname;
+
   # networking.wireless.enable = true;  # Enables wireless support via wpa_supplicant.
 
   # Configure network proxy if necessary
diff --git a/lib/nixos/default.nix b/lib/nixos/default.nix
index bd9a32bb..5ed655c3 100644
--- a/lib/nixos/default.nix
+++ b/lib/nixos/default.nix
@@ -1,7 +1,7 @@
-{ inputs, self, username, }:
-{ desktop ? false, }:
+{ inputs, self, username }:
+{ desktop ? false, hostname }:
 let
-  configuration = import ./configuration.nix { inherit desktop inputs self; };
+  configuration = import ./configuration.nix { inherit desktop hostname inputs self; };
   hardwareConfiguration = import ./hardware-configuration.nix;
 in inputs.nixpkgs.lib.nixosSystem {
   modules = [