-
Notifications
You must be signed in to change notification settings - Fork 107
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow for directories in module-list #224
Conversation
It might just be a translation issue, but I'm still not clear on exactly what the issue is in #221 or how this addresses it. |
Ohh so currently when you try to add a directory with a default.nix in |
Exactly, thanks for you clarifying my issue. |
Okay great. Wouldn't a more minimal fix for {
pathsToImportedAttrs = paths:
let
paths' = lib.filter
(path: lib.hasSuffix ".nix" path
# simply add another filter condition
|| lib.pathExists "${path}/default.nix")
paths;
in
genAttrs' paths' (path: {
name = lib.removeSuffix ".nix"
# Safe as long this is just used as a name
(builtins.unsafeDiscardStringContext (baseNameOf path));
value = import path;
});
} I'll take a look at |
Ohh yeah that would work well. I don't mind switching to that. |
I hear what your saying but I kinda feel the opposite. The final operation is an I reciprocate your feeling, but about |
I see what your saying. Thanks for explaining the reasoning. I'll update this PR. |
updated, but I also updated teh relevant test and thats failing. I'll debug tomorrow. |
Is this also how nixpkgs module system works? |
In what respect? |
tests/lib.nix
Outdated
./testPathsToImportedAttrs/dir | ||
./testPathsToImportedAttrs/foo.nix | ||
./testPathsToImportedAttrs/bar.nix | ||
./testPathsToImportedAttrs/t.nix | ||
./testPathsToImportedAttrs/f.nix | ||
]; | ||
|
||
expected = { | ||
dir = { a = 5; }; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm lost, this fails nix flake check
. But when I run the exact expression in nix repl
, this the output I get.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The following will fix it:
"${self}/tests/testPathsToImportedAttrs/dir"
"${self}/tests/testPathsToImportedAttrs/foo.nix"
"${self}/tests/testPathsToImportedAttrs/bar.nix"
"${self}/tests/testPathsToImportedAttrs/t.nix"
"${self}/tests/testPathsToImportedAttrs/f.nix"
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fixed, good find, I never thought that this would be necessary
For the most part yeah, you can pass files or directories. The difference here is that we want to export modules as an attribute, so we need some way to get a name from a file. Whereas nixpkgs, doesn't need to do that, since it instead lumps them all into |
6c29b48
to
836e70b
Compare
check if directory has a default.nix and use directory name as key Co-authored-by: Timothy DeHerrera <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bors r+
Build succeeded: |
fixes #221
building on #222 this PR improves the lib functions pathsToImportedAttrs and pathsIn. First to add support for directories. This does not support actually passing a file in a directory, so
./matrix/default.nix
won't work but./matrix
will - I should probably document this somewhere.Also I moved the filtering for nix files to
pathsIn
, since its only necessary for auto-import. We can assume that users would pass proper files inmodule-list.nix
.