From 349a155e845d71a1c2ba42b22d60bc41791b89dc Mon Sep 17 00:00:00 2001 From: Gabe Dunn Date: Thu, 28 Mar 2024 17:56:42 -0700 Subject: [PATCH] overhaul modules, move to flake module --- flake.nix | 66 ++++++-------------------- modules/default.nix | 66 -------------------------- modules/flake/modules.nix | 87 ++++++++++++++++++++++++++++++++++ modules/flake/nix.nix | 55 +++++++++++++++++++++ modules/flake/overlays.nix | 3 -- modules/nixos/base/cli.nix | 2 +- modules/nixos/base/default.nix | 2 +- nix.nix | 45 ------------------ 8 files changed, 158 insertions(+), 168 deletions(-) delete mode 100644 modules/default.nix create mode 100644 modules/flake/modules.nix create mode 100644 modules/flake/nix.nix delete mode 100644 nix.nix diff --git a/flake.nix b/flake.nix index 5cd32fe8..8e346a7d 100644 --- a/flake.nix +++ b/flake.nix @@ -51,80 +51,42 @@ }; outputs = inputs@{ self, nixpkgs, home-manager, flake-parts, hardware, ... }: - let - realHostNames = [ "bastion" "voyager" "quasar" ]; - - extraSpecialArgs = { - inherit inputs realHostNames; - inherit (self) overlays; - }; - - modules = (import ./modules { - inherit inputs extraSpecialArgs; - inherit (self) nixosModules homeManagerModules lib overlays; - }); - in flake-parts.lib.mkFlake { inherit inputs; } { + flake-parts.lib.mkFlake { inherit inputs; } { imports = [ ./modules/flake/deploy.nix + ./modules/flake/nix.nix + ./modules/flake/modules.nix ./modules/flake/overlays.nix ./modules/flake/shell.nix ]; systems = [ "x86_64-linux" "aarch64-linux" ]; - flake = let lib = nixpkgs.lib // home-manager.lib; - in { - inherit lib; - - nixosModules = import ./modules/nixos; - homeManagerModules = import ./modules/home-manager; - - overlays = import ./overlays { inherit inputs; }; - - nixosConfigurations = let - specialArgs = { - inherit inputs realHostNames; - inherit (self) overlays homeManagerModules; - }; - in { + flake = { + nixosConfigurations = { # main desktop - bastion = lib.nixosSystem { - inherit specialArgs; + bastion = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; - modules = modules.nixos.bastion; + modules = [ self.nixosModules.bastion ]; }; # laptop - voyager = lib.nixosSystem { - inherit specialArgs; + voyager = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; - modules = modules.nixos.voyager; + modules = [ self.nixosModules.voyager ]; }; # nas & media server - quasar = lib.nixosSystem { - inherit specialArgs; + quasar = nixpkgs.lib.nixosSystem { system = "x86_64-linux"; - modules = modules.nixos.quasar; + modules = [ self.nixosModules.quasar ]; }; - # # raspi - ?? - # gizmo = lib.nixosSystem { - # inherit specialArgs; - # modules = [ ./hosts/gizmo ] ++ commonModules; - # }; - # # nixiso - # nixiso = lib.nixosSystem { - # inherit specialArgs; - # modules = [ ./hosts/nixiso ] ++ commonModules; - # system = "x86_64-linux"; - # }; }; homeConfigurations = { - "gabe@deck" = lib.homeManagerConfiguration { - inherit extraSpecialArgs; - modules = modules.home-manager.deck; + "gabe@deck" = home-manager.lib.homeManagerConfiguration { + modules = [ self.homeManagerModules.deck ]; pkgs = import nixpkgs { + inherit (self.nixCfg.nixpkgs) config overlays; system = "x86_64-linux"; - config.allowUnfree = true; }; }; }; diff --git a/modules/default.nix b/modules/default.nix deleted file mode 100644 index 75b366b0..00000000 --- a/modules/default.nix +++ /dev/null @@ -1,66 +0,0 @@ -{ inputs, lib, nixosModules, homeManagerModules, specialArgs, extraSpecialArgs -, overlays, ... }: - -let - nixcfg = (import ../nix.nix { inherit inputs lib overlays; }); - - homeCommon = [ - inputs.hyprland.homeManagerModules.default - inputs.sops-nix.homeManagerModules.sops - inputs.nix-flatpak.homeManagerModules.nix-flatpak - - { config = { inherit (nixcfg) nix; }; } - ] ++ (builtins.attrValues homeManagerModules); -in rec { - nixos = { - common = [ - ../hosts/common - - inputs.home-manager.nixosModules.home-manager - inputs.hyprland.nixosModules.default - inputs.nh.nixosModules.default - inputs.nix-flatpak.nixosModules.nix-flatpak - inputs.solaar.nixosModules.default - inputs.sops-nix.nixosModules.sops - inputs.xremap-flake.nixosModules.default - - { config = { inherit (nixcfg) nix nixpkgs; }; } - { - config.home-manager = { - inherit extraSpecialArgs; - sharedModules = homeCommon; - useGlobalPkgs = true; - }; - } - ] ++ (builtins.attrValues nixosModules); - - bastion = [ - ../hosts/bastion - - inputs.hardware.nixosModules.common-cpu-amd - inputs.hardware.nixosModules.common-gpu-amd - inputs.hardware.nixosModules.common-pc-ssd - - inputs.disko.nixosModules.disko - ] ++ nixos.common; - voyager = [ - ../hosts/voyager - - inputs.hardware.nixosModules.dell-xps-15-7590-nvidia - inputs.hardware.nixosModules.common-cpu-intel-cpu-only - inputs.hardware.nixosModules.common-gpu-nvidia-nonprime - inputs.hardware.nixosModules.common-pc-ssd - ] ++ nixos.common; - - quasar = [ - ../hosts/quasar - - inputs.hardware.nixosModules.common-cpu-intel-cpu-only - inputs.hardware.nixosModules.common-gpu-nvidia-nonprime - inputs.hardware.nixosModules.common-pc-ssd - ] ++ nixos.common; - }; - - home-manager = let common = [{ imports = homeCommon; }]; - in { deck = [ ../home/gabe/deck.nix ] ++ common; }; -} diff --git a/modules/flake/modules.nix b/modules/flake/modules.nix new file mode 100644 index 00000000..ae646a99 --- /dev/null +++ b/modules/flake/modules.nix @@ -0,0 +1,87 @@ +{ self, inputs, lib, ... }: + +let inherit (builtins) attrValues; +in { + flake = let + realHostNames = [ "bastion" "voyager" "quasar" ]; + + allNixos = import ../nixos; + allHomeManager = import ../home-manager; + + homeCommon = [ + inputs.hyprland.homeManagerModules.default + inputs.sops-nix.homeManagerModules.sops + inputs.nix-flatpak.homeManagerModules.nix-flatpak + + { + config = { + inherit (self.nixCfg) nix; + + _module.args = { inherit realHostNames; }; + }; + } + ] ++ attrValues allHomeManager; + + nixosCommon = [ + inputs.home-manager.nixosModules.home-manager + inputs.hyprland.nixosModules.default + inputs.nh.nixosModules.default + inputs.nix-flatpak.nixosModules.nix-flatpak + inputs.solaar.nixosModules.default + inputs.sops-nix.nixosModules.sops + inputs.xremap-flake.nixosModules.default + + ../../hosts/common + + { + config = { + inherit (self.nixCfg) nix nixpkgs; + + _module.args = { inherit realHostNames; }; + + home-manager = { + sharedModules = homeCommon; + useGlobalPkgs = true; + }; + }; + } + ] ++ attrValues allNixos; + in { + nixosModules = { + common = nixosCommon; + + bastion.imports = [ + ../../hosts/bastion + + inputs.hardware.nixosModules.common-cpu-amd + inputs.hardware.nixosModules.common-gpu-amd + inputs.hardware.nixosModules.common-pc-ssd + + inputs.disko.nixosModules.disko + ] ++ nixosCommon; + + voyager.imports = [ + ../../hosts/voyager + + inputs.hardware.nixosModules.dell-xps-15-7590-nvidia + inputs.hardware.nixosModules.common-cpu-intel-cpu-only + inputs.hardware.nixosModules.common-gpu-nvidia-nonprime + inputs.hardware.nixosModules.common-pc-ssd + ] ++ nixosCommon; + + quasar.imports = [ + ../../hosts/quasar + + inputs.hardware.nixosModules.common-cpu-intel-cpu-only + inputs.hardware.nixosModules.common-gpu-nvidia-nonprime + inputs.hardware.nixosModules.common-pc-ssd + ] ++ nixosCommon; + } // allNixos; + + homeManagerModules = { + common = homeCommon; + + deck.imports = [ ../../home/gabe/deck.nix ] ++ homeCommon; + } // allNixos; + }; +} diff --git a/modules/flake/nix.nix b/modules/flake/nix.nix new file mode 100644 index 00000000..ebb3002a --- /dev/null +++ b/modules/flake/nix.nix @@ -0,0 +1,55 @@ +{ self, inputs, lib, ... }: + +{ + flake = { + nixCfg = { + nix = { + settings = { + trusted-users = [ "root" "@wheel" "gabe" ]; + experimental-features = [ "nix-command" "flakes" "repl-flake" ]; + substituters = [ + "https://cache.nixos.org" + "https://nix-community.cachix.org" + "https://devenv.cachix.org" + "https://gabedunn.cachix.org" + "https://hyprland.cachix.org" + ]; + trusted-public-keys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" + "gabedunn.cachix.org-1:wLWTKadNjpr2Op3rBnDZMUmUEPPIoKG87oY4PmBP8qU=" + "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" + ]; + auto-optimise-store = lib.mkDefault true; + warn-dirty = false; + system-features = [ "kvm" "big-parallel" "nixos-test" ]; + }; + gc = { + automatic = true; + options = "--delete-older-than 5d"; + }; + + # add each flake input as a registry + # to make nix3 commands consistent with the flake + registry = lib.mapAttrs (_: value: { flake = value; }) inputs; + }; + + nixpkgs = { + overlays = builtins.attrValues self.overlays; + config = { + allowUnfree = true; + permittedInsecurePackages = [ "electron-25.9.0" ]; + nvidia.acceptLicense = true; + }; + }; + }; + }; + + perSystem = { config, self', inputs', pkgs, system, ... }: { + _module.args.pkgs = import inputs.nixpkgs { + inherit system; + inherit (self.nixCfg.nixpkgs) config overlays; + }; + }; +} diff --git a/modules/flake/overlays.nix b/modules/flake/overlays.nix index c2c58741..fa0429a1 100644 --- a/modules/flake/overlays.nix +++ b/modules/flake/overlays.nix @@ -84,9 +84,6 @@ neovim-nightly = inputs.neovim-nightly-overlay.overlay; rust-overlay = inputs.rust-overlay.overlays.default; # nur = inputs.nur.overlay; - # inputs.nix-minecraft.overlay }; }; - - # perSystem = { config, self', inputs', pkgs, system, ... }: { }; } diff --git a/modules/nixos/base/cli.nix b/modules/nixos/base/cli.nix index f317d71c..55a5ce8b 100644 --- a/modules/nixos/base/cli.nix +++ b/modules/nixos/base/cli.nix @@ -1,4 +1,4 @@ -{ inputs, pkgs, lib, config, ... }: +{ pkgs, lib, config, ... }: let inherit (lib) mkIf; diff --git a/modules/nixos/base/default.nix b/modules/nixos/base/default.nix index 098115e0..39db02ef 100644 --- a/modules/nixos/base/default.nix +++ b/modules/nixos/base/default.nix @@ -1,4 +1,4 @@ -{ pkgs, lib, config, overlays, ... }: +{ pkgs, lib, config, ... }: let inherit (lib) mkIf mkDefault mkOption mkEnableOption optional; diff --git a/nix.nix b/nix.nix deleted file mode 100644 index 5f835462..00000000 --- a/nix.nix +++ /dev/null @@ -1,45 +0,0 @@ -{ inputs, lib, overlays, ... }: - -{ - nix = { - settings = { - trusted-users = [ "root" "@wheel" "gabe" ]; - experimental-features = [ "nix-command" "flakes" "repl-flake" ]; - substituters = [ - "https://cache.nixos.org" - "https://nix-community.cachix.org" - "https://devenv.cachix.org" - "https://gabedunn.cachix.org" - "https://hyprland.cachix.org" - ]; - trusted-public-keys = [ - "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" - "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" - "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" - "gabedunn.cachix.org-1:wLWTKadNjpr2Op3rBnDZMUmUEPPIoKG87oY4PmBP8qU=" - "hyprland.cachix.org-1:a7pgxzMz7+chwVL3/pzj6jIBMioiJM7ypFP8PwtkuGc=" - ]; - auto-optimise-store = lib.mkDefault true; - warn-dirty = false; - system-features = [ "kvm" "big-parallel" "nixos-test" ]; - }; - gc = { - automatic = true; - options = "--delete-older-than 5d"; - }; - - # add each flake input as a registry - # to make nix3 commands consistent with the flake - registry = lib.mapAttrs (_: value: { flake = value; }) inputs; - }; - - nixpkgs = { - overlays = builtins.attrValues overlays; - config = { - allowUnfree = true; - permittedInsecurePackages = [ "electron-25.9.0" ]; - nvidia.acceptLicense = true; - }; - }; -} -