From c0cde197148d4db2ff1c1ea697699c2fad164ff9 Mon Sep 17 00:00:00 2001
From: Nathan Anderson <nathananderson98@gmail.com>
Date: Fri, 15 Dec 2023 15:50:45 -0700
Subject: [PATCH] Migrating to module usage

---
 flake.nix                    |  22 +++++++
 modules/sway/sway_conf.nix   |  99 +++++++++++++++++++++++++++++
 nixos/default.nix            |  24 +++++++
 nixos/sway_configuration.nix | 119 +++++++++++++++++++----------------
 4 files changed, 209 insertions(+), 55 deletions(-)
 create mode 100644 nixos/default.nix

diff --git a/flake.nix b/flake.nix
index 45678f5..1094877 100644
--- a/flake.nix
+++ b/flake.nix
@@ -23,6 +23,7 @@
     system = "x86_64-linux";
     userName = "nate";
     hostName = "winmax";
+    desktop = "sway";
     pkgs = nixpkgs.legacyPackages.${system};
     stablePkgs = import nixpkgs-stable {
         legacyPackages = system;
@@ -31,6 +32,27 @@
   in
   {
     nixosConfigurations = {
+      default = nixpkgs.lib.nixosSystem {
+        # Pass args to sway_configuration
+        specialArgs = {
+            inherit inputs;
+            inherit userName;
+            inherit hostName;
+        };
+        modules = [
+          ./modules/sway/sway_conf.nix
+          # Setup home manager
+          home-manager.nixosModules.home-manager {
+              home-manager.useGlobalPkgs = true;
+              home-manager.useUserPackages = true;
+              home-manager.users.${userName} = import ./modules/home-manager/home.nix;
+              home-manager.extraSpecialArgs = {
+                  inherit inputs outputs userName hostName;
+              };
+          }
+        ];
+      }
+
       nixServer = nixpkgs.lib.nixosSystem {
         specialArgs = { inherit inputs; };
         modules = [
diff --git a/modules/sway/sway_conf.nix b/modules/sway/sway_conf.nix
index e69de29..306020d 100644
--- a/modules/sway/sway_conf.nix
+++ b/modules/sway/sway_conf.nix
@@ -0,0 +1,99 @@
+{ lib, config, pkgs, ... }:
+{
+    options.swaywm = {
+        enable = lib.mkEnableOption "Enable sway window manager.";
+        useNonFree = lib.mkOption {
+            default = false;
+            example = true;
+            description = "Whether to enable non-free software in the sway config";
+        };
+        systemPackages = lib.mkOption {
+            default = [];
+            description = "Add any additional packages desired. Merged with sway defaults.";
+        };
+
+    };
+
+    config = lib.mkIf config.swaywm.enable {
+
+        nixpkgs.config.allowUnfree = config.swaywm.useNonFree;
+        
+        ###
+        ##  XDG portal setup
+        ###
+        xdg.portal = {
+            config = {
+                common = {
+                  default = [
+                    "wlr"
+                  ];
+                };
+            };
+            extraPortals = with pkgs; [
+                # xdg-desktop-portal-kde
+                xdg-desktop-portal-gtk
+            ];
+            wlr.enable = true;
+            enable = true;
+        };
+        xdg.sounds.enable = true;
+
+        ###
+        ##  System Packages
+        ###
+        environment.systemPackages = with pkgs; lib.mkMerge [
+            [
+                git
+                glib # gsettings
+                grim
+                pavucontrol
+                slurp
+                swaylock
+                swayidle
+                wget
+                wl-clipboard
+                xdg-utils
+                zsh
+            ]
+            config.swaywm.systemPackages
+        ];
+
+        programs.zsh.enable = true;
+        programs.steam.enable = true;
+
+        ###
+        ##  Services
+        ###
+        services.openssh.enable = true;
+        services.dbus.enable = true;
+        services.pipewire = {
+          enable = true;
+          alsa.enable = true;
+          pulse.enable = true;
+        };
+
+        # Firewall
+        networking.firewall = {
+          enable = true;
+          allowedTCPPortRanges = [
+              {from = 1714; to = 1764;} # KDE Connnect
+          ];
+          allowedUDPPortRanges = [
+              {from = 1714; to = 1764;} # KDE Connnect
+          ];
+        };
+
+        ###
+        ##  Misc
+        ###
+        sound.enable = true;
+        # Necessary for home-manager sway setup
+        security.polkit.enable = true;
+
+        hardware.opengl = {
+        enable = true;
+            driSupport = true;
+        };
+
+    };
+}
diff --git a/nixos/default.nix b/nixos/default.nix
new file mode 100644
index 0000000..df062b4
--- /dev/null
+++ b/nixos/default.nix
@@ -0,0 +1,24 @@
+
+# Edit this configuration file to define what should be installed on
+# your system. Help is available in the configuration.nix(5) man page, on
+# https://search.nixos.org/options and in the NixOS manual (`nixos-help`).
+
+{ config, lib, pkgs, userName, hostName, ... }:
+
+{
+  imports =
+    [ # Include the results of the hardware scan.
+      ./hardware-configuration.nix
+      ./sway_configuration.nix
+      # ../modules/user/main_user.nix
+      # ../modules/sway/sway_conf.nix
+    ];
+
+  # Enable flakes feature
+  nix.settings.experimental-features = [
+    "nix-command" "flakes"
+  ];
+
+  system.stateVersion = "23.11"; # Did you read the comment?
+}
+
diff --git a/nixos/sway_configuration.nix b/nixos/sway_configuration.nix
index d25a1ab..fa3811d 100644
--- a/nixos/sway_configuration.nix
+++ b/nixos/sway_configuration.nix
@@ -9,6 +9,7 @@
     [ # Include the results of the hardware scan.
       ./hardware-configuration.nix
       ../modules/user/main_user.nix
+      ../modules/sway/sway_conf.nix
     ];
 
   # Enable flakes feature
@@ -16,7 +17,7 @@
     "nix-command" "flakes"
   ];
 
-  nixpkgs.config.allowUnfree = true;
+  # nixpkgs.config.allowUnfree = true;
 
   # Use the systemd-boot EFI boot loader.
   boot.loader.systemd-boot.enable = true;
@@ -54,37 +55,37 @@
   # Enable CUPS to print documents.
   # services.printing.enable = true;
 
-  sound.enable = true;
+  # sound.enable = true;
   # hardware.pulseaudio.enable = true;
 
   # Enable touchpad support (enabled default in most desktopManager).
   # services.xserver.libinput.enable = true;
 
   # enable polkit for sway in home-manager
-  security.polkit.enable = true;
+  # security.polkit.enable = true;
 
-  hardware.opengl = {
-      enable = true;
-      driSupport = true;
-  };
+  # hardware.opengl = {
+  #     enable = true;
+  #     driSupport = true;
+  # };
 
   # Setup xdg portal for screen share
-  xdg.portal = {
-      config = {
-          common = {
-            default = [
-              "wlr"
-            ];
-          };
-      };
-      extraPortals = with pkgs; [
-          # xdg-desktop-portal-kde
-          xdg-desktop-portal-gtk
-      ];
-      wlr.enable = true;
-      enable = true;
-  };
-  xdg.sounds.enable = true;
+  # xdg.portal = {
+  #     config = {
+  #         common = {
+  #           default = [
+  #             "wlr"
+  #           ];
+  #         };
+  #     };
+  #     extraPortals = with pkgs; [
+  #         # xdg-desktop-portal-kde
+  #         xdg-desktop-portal-gtk
+  #     ];
+  #     wlr.enable = true;
+  #     enable = true;
+  # };
+  # xdg.sounds.enable = true;
 
   main_user = {
     enable = true;
@@ -92,47 +93,55 @@
     isDesktopUser = true;
   };
 
-  programs.zsh.enable = true;
-  programs.steam.enable = true;
+  swaywm = {
+      enable = true;
+      useNonFree = true;
+      systemPackages = with pkgs; [
+          # corectrl
+      ];
+  };
+
+  # programs.zsh.enable = true;
+  # programs.steam.enable = true;
 
   # Corectrl from stable branch
   # inputs.nixpkgs-stable.lib.nixosSystem.programs.corectrl.enable = true;
   # programs.corectrl.enable = true;
 
-  environment.systemPackages = with pkgs; [
-    git
-    glib # gsettings
-    grim
-    pavucontrol
-    slurp
-    swaylock
-    swayidle
-    wget
-    wl-clipboard
-    xdg-utils
-    zsh
-  ];
+  # environment.systemPackages = with pkgs; [
+  #   git
+  #   glib # gsettings
+  #   grim
+  #   pavucontrol
+  #   slurp
+  #   swaylock
+  #   swayidle
+  #   wget
+  #   wl-clipboard
+  #   xdg-utils
+  #   zsh
+  # ];
 
   # Services
-  services.flatpak.enable = true;
-  services.openssh.enable = true;
-  services.dbus.enable = true;
-  services.pipewire = {
-      enable = true;
-      alsa.enable = true;
-      pulse.enable = true;
-  };
+  # services.flatpak.enable = true;
+  # services.openssh.enable = true;
+  # services.dbus.enable = true;
+  # services.pipewire = {
+  #     enable = true;
+  #     alsa.enable = true;
+  #     pulse.enable = true;
+  # };
 
   # Firewall
-  networking.firewall = {
-      enable = true;
-      allowedTCPPortRanges = [
-          {from = 1714; to = 1764;} # KDE Connnect
-      ];
-      allowedUDPPortRanges = [
-          {from = 1714; to = 1764;} # KDE Connnect
-      ];
-  };
+  # networking.firewall = {
+  #     enable = true;
+  #     allowedTCPPortRanges = [
+  #         {from = 1714; to = 1764;} # KDE Connnect
+  #     ];
+  #     allowedUDPPortRanges = [
+  #         {from = 1714; to = 1764;} # KDE Connnect
+  #     ];
+  # };
 
   # Copy the NixOS configuration file and link it from the resulting system
   # (/run/current-system/configuration.nix). This is useful in case you