-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathdefault.nix
45 lines (42 loc) · 1.27 KB
/
default.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
let
yamlModule = { yj, runCommand, file }:
let
json = runCommand "file.json" { } ''
${yj}/bin/yj < ${file} > $out
'';
in {
# set location for errors
_file = file;
cog = builtins.fromJSON (builtins.readFile json);
};
inherit (builtins) pathExists;
# take a cog location, return a dream2nix module that imports it
packageModule = package:
({ lib, packageSets, ... }: {
imports = [
(if pathExists (package + "/default.nix") then package else { })
(if pathExists (package + "/cog.yaml") then
yamlModule {
file = (package + "/cog.yaml");
inherit (packageSets.nixpkgs) runCommand yj;
}
else
{ })
];
assertions = [{
assertion = pathExists (package + "/default.nix")
|| pathExists (package + "/cog.yaml");
message =
"Path name ${package} should contain 'default.nix' or 'cog.yaml'";
}];
_module.args.pkgs = packageSets.nixpkgs;
paths.package = package;
name = lib.mkDefault (baseNameOf package);
});
in { pkgs, dream2nix }:
args: package:
dream2nix.lib.evalModules {
packageSets.nixpkgs = pkgs;
modules =
[ ./modules/cog ./modules/weights args (packageModule package) ];
}