From 19a4bbda3cbe599f330708c25ba20b2b361348ca Mon Sep 17 00:00:00 2001 From: ooks-io Date: Sun, 20 Oct 2024 13:55:00 +1300 Subject: [PATCH] flake: add builder lib & formatter flake: add builder lib & formatter flake: add builder lib & formatter flake: add builder lib & formatter --- flake.nix | 24 ++--------- outputs/default.nix | 9 ++++ outputs/formatter.nix | 5 +++ outputs/lib/builders.nix | 91 ++++++++++++++++++++++++++++++++++++++++ outputs/lib/default.nix | 12 ++++++ outputs/nixos.nix | 79 ++++++++++++++++------------------ 6 files changed, 157 insertions(+), 63 deletions(-) create mode 100644 outputs/default.nix create mode 100644 outputs/formatter.nix create mode 100644 outputs/lib/builders.nix create mode 100644 outputs/lib/default.nix diff --git a/flake.nix b/flake.nix index d7630c1..a7a655c 100644 --- a/flake.nix +++ b/flake.nix @@ -2,27 +2,11 @@ # ooknet description = "a nix configuration written by an orangutan"; - outputs = { - flake-parts, - self, - ... - } @ inputs: - flake-parts.lib.mkFlake {inherit inputs;} ({withSystem, ...}: { + outputs = {flake-parts, ...} @ inputs: + flake-parts.lib.mkFlake {inherit inputs;} { systems = import inputs.systems; - - imports = [ - ./outputs/pkgs - ./outputs/sshKeys.nix - ]; - - flake = { - nixosConfigurations = import ./outputs/nixos.nix {inherit self inputs withSystem;}; - }; - - perSystem = {pkgs, ...}: { - formatter = pkgs.alejandra; - }; - }); + imports = [./outputs]; + }; # External inputs we depend on inputs = { diff --git a/outputs/default.nix b/outputs/default.nix new file mode 100644 index 0000000..635c85f --- /dev/null +++ b/outputs/default.nix @@ -0,0 +1,9 @@ +{ + imports = [ + ./nixos.nix + ./sshKeys.nix + ./formatter.nix + ./lib + ./pkgs + ]; +} diff --git a/outputs/formatter.nix b/outputs/formatter.nix new file mode 100644 index 0000000..18380d0 --- /dev/null +++ b/outputs/formatter.nix @@ -0,0 +1,5 @@ +_: { + perSystem = {pkgs, ...}: { + formatter = pkgs.alejandra; + }; +} diff --git a/outputs/lib/builders.nix b/outputs/lib/builders.nix new file mode 100644 index 0000000..e0b03fd --- /dev/null +++ b/outputs/lib/builders.nix @@ -0,0 +1,91 @@ +{ + lib, + inputs, + self, + ... +}: let + inherit (lib) singleton recursiveUpdate mkDefault; + inherit (builtins) concatLists; + inherit (self) keys; + hm = inputs.home-manager.nixosModules.home-manager; + agenix = inputs.agenix.nixosModules.default; + nixosModules = "${self}/nixos"; + mkNixos = inputs.nixpkgs.lib.nixosSystem; + hostModules = "${self}/hosts"; + + mkBaseSystem = { + withSystem, + hostname, + system, + type, + role, + additionalModules ? [], + specialArgs ? {}, + }: + withSystem system ({ + inputs', + self', + ... + }: + mkNixos { + specialArgs = + recursiveUpdate { + inherit keys lib inputs self inputs' self'; + } + specialArgs; + modules = concatLists [ + (singleton { + networking.hostName = hostname; + nixpkgs.hostPlatform = mkDefault system; + ooknet.host = { + name = hostname; + inherit role type; + }; + }) + [(hostModules + "/${hostname}")] + additionalModules + ]; + }); + + mkWorkstation = { + withSystem, + hostname, + system, + type, + additionalModules ? [], + specialArgs ? {}, + }: + mkBaseSystem { + inherit withSystem hostname system type specialArgs; + role = "workstation"; + additionalModules = concatLists [ + [hm agenix nixosModules] + additionalModules + ]; + }; + + mkServer = { + withSystem, + hostname, + system, + type, + platform, + services, + additionalModules ? [], + specialArgs ? {}, + }: + mkBaseSystem { + inherit withSystem hostname system type specialArgs; + role = "server"; + additionalModules = concatLists [ + (singleton { + ooknet.host = { + inherit platform services; + }; + }) + additionalModules + ]; + }; +in { + inherit mkServer mkWorkstation; +} diff --git a/outputs/lib/default.nix b/outputs/lib/default.nix new file mode 100644 index 0000000..9c5c3ec --- /dev/null +++ b/outputs/lib/default.nix @@ -0,0 +1,12 @@ +{ + lib, + self, + inputs, + ... +}: let + builders = import ./builders.nix {inherit self lib inputs;}; +in { + _module.args.ooknet.lib = { + inherit builders; + }; +} diff --git a/outputs/nixos.nix b/outputs/nixos.nix index 743e273..430b679 100644 --- a/outputs/nixos.nix +++ b/outputs/nixos.nix @@ -1,55 +1,48 @@ { - inputs, self, withSystem, + ooknet, ... }: let - inherit (inputs.nixpkgs.lib) nixosSystem; - inherit (self) keys; - - hosts = "${self}/hosts"; - - hm = inputs.home-manager.nixosModules.home-manager; - nixarr = inputs.nixarr.nixosModules.default; - agenix = inputs.agenix.nixosModules.default; - - nixosModules = "${self}/nixos"; - - workstation = [ - hm - agenix - nixosModules - ]; - - specialArgs = {inherit withSystem keys inputs self;}; + inherit (ooknet.lib.builders) mkServer mkWorkstation; in { - ooksdesk = nixosSystem { - inherit specialArgs; - system = "x86_64-linux"; - modules = ["${hosts}/ooksdesk"] ++ workstation; - }; + flake.nixosConfigurations = { + ooksdesk = mkWorkstation { + inherit withSystem; + hostname = "ooksdesk"; + system = "x86_64-linux"; + type = "desktop"; + }; - ookst480s = nixosSystem { - inherit specialArgs; - system = "x86_64-linux"; - modules = ["${hosts}/ookst480s"] ++ workstation; - }; + ookst480s = mkWorkstation { + inherit withSystem; + system = "x86_64-linux"; + hostname = "ookst480s"; + type = "laptop"; + }; - ooksmedia = nixosSystem { - inherit specialArgs; - system = "x86_64-linux"; - modules = ["${hosts}/ooksmedia" nixarr] ++ workstation; - }; + ooksmedia = mkWorkstation { + inherit withSystem; + system = "x86_64-linux"; + hostname = "ooksmedia"; + type = "desktop"; + }; - ooksmicro = nixosSystem { - inherit specialArgs; - system = "x86_64-linux"; - modules = ["${hosts}/ooksmicro"] ++ workstation; - }; + ooksmicro = mkWorkstation { + inherit withSystem; + system = "x86_64-linux"; + hostname = "ooksmicro"; + }; - ooksx1 = nixosSystem { - inherit specialArgs; - system = "x86_64-linux"; - modules = ["${hosts}/ooksx1"] ++ workstation; + ooksx1 = mkWorkstation { + inherit withSystem; + system = "x86_64-linux"; + hostname = "ooksx1"; + }; + ooknode = mkServer { + inherit withSystem; + system = "x86_64-linux"; + hostname = "ooknode"; + }; }; }