From 2eb6f832620999e6465099112a23be51ac27d184 Mon Sep 17 00:00:00 2001 From: David Arnold Date: Mon, 14 Jun 2021 20:40:27 -0500 Subject: [PATCH] fix: maybImport to also classic imports that peak for defualt.nix such as `import ./pkgs`, actually loading `./pkgs/default.nix` --- flake.lock | 6 +++--- flake.nix | 6 ++++-- src/importers.nix | 10 +--------- src/mkFlake/default.nix | 5 +---- src/mkFlake/evalArgs.nix | 20 +++++++++++--------- src/pkgs-lib/shell/default.nix | 2 +- 6 files changed, 21 insertions(+), 28 deletions(-) diff --git a/flake.lock b/flake.lock index 1971f93..8149728 100644 --- a/flake.lock +++ b/flake.lock @@ -184,11 +184,11 @@ "flake-utils": "flake-utils" }, "locked": { - "lastModified": 1623691375, - "narHash": "sha256-y5XQGJpLFfBTFj+vu5ZQgeeyAI6Wjbr/6pe3SzITvG0=", + "lastModified": 1623776596, + "narHash": "sha256-+5+fx76ucxUffw3AtzG56U/xTFk65RV+qIsBzBHjXzg=", "owner": "gytis-ivaskevicius", "repo": "flake-utils-plus", - "rev": "38f0103feadf93f949ca72579607a37601e34178", + "rev": "e9cfad74a79430bfdd391a6073cc581c1b1504c8", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index d8af551..e8c0b5d 100644 --- a/flake.nix +++ b/flake.nix @@ -41,7 +41,6 @@ importers = import ./src/importers.nix { lib = combinedLib; - inherit devshell; }; generators = import ./src/generators.nix { @@ -51,7 +50,10 @@ mkFlake = { __functor = import ./src/mkFlake { lib = combinedLib; }; - evalArgs = import ./src/mkFlake/evalArgs.nix { lib = combinedLib; }; + evalArgs = import ./src/mkFlake/evalArgs.nix { + lib = combinedLib; + inherit devshell; + }; }; pkgs-lib = import ./src/pkgs-lib { diff --git a/src/importers.nix b/src/importers.nix index 843ac6a..28d5298 100644 --- a/src/importers.nix +++ b/src/importers.nix @@ -1,4 +1,4 @@ -{ lib, devshell }: +{ lib }: let flattenTree = /** @@ -189,13 +189,5 @@ in (flattenTree (rakeLeaves dir)); }; - maybeImportDevshellModule = item: - let isPath = builtins.isPath item || builtins.isString item; in - if isPath && lib.hasSuffix ".toml" item then - devshell.lib.importTOML item - else if isPath && lib.hasSuffix ".nix" then - import item - else item; - } diff --git a/src/mkFlake/default.nix b/src/mkFlake/default.nix index 56cbd91..d814069 100644 --- a/src/mkFlake/default.nix +++ b/src/mkFlake/default.nix @@ -81,10 +81,7 @@ lib.systemFlake (lib.mergeAny homeModules = lib.exporters.modulesFromList cfg.home.modules; - devshellModules = lib.exporters.modulesFromList { - paths = cfg.devshell.modules; - _import = lib.maybeImportDevshellModule; - }; + devshellModules = lib.exporters.modulesFromList cfg.devshell.modules; overlays = lib.exporters.internalOverlays { # since we can't detect overlays owned by self diff --git a/src/mkFlake/evalArgs.nix b/src/mkFlake/evalArgs.nix index 2856019..1a90d9d 100644 --- a/src/mkFlake/evalArgs.nix +++ b/src/mkFlake/evalArgs.nix @@ -1,4 +1,4 @@ -{ lib }: +{ lib, devshell }: { args }: let @@ -7,9 +7,16 @@ let cfg = config; inherit (args) self; + + maybeImportDevshellModule = path: + if lib.hasSuffix ".toml" path then + devshell.lib.importTOML path + else import path; + + maybeImport = obj: - if (builtins.isPath obj || builtins.isString obj) && lib.hasSuffix ".nix" obj then - import obj + if (builtins.isPath obj || builtins.isString obj) then + maybeImportDevshellModule obj else obj; @@ -20,11 +27,6 @@ let description = "valid module"; }); - # to export modules we need paths to get the name - exportModuleType = with types; - (addCheck path (x: moduleType.check (maybeImport x))) // { - description = "path to a module"; - }; overlayType = pathTo (types.anything // { check = builtins.isFunction; description = "valid Nixpkgs overlay"; @@ -128,7 +130,7 @@ let exportModulesModule = name: { options = { modules = mkOption { - type = with types; pathTo (coercedListOf exportModuleType); + type = with types; pathTo (coercedListOf moduleType); default = [ ]; description = '' modules to include in all hosts and export to ${name}Modules output diff --git a/src/pkgs-lib/shell/default.nix b/src/pkgs-lib/shell/default.nix index b790918..100f05b 100644 --- a/src/pkgs-lib/shell/default.nix +++ b/src/pkgs-lib/shell/default.nix @@ -29,7 +29,7 @@ let configuration = { imports = [ (pkgs'.devshell.importTOML ./devshell.toml) ] - ++ (map lib.maybeImportDevshellModule extraModules); + ++ extraModules; packages = with installPkgs; [ nixos-install