diff --git a/lib/flake.nix b/lib/flake.nix index 9025477a..17e069c2 100644 --- a/lib/flake.nix +++ b/lib/flake.nix @@ -35,7 +35,6 @@ inherit deploy; }; evalArgs = import ./mkFlake/evalArgs.nix { lib = nixpkgs.lib // self; }; - evalOldArgs = import ./mkFlake/evalOldArgs.nix { lib = nixpkgs.lib // self; }; }; pkgs-lib = import ./pkgs-lib { @@ -83,7 +82,7 @@ mkFlakeDoc = pkgs.writeText "mkFlakeOptions.md" ( pkgs.nixosOptionsDoc { - inherit (lib.mkFlake.evalArgs { nixos = "nixos"; args = { }; }) options; + inherit (lib.mkFlake.evalArgs { args = { }; }) options; } ).optionsMDDoc; }; diff --git a/lib/mkFlake/default.nix b/lib/mkFlake/default.nix index d086283a..3d285c73 100644 --- a/lib/mkFlake/default.nix +++ b/lib/mkFlake/default.nix @@ -1,64 +1,85 @@ { lib, deploy }: let inherit (lib) os; + inherit (builtins) mapAttrs attrNames attrValues head isFunction; in -_: { self, inputs, nixos, ... } @ args: +_: { self, inputs, ... } @ args: let - cfg = ( - lib.mkFlake.evalOldArgs - { inherit self inputs args; } - ).config; - - multiPkgs = os.mkPkgs - { - inherit self inputs nixos; - inherit (cfg) extern overrides; - }; - - outputs = { - nixosConfigurations = os.mkHosts - { - inherit self inputs nixos multiPkgs; - inherit (cfg) extern suites overrides; - dir = cfg.hosts; - }; - - homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; - - nixosModules = cfg.modules; - - homeModules = cfg.userModules; - - overlay = cfg.packages; - inherit (cfg) overlays; - - deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + config = lib.mkFlake.evalArgs { + args = lib.mkMerge [ args { _module.check = false; } ]; }; - systemOutputs = lib.eachDefaultSystem (system: - let - pkgs = multiPkgs.${system}; - pkgs-lib = lib.pkgs-lib.${system}; - # all packages that are defined in ./pkgs - legacyPackages = os.mkPackages { - inherit pkgs; - inherit (self) overlay overlays; - }; - in - { - checks = pkgs-lib.tests.mkChecks { + cfg = config.config; + + otherArguments = removeAttrs args (attrNames config.options); + + defaultModules = with lib.modules; [ + (hmDefaults { + inherit (cfg.home) suites; + modules = cfg.home.modules ++ cfg.home.externalModules; + }) + (globalDefaults { + inherit self inputs; + }) + ]; + + getDefaultChannel = channels: channels.${cfg.nixos.hostDefaults.channelName}; +in +lib.systemFlake (lib.recursiveUpdate + otherArguments + { + inherit self inputs; + inherit (cfg) channelsConfig supportedSystems; + + mkFlakeConfig = config; + + channels = mapAttrs + (name: channel: + channel // { + # pass channels if "overlay" has three arguments + overlaysBuilder = channels: lib.unifyOverlays channels channel.overlays; + } + ) cfg.channels; + + # the host arguments cannot exist for fup hostDefaults to work + # so evalArgs sets them to null by default and the null args are filtered out here + hosts = mapAttrs (_: host: lib.filterAttrs (_: arg: arg != null) host) cfg.nixos.hosts; + + hostDefaults = { + specialArgs.suites = cfg.nixos.suites; + modules = cfg.nixos.hostDefaults.modules + ++ cfg.nixos.hostDefaults.externalModules + ++ defaultModules; + builder = os.devosSystem { inherit self inputs; }; + inherit (cfg.nixos.hostDefaults) + channelName + system; + }; + + nixosModules = lib.exporter.modulesFromList cfg.nixos.hostDefaults.modules; + + homeModules = lib.exporter.modulesFromList cfg.home.modules; + homeConfigurations = os.mkHomeConfigurations self.nixosConfigurations; + + deploy.nodes = os.mkNodes deploy self.nixosConfigurations; + + overlays = lib.exporter.overlaysFromChannelsExporter { inherit (self) pkgs inputs; }; + + packagesBuilder = lib.builder.packagesFromOverlaysBuilderConstructor self.overlays; + + checksBuilder = channels: + lib.pkgs-lib.tests.mkChecks { + pkgs = getDefaultChannel channels; inherit (self.deploy) nodes; hosts = self.nixosConfigurations; homes = self.homeConfigurations; }; - inherit legacyPackages; - packages = lib.filterPackages system legacyPackages; - - devShell = pkgs-lib.shell; - }); -in -outputs // systemOutputs - + devShellBuilder = channels: + lib.pkgs-lib.shell { + pkgs = getDefaultChannel channels; + }; + } +) diff --git a/lib/mkFlake/evalOldArgs.nix b/lib/mkFlake/evalOldArgs.nix deleted file mode 100644 index c319d43a..00000000 --- a/lib/mkFlake/evalOldArgs.nix +++ /dev/null @@ -1,162 +0,0 @@ -{ lib }: - -{ self, inputs, args }: -let - argOpts = with lib; { config, options, ... }: - let - inherit (lib) os; - - inherit (config) self; - - inputAttrs = with types; functionTo attrs; - moduleType = with types; anything // { - inherit (submodule { }) check; - description = "valid module"; - }; - in - { - options = with types; { - self = mkOption { - type = addCheck attrs lib.isStorePath; - description = "The flake to create the devos outputs for"; - }; - nixos = mkOption { - type = addCheck attrs lib.isStorePath; - description = "The default nixpkgs channel of the devos"; - }; - inputs = mkOption { - type = addCheck attrs lib.isStorePath; - description = "All inptus of the devos"; - }; - hosts = mkOption { - type = path; - default = "${self}/hosts"; - defaultText = "\${self}/hosts"; - apply = toString; - description = '' - Path to directory containing host configurations that will be exported - to the 'nixosConfigurations' output. - ''; - }; - packages = mkOption { - # functionTo changes arg names which breaks flake check - type = types.anything // { - check = builtins.isFunction; - description = "Nixpkgs overlay"; - }; - default = (final: prev: { }); - defaultText = "(final: prev: {})"; - description = '' - Overlay for custom packages that will be included in treewide 'pkgs'. - This should follow the standard nixpkgs overlay format - two argument function - that returns an attrset. - These packages will be exported to the 'packages' and 'legacyPackages' outputs. - ''; - }; - modules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in confgurations and export in 'nixosModules' output - ''; - }; - userModules = mkOption { - type = listOf moduleType; - default = [ ]; - apply = lib.pathsToImportedAttrs; - description = '' - list of modules to include in home-manager configurations and export in - 'homeModules' output - ''; - }; - profiles = mkOption { - type = path; - default = "${self}/profiles"; - defaultText = "\${self}/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to profiles folder that can be collected into suites"; - }; - userProfiles = mkOption { - type = path; - default = "${self}/users/profiles"; - defaultText = "\${self}/users/profiles"; - apply = x: os.mkProfileAttrs (toString x); - description = "path to user profiles folder that can be collected into userSuites"; - }; - suites = - let - defaults = { user = { }; system = { }; }; - in - mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = "{ user = {}; system = {}; }"; - apply = suites: defaults // os.mkSuites { - inherit suites; - inherit (config) profiles users userProfiles; - }; - description = '' - Function with inputs 'users' and 'profiles' that returns attribute set - with user and system suites. The former for Home Manager and the latter - for nixos configurations. - These can be accessed through the 'suites' specialArg in each config system. - ''; - }; - users = mkOption { - type = path; - default = "${self}/users"; - defaultText = "\${self}/users"; - apply = x: os.mkProfileAttrs (toString x); - description = '' - path to folder containing profiles that define system users - ''; - }; - extern = - let - defaults = { - modules = [ ]; - overlays = [ ]; - specialArgs = { }; - userModules = [ ]; - userSpecialArgs = { }; - }; - in - mkOption { - type = inputAttrs; - default = { ... }: defaults; - defaultText = '' - { modules = []; overlays = []; specialArgs = []; userModules = []; userSpecialArgs = []; } - ''; - # So unneeded extern attributes can safely be deleted - apply = x: defaults // (x { inputs = inputs // self.inputs; }); - description = '' - Function with argument 'inputs' that contains all devos and ''${self}'s inputs. - The function should return an attribute set with modules, overlays, and - specialArgs to be included across nixos and home manager configurations. - Only attributes that are used should be returned. - ''; - }; - overlays = mkOption { - type = path; - default = "${self}/overlays"; - defaultText = "\${self}/overlays"; - apply = x: lib.pathsToImportedAttrs (lib.pathsIn (toString x)); - description = '' - path to folder containing overlays which will be applied to pkgs and exported in - the 'overlays' output - ''; - }; - overrides = mkOption rec { - type = attrs; - default = { modules = [ ]; disabledModules = [ ]; packages = _: _: _: { }; }; - defaultText = "{ modules = []; disabledModules = []; packages = {}; }"; - apply = x: default // x; - description = "attrset of packages and modules that will be pulled from nixpkgs master"; - }; - }; - }; -in -lib.evalModules { - modules = [ argOpts args ]; -}