From 26072b5cffa41401a223d3008937a7db320f494c Mon Sep 17 00:00:00 2001 From: Oliver Davies Date: Wed, 9 Jul 2025 02:12:31 +0100 Subject: [PATCH] Extract flake modules --- flake-modules/dev-shell.nix | 14 ++++ flake-modules/formatting.nix | 7 ++ flake-modules/nixos-configurations.nix | 47 +++++++++++++ flake-modules/packages.nix | 21 ++++++ flake.nix | 91 ++++---------------------- 5 files changed, 101 insertions(+), 79 deletions(-) create mode 100644 flake-modules/dev-shell.nix create mode 100644 flake-modules/formatting.nix create mode 100644 flake-modules/nixos-configurations.nix create mode 100644 flake-modules/packages.nix diff --git a/flake-modules/dev-shell.nix b/flake-modules/dev-shell.nix new file mode 100644 index 00000000..89037018 --- /dev/null +++ b/flake-modules/dev-shell.nix @@ -0,0 +1,14 @@ +{ + perSystem = + { pkgs, ... }: + { + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + just + lua-language-server + lua54Packages.luacheck + nixd + ]; + }; + }; +} diff --git a/flake-modules/formatting.nix b/flake-modules/formatting.nix new file mode 100644 index 00000000..3c962b13 --- /dev/null +++ b/flake-modules/formatting.nix @@ -0,0 +1,7 @@ +{ + perSystem = + { pkgs, ... }: + { + formatter = pkgs.nixfmt-rfc-style; + }; +} diff --git a/flake-modules/nixos-configurations.nix b/flake-modules/nixos-configurations.nix new file mode 100644 index 00000000..2d3c949b --- /dev/null +++ b/flake-modules/nixos-configurations.nix @@ -0,0 +1,47 @@ +{ inputs, self, ... }: + +{ + flake = + let + inherit (self) outputs; + + specialArgs = { + inherit inputs outputs self; + + system = "x86_64-linux"; + username = "opdavies"; + }; + + mkNixosConfiguration = + { + hostname, + stateVersion ? "22.11", + system ? "x86_64-linux", + }: + inputs.nixpkgs.lib.nixosSystem { + inherit system; + + modules = [ "${self}/hosts/${hostname}/configuration.nix" ]; + + specialArgs = specialArgs // { + inherit hostname stateVersion system; + }; + }; + in + { + nixosConfigurations = { + lemp11 = mkNixosConfiguration { hostname = "lemp11"; }; + + nixedo = mkNixosConfiguration { + hostname = "nixedo"; + stateVersion = "24.11"; + }; + + t480 = mkNixosConfiguration { hostname = "t480"; }; + + t490 = mkNixosConfiguration { hostname = "t490"; }; + + PW05CH3L = mkNixosConfiguration { hostname = "PW05CH3L"; }; + }; + }; +} diff --git a/flake-modules/packages.nix b/flake-modules/packages.nix new file mode 100644 index 00000000..270356d7 --- /dev/null +++ b/flake-modules/packages.nix @@ -0,0 +1,21 @@ +{ inputs, self, ... }: + +{ + perSystem = + { pkgs, system, ... }: + let + # TODO: refactor to use inputs' or similar. + nixvim = inputs.nixvim.legacyPackages.${system}.makeNixvimWithModule { + inherit pkgs; + + module = import "${self}/modules/home-manager/coding/neovim/config"; + }; + in + { + packages = { + inherit nixvim; + + default = pkgs.mkShell { buildInputs = with pkgs; [ just ]; }; + }; + }; +} diff --git a/flake.nix b/flake.nix index 876eaf42..5f2bf7af 100644 --- a/flake.nix +++ b/flake.nix @@ -27,89 +27,22 @@ }; outputs = - inputs@{ - flake-parts, - nixpkgs, - self, - ... - }: + inputs@{ flake-parts, ... }: flake-parts.lib.mkFlake { inherit inputs; } { - flake = - let - inherit (self) outputs; + flake = { + homeManagerModules.default = import ./modules/home-manager; - specialArgs = { - inherit inputs outputs self; + nixosModules.default = import ./modules/nixos; - system = "x86_64-linux"; - username = "opdavies"; - }; + overlays = import ./overlays { inherit inputs; }; + }; - mkNixosConfiguration = - { - hostname, - stateVersion ? "22.11", - system ? "x86_64-linux", - }: - nixpkgs.lib.nixosSystem { - inherit system; - - modules = [ ./hosts/${hostname}/configuration.nix ]; - - specialArgs = specialArgs // { - inherit hostname stateVersion system; - }; - }; - in - { - homeManagerModules.default = import ./modules/home-manager; - - nixosConfigurations = { - lemp11 = mkNixosConfiguration { hostname = "lemp11"; }; - - nixedo = mkNixosConfiguration { - hostname = "nixedo"; - stateVersion = "24.11"; - }; - - t480 = mkNixosConfiguration { hostname = "t480"; }; - t490 = mkNixosConfiguration { hostname = "t490"; }; - PW05CH3L = mkNixosConfiguration { hostname = "PW05CH3L"; }; - }; - - nixosModules.default = import ./modules/nixos; - - overlays = import ./overlays { inherit inputs; }; - }; - - perSystem = - { pkgs, system, ... }: - let - # TODO: refactor to use inputs' or similar. - nixvim = inputs.nixvim.legacyPackages.${system}.makeNixvimWithModule { - inherit pkgs; - - module = import ./modules/home-manager/coding/neovim/config; - }; - in - { - devShells.default = pkgs.mkShell { - packages = with pkgs; [ - just - lua-language-server - lua54Packages.luacheck - nixd - ]; - }; - - formatter = pkgs.nixfmt-rfc-style; - - packages = { - inherit nixvim; - - default = pkgs.mkShell { buildInputs = with pkgs; [ just ]; }; - }; - }; + imports = [ + ./flake-modules/dev-shell.nix + ./flake-modules/formatting.nix + ./flake-modules/nixos-configurations.nix + ./flake-modules/packages.nix + ]; systems = [ "x86_64-linux" ]; };