Skip to content

Instantly share code, notes, and snippets.

@webflo-dev
Forked from yunfachi/default.nix
Created November 22, 2024 13:27
Show Gist options
  • Save webflo-dev/f745ef763cba2128e4b054ebc65d0323 to your computer and use it in GitHub Desktop.
Save webflo-dev/f745ef763cba2128e4b054ebc65d0323 to your computer and use it in GitHub Desktop.
Nix / NixOS : Import all files from current directory
{...}: {
# imports by full path without copying to /nix/store
imports = builtins.map (n: toString ./. + "/${n}") (builtins.attrNames (builtins.removeAttrs (builtins.readDir ./.) [(builtins.unsafeGetAttrPos "_" {_ = null;}).file]));
# copies all files from the current directory to /nix/store and imports from /nix/store
# imports = builtins.map (n: "${./.}/${n}") (builtins.attrNames (builtins.removeAttrs (builtins.readDir ./.) [(builtins.unsafeGetAttrPos "_" {_ = null;}).file]));
}
@webflo-dev
Copy link
Author

a more advanced implementation of this thing
https://github.com/yunfachi/nixpkgs-yunfachi/blob/master/lib/umport.nix

{umport, ...}: {
  imports = umport {path = ./.;};
}
{umport, ...}: {
  imports = umport {
    path = ./.; # a required parameter that must be specified in the current file
    include = [../../bar.nix]; # default []
    exclude = [./foo.nix]; # defaults to [], but always excludes the current file
    copyToStore = true; # default false
  };

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment