mirror of
https://github.com/nix-community/dream2nix.git
synced 2024-12-23 14:31:55 +03:00
feat(lib): add helper lib.importPackages
This makes the repo initialization simpler (see examples)
This commit is contained in:
parent
79fc0de519
commit
556f2e7114
@ -13,18 +13,14 @@
|
||||
...
|
||||
}: let
|
||||
system = "x86_64-linux";
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
lib = nixpkgs.lib;
|
||||
packageModuleNames = builtins.attrNames (builtins.readDir ./packages);
|
||||
in {
|
||||
# all packages defined inside ./packages/
|
||||
packages.${system} =
|
||||
lib.genAttrs packageModuleNames
|
||||
(moduleName:
|
||||
dream2nix.lib.evalModules {
|
||||
modules = ["${./packages}/${moduleName}" ./settings.nix];
|
||||
packageSets.nixpkgs = pkgs;
|
||||
specialArgs.self = self;
|
||||
});
|
||||
packages.${system} = dream2nix.lib.importPackages {
|
||||
projectRoot = ./.;
|
||||
# can be changed to ".git" or "flake.nix" to get rid of .project-root
|
||||
projectRootFile = ".project-root";
|
||||
packagesDir = "/packages";
|
||||
packageSets.nixpkgs = nixpkgs.legacyPackages.${system};
|
||||
};
|
||||
};
|
||||
}
|
||||
|
@ -7,17 +7,14 @@
|
||||
}: let
|
||||
dream2nix = import dream2nixSource;
|
||||
nixpkgs = import dream2nix.inputs.nixpkgs {};
|
||||
lib = nixpkgs.lib;
|
||||
|
||||
packageModuleNames = builtins.attrNames (builtins.readDir ./packages);
|
||||
|
||||
packages =
|
||||
lib.genAttrs packageModuleNames
|
||||
(moduleName:
|
||||
dream2nix.lib.evalModules {
|
||||
modules = ["${./packages}/${moduleName}" ./settings.nix];
|
||||
packageSets.nixpkgs = nixpkgs;
|
||||
});
|
||||
# all packages defined inside ./packages/
|
||||
packages = dream2nix.lib.importPackages {
|
||||
projectRoot = ./.;
|
||||
# can be changed to ".git" to get rid of .project-root
|
||||
projectRootFile = ".project-root";
|
||||
packagesDir = "/packages";
|
||||
packageSets.nixpkgs = nixpkgs;
|
||||
};
|
||||
in
|
||||
# all packages defined inside ./packages/
|
||||
packages
|
||||
|
@ -7,16 +7,49 @@
|
||||
flake.options.lib = lib.mkOption {
|
||||
type = lib.types.lazyAttrsOf lib.types.raw;
|
||||
};
|
||||
flake.config.lib.importPackages = args @ {
|
||||
projectRoot,
|
||||
projectRootFile,
|
||||
packagesDir,
|
||||
...
|
||||
}: let
|
||||
packagesDirPath =
|
||||
if ! builtins.isString packagesDir
|
||||
then throw "packagesDir must be a string"
|
||||
else projectRoot + "/${packagesDir}";
|
||||
forwardedArgs = builtins.removeAttrs args [
|
||||
"projectRoot"
|
||||
"projectRootFile"
|
||||
"packagesDir"
|
||||
];
|
||||
in
|
||||
lib.mapAttrs
|
||||
(
|
||||
module: type:
|
||||
self.lib.evalModules (forwardedArgs
|
||||
// {
|
||||
modules = [
|
||||
(packagesDirPath + "/${module}")
|
||||
{
|
||||
paths.projectRoot = projectRoot;
|
||||
paths.projectRootFile = projectRootFile;
|
||||
paths.package = "/${packagesDir}/${module}";
|
||||
}
|
||||
];
|
||||
})
|
||||
)
|
||||
(builtins.readDir packagesDirPath);
|
||||
|
||||
flake.config.lib.evalModules = args @ {
|
||||
packageSets,
|
||||
modules,
|
||||
# If set, returns the result coming form nixpgs.lib.evalModules as is,
|
||||
# If set, returns the result coming form nixpkgs.lib.evalModules as is,
|
||||
# otherwise it returns the derivation only (.config.public).
|
||||
raw ? false,
|
||||
specialArgs ? {},
|
||||
...
|
||||
}: let
|
||||
forawardedArgs = builtins.removeAttrs args [
|
||||
forwardedArgs = builtins.removeAttrs args [
|
||||
"packageSets"
|
||||
"raw"
|
||||
];
|
||||
@ -24,7 +57,7 @@
|
||||
evaluated =
|
||||
lib.evalModules
|
||||
(
|
||||
forawardedArgs
|
||||
forwardedArgs
|
||||
// {
|
||||
modules =
|
||||
args.modules
|
||||
|
Loading…
Reference in New Issue
Block a user