diff --git a/flake.nix b/flake.nix index 8cf0049..1d8a666 100644 --- a/flake.nix +++ b/flake.nix @@ -86,7 +86,7 @@ modules = [ sops-nix.nixosModules.sops home-manager.nixosModules.home-manager - ./modules/default.nix + ./modules/linux/default.nix ({ pkgs, lib, config, ... }: { # Configure hostname networking = { diff --git a/modules/base.nix b/modules/base.nix deleted file mode 100644 index 5169a2e..0000000 --- a/modules/base.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ config, lib, pkgs, ... }: - -with lib; { - - config = { - nix = mkIf config.nathan.config.nix.autoGC { - gc = { - automatic = true; - dates = "weekly"; - options = "--delete-older-than 7d"; - }; - }; - }; -} diff --git a/modules/linux/base.nix b/modules/linux/base.nix index bc0b0ec..5169a2e 100644 --- a/modules/linux/base.nix +++ b/modules/linux/base.nix @@ -1,59 +1,14 @@ -{ config, lib, pkgs, inputs, ... }@attrs: -with lib; -{ - config = mkMerge [ - (mkIf pkgs.stdenv.isLinux - { - zramSwap = mkIf config.nathan.services.zramSwap - { - enable = true; - algorithm = "lz4"; - memoryPercent = 25; - }; - nix = mkIf config.nathan.config.nix.autoGC { - autoOptimiseStore = true; - }; - }) - (mkIf config.nathan.config.harden (import "${inputs.nixpkgs}/nixos/modules/profiles/hardened.nix" attrs)) - (mkIf config.nathan.config.harden { - boot.kernelPackages = pkgs.linuxPackages_5_18_hardened; - security = { - allowSimultaneousMultithreading = true; - unprivilegedUsernsClone = true; +{ config, lib, pkgs, ... }: + +with lib; { + + config = { + nix = mkIf config.nathan.config.nix.autoGC { + gc = { + automatic = true; + dates = "weekly"; + options = "--delete-older-than 7d"; }; - }) - (mkIf ((! config.nathan.config.harden) && config.nathan.config.isDesktop) { - # Use the zen kernel with muqss turned on - boot.kernelPackages = - let - linuxZenWMuQSS = pkgs.linuxPackagesFor (pkgs.linuxPackages_zen.kernel.override { - structuredExtraConfig = with lib.kernel; { - SCHED_MUQSS = yes; - }; - ignoreConfigErrors = true; - } - ); - in - linuxZenWMuQSS; - }) - (mkIf - (config.nathan.config.nix.autoUpdate && pkgs.stdenv.isLinux) - { - # Auto update daily at 2 am - system.autoUpgrade = { - enable = true; - allowReboot = true; - # Update from the flake - flake = "github:nathans-flakes/system"; - # Attempt to update daily at 2AM - dates = "2:00"; - }; - }) - # Systemd user service cludge - { - systemd.user.extraConfig = '' - DefaultEnvironment="PATH=/run/current-system/sw/bin:/etc/profiles/per-user/${config.nathan.config.user}/bin" - ''; - } - ]; + }; + }; } diff --git a/modules/linux/default.nix b/modules/linux/default.nix new file mode 100644 index 0000000..85f3869 --- /dev/null +++ b/modules/linux/default.nix @@ -0,0 +1,44 @@ +{ config, lib, pkgs, ... }: +let + inherit (import ../lib.nix { inherit lib; inherit pkgs; }) nLib; +in +{ + imports = [ + ../options.nix + ./base.nix + ./user.nix + ./desktop.nix + ./swaywm.nix + ./hardware.nix + ./virtualization.nix + ./windows.nix + ./programs/games.nix + ./programs/gpg.nix + ./programs/utils.nix + ./services/ssh.nix + ./services/tailscale.nix + ./services/borg.nix + ./services/nginx.nix + ./services/matrix.nix + ./linux/base.nix + ]; + + config = { + # Enable the firewall + networking.firewall.enable = true; + # Enable unfree packages + nixpkgs.config.allowUnfree = config.nathan.config.enableUnfree; + # Work around for discord jank ugh + nixpkgs.config.permittedInsecurePackages = [ + "electron-13.6.9" + ]; + # Set system state version + system.stateVersion = "22.05"; + # Enable flakes + # Enable nix flakes + nix.package = pkgs.nixFlakes; + nix.extraOptions = '' + experimental-features = nix-command flakes + ''; + }; +} diff --git a/modules/desktop.nix b/modules/linux/desktop.nix similarity index 100% rename from modules/desktop.nix rename to modules/linux/desktop.nix diff --git a/modules/hardware.nix b/modules/linux/hardware.nix similarity index 100% rename from modules/hardware.nix rename to modules/linux/hardware.nix diff --git a/modules/linux/linux/base.nix b/modules/linux/linux/base.nix new file mode 100644 index 0000000..bc0b0ec --- /dev/null +++ b/modules/linux/linux/base.nix @@ -0,0 +1,59 @@ +{ config, lib, pkgs, inputs, ... }@attrs: +with lib; +{ + config = mkMerge [ + (mkIf pkgs.stdenv.isLinux + { + zramSwap = mkIf config.nathan.services.zramSwap + { + enable = true; + algorithm = "lz4"; + memoryPercent = 25; + }; + nix = mkIf config.nathan.config.nix.autoGC { + autoOptimiseStore = true; + }; + }) + (mkIf config.nathan.config.harden (import "${inputs.nixpkgs}/nixos/modules/profiles/hardened.nix" attrs)) + (mkIf config.nathan.config.harden { + boot.kernelPackages = pkgs.linuxPackages_5_18_hardened; + security = { + allowSimultaneousMultithreading = true; + unprivilegedUsernsClone = true; + }; + }) + (mkIf ((! config.nathan.config.harden) && config.nathan.config.isDesktop) { + # Use the zen kernel with muqss turned on + boot.kernelPackages = + let + linuxZenWMuQSS = pkgs.linuxPackagesFor (pkgs.linuxPackages_zen.kernel.override { + structuredExtraConfig = with lib.kernel; { + SCHED_MUQSS = yes; + }; + ignoreConfigErrors = true; + } + ); + in + linuxZenWMuQSS; + }) + (mkIf + (config.nathan.config.nix.autoUpdate && pkgs.stdenv.isLinux) + { + # Auto update daily at 2 am + system.autoUpgrade = { + enable = true; + allowReboot = true; + # Update from the flake + flake = "github:nathans-flakes/system"; + # Attempt to update daily at 2AM + dates = "2:00"; + }; + }) + # Systemd user service cludge + { + systemd.user.extraConfig = '' + DefaultEnvironment="PATH=/run/current-system/sw/bin:/etc/profiles/per-user/${config.nathan.config.user}/bin" + ''; + } + ]; +} diff --git a/modules/programs/games.nix b/modules/linux/programs/games.nix similarity index 83% rename from modules/programs/games.nix rename to modules/linux/programs/games.nix index 8bb62f7..1ef08e8 100644 --- a/modules/programs/games.nix +++ b/modules/linux/programs/games.nix @@ -10,8 +10,8 @@ with lib; # https://github.com/Admicos/minecraft-wayland glfw-patched = pkgs.glfw-wayland.overrideAttrs (attrs: { patches = attrs.patches ++ [ - ../../patches/minecraft/0003-Don-t-crash-on-calls-to-focus-or-icon.patch - ../../patches/minecraft/0004-wayland-fix-broken-opengl-screenshots-on-mutter.patch + ../../../patches/minecraft/0003-Don-t-crash-on-calls-to-focus-or-icon.patch + ../../../patches/minecraft/0004-wayland-fix-broken-opengl-screenshots-on-mutter.patch ]; }); stable-packages = with pkgs; [ diff --git a/modules/programs/gpg.nix b/modules/linux/programs/gpg.nix similarity index 100% rename from modules/programs/gpg.nix rename to modules/linux/programs/gpg.nix diff --git a/modules/programs/utils.nix b/modules/linux/programs/utils.nix similarity index 100% rename from modules/programs/utils.nix rename to modules/linux/programs/utils.nix diff --git a/modules/services/borg.nix b/modules/linux/services/borg.nix similarity index 100% rename from modules/services/borg.nix rename to modules/linux/services/borg.nix diff --git a/modules/services/matrix.nix b/modules/linux/services/matrix.nix similarity index 100% rename from modules/services/matrix.nix rename to modules/linux/services/matrix.nix diff --git a/modules/services/nginx.nix b/modules/linux/services/nginx.nix similarity index 100% rename from modules/services/nginx.nix rename to modules/linux/services/nginx.nix diff --git a/modules/services/ssh.nix b/modules/linux/services/ssh.nix similarity index 100% rename from modules/services/ssh.nix rename to modules/linux/services/ssh.nix diff --git a/modules/services/tailscale.nix b/modules/linux/services/tailscale.nix similarity index 96% rename from modules/services/tailscale.nix rename to modules/linux/services/tailscale.nix index b37a408..27664e3 100644 --- a/modules/services/tailscale.nix +++ b/modules/linux/services/tailscale.nix @@ -16,7 +16,7 @@ with lib; # Setup sops sops.secrets."tailscale-auth" = { - sopsFile = ../../secrets/all/tailscale.yaml; + sopsFile = ../../../secrets/all/tailscale.yaml; format = "yaml"; }; diff --git a/modules/swaywm.nix b/modules/linux/swaywm.nix similarity index 100% rename from modules/swaywm.nix rename to modules/linux/swaywm.nix diff --git a/modules/user.nix b/modules/linux/user.nix similarity index 100% rename from modules/user.nix rename to modules/linux/user.nix diff --git a/modules/virtualization.nix b/modules/linux/virtualization.nix similarity index 100% rename from modules/virtualization.nix rename to modules/linux/virtualization.nix diff --git a/modules/windows.nix b/modules/linux/windows.nix similarity index 78% rename from modules/windows.nix rename to modules/linux/windows.nix index 734fd45..1bed9c4 100644 --- a/modules/windows.nix +++ b/modules/linux/windows.nix @@ -23,8 +23,8 @@ with lib;{ serviceConfig = { Type = "forking"; ExecStart = - "${../scripts/windows/mount.sh} ${mount.device} ${mount.mountPoint} ${mount.keyFile}"; - ExecStop = "${../scripts/windows/unmount.sh} ${mount.device} ${mount.mountPoint}"; + "${../../scripts/windows/mount.sh} ${mount.device} ${mount.mountPoint} ${mount.keyFile}"; + ExecStop = "${../../scripts/windows/unmount.sh} ${mount.device} ${mount.mountPoint}"; }; }; }; diff --git a/modules/default.nix b/modules/options.nix similarity index 88% rename from modules/default.nix rename to modules/options.nix index c5adcc8..e1ec302 100644 --- a/modules/default.nix +++ b/modules/options.nix @@ -1,27 +1,9 @@ { config, lib, pkgs, ... }: + let inherit (import ./lib.nix { inherit lib; inherit pkgs; }) nLib; in { - imports = [ - ./base.nix - ./user.nix - ./desktop.nix - ./swaywm.nix - ./hardware.nix - ./virtualization.nix - ./windows.nix - ./programs/games.nix - ./programs/gpg.nix - ./programs/utils.nix - ./services/ssh.nix - ./services/tailscale.nix - ./services/borg.nix - ./services/nginx.nix - ./services/matrix.nix - ./linux/base.nix - ]; - options = with lib; with nLib; { nathan = { # Control enabling of services @@ -199,23 +181,4 @@ in }; }; }; - - config = { - # Enable the firewall - networking.firewall.enable = true; - # Enable unfree packages - nixpkgs.config.allowUnfree = config.nathan.config.enableUnfree; - # Work around for discord jank ugh - nixpkgs.config.permittedInsecurePackages = [ - "electron-13.6.9" - ]; - # Set system state version - system.stateVersion = "22.05"; - # Enable flakes - # Enable nix flakes - nix.package = pkgs.nixFlakes; - nix.extraOptions = '' - experimental-features = nix-command flakes - ''; - }; }