From 01d4eb2c850b84fcac6b87cd74065729448c5d8d Mon Sep 17 00:00:00 2001 From: Pacman99 Date: Sat, 20 Mar 2021 09:39:19 -0700 Subject: [PATCH] Move all flake creation logic to lib as mkDevos and use evalDevosArgs --- flake.nix | 69 ++++--------------------------------------- lib/default.nix | 1 + lib/devos/default.nix | 2 ++ lib/devos/mkDevos.nix | 64 +++++++++++++++++++++++++++++++++++++++ 4 files changed, 73 insertions(+), 63 deletions(-) create mode 100644 lib/devos/mkDevos.nix diff --git a/flake.nix b/flake.nix index 082f501ad..940f455bc 100644 --- a/flake.nix +++ b/flake.nix @@ -28,68 +28,11 @@ pkgs.inputs.nixpkgs.follows = "nixos"; }; - outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: - let - inherit (self) lib; - inherit (lib) os; - - extern = import ./extern { inherit inputs; }; - - multiPkgs = os.mkPkgs; - - outputs = { - nixosConfigurations = - import ./hosts (nixos.lib.recursiveUpdate inputs { - inherit multiPkgs extern; - defaultSystem = "x86_64-linux"; - lib = nixos.lib.extend (final: prev: { - dev = self.lib; - }); - }); - - homeConfigurations = os.mkHomeConfigurations; - - nixosModules = - let moduleList = import ./modules/module-list.nix; - in lib.pathsToImportedAttrs moduleList; - - homeModules = - let moduleList = import ./users/modules/module-list.nix; - in lib.pathsToImportedAttrs moduleList; - - overlay = import ./pkgs; - overlays = lib.pathsToImportedAttrs (lib.pathsIn ./overlays); - - lib = import ./lib { inherit nixos self inputs; }; - - templates.flk.path = ./.; - templates.flk.description = "flk template"; - defaultTemplate = self.templates.flk; - - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + outputs = inputs@{ deploy, nixos, nur, self, utils, ... }: + let + lib = import ./lib { inherit self nixos inputs; }; + in + lib.mkDevos { + inherit self; }; - - systemOutputs = utils.lib.eachDefaultSystem (system: - let pkgs = multiPkgs.${system}; in - { - checks = - let - tests = nixos.lib.optionalAttrs (system == "x86_64-linux") - (import ./tests { inherit self pkgs; }); - deployHosts = nixos.lib.filterAttrs - (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes; - deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; - in - nixos.lib.recursiveUpdate tests deployChecks; - - packages = utils.lib.flattenTreeSystem system - (os.mkPackages { inherit pkgs; }); - - devShell = import ./shell { - inherit self system; - }; - } - ); - in - nixos.lib.recursiveUpdate outputs systemOutputs; } diff --git a/lib/default.nix b/lib/default.nix index 7fceb3ce0..e3fe1c053 100644 --- a/lib/default.nix +++ b/lib/default.nix @@ -17,6 +17,7 @@ lib.makeExtensible (final: lists = callLibs ./lists.nix; strings = callLibs ./strings.nix; + inherit (os) mkDevos; inherit (attrs) mapFilterAttrs genAttrs' pathsToImportedAttrs concatAttrs; inherit (lists) pathsIn; inherit (strings) rgxToString; diff --git a/lib/devos/default.nix b/lib/devos/default.nix index 5a176fed9..c2ee48f63 100644 --- a/lib/devos/default.nix +++ b/lib/devos/default.nix @@ -14,6 +14,8 @@ evalDevosArgs = dev.callLibs ./evalDevosArgs.nix; + mkDevos = dev.callLibs ./mkDevos.nix; + mkNodes = dev.callLibs ./mkNodes.nix; mkHosts = dev.callLibs ./mkHosts.nix; diff --git a/lib/devos/mkDevos.nix b/lib/devos/mkDevos.nix new file mode 100644 index 000000000..308cda183 --- /dev/null +++ b/lib/devos/mkDevos.nix @@ -0,0 +1,64 @@ +{ self, nixos, inputs, ... }: +let + devos = self; +in + +{ ... } @ args: +let + inherit (self) lib; + inherit (lib) os; + + inherit (inputs) utils deploy; + + cfg = os.evalDevosArgs { inherit args; }; + + multiPkgs = os.mkPkgs { inherit (cfg) extern overrides; }; + + outputs = { + nixosConfigurations = os.mkHosts { + inherit multiPkgs; + inherit (cfg) extern suites overrides; + dir = cfg.hosts; + }; + + homeConfigurations = os.mkHomeConfigurations; + + nixosModules = cfg.modules; + + homeModules = cfg.userModules; + + overlay = cfg.packages; + inherit (cfg) overlays; + + lib = import "${devos}/lib" { inherit self nixos inputs; }; + + templates.flk.path = builtins.toPath self; + templates.flk.description = "flk template"; + defaultTemplate = self.templates.flk; + + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + }; + + systemOutputs = utils.lib.eachDefaultSystem (system: + let pkgs = multiPkgs.${system}; in + { + checks = + let + tests = nixos.lib.optionalAttrs (system == "x86_64-linux") + (import "${devos}/tests" { inherit self pkgs; }); + deployHosts = nixos.lib.filterAttrs + (n: _: self.nixosConfigurations.${n}.config.nixpkgs.system == system) self.deploy.nodes; + deployChecks = deploy.lib.${system}.deployChecks { nodes = deployHosts; }; + in + nixos.lib.recursiveUpdate tests deployChecks; + + packages = utils.lib.flattenTreeSystem system + (os.mkPackages { inherit pkgs; }); + + devShell = import "${devos}/shell" { + inherit self pkgs system; + }; + }); +in + nixos.lib.recursiveUpdate outputs systemOutputs +