forked from extern/flakelight
Allow packages values to depend on system
This commit is contained in:
parent
cc0bcddf07
commit
32bf894a50
@ -6,9 +6,9 @@
|
|||||||
let
|
let
|
||||||
inherit (builtins) hasAttr parseDrvName tryEval;
|
inherit (builtins) hasAttr parseDrvName tryEval;
|
||||||
inherit (lib) findFirst functionArgs mapAttrs' mapAttrs mkIf mkMerge mkOption
|
inherit (lib) findFirst functionArgs mapAttrs' mapAttrs mkIf mkMerge mkOption
|
||||||
nameValuePair optionalAttrs;
|
nameValuePair optionalAttrs optionals;
|
||||||
inherit (lib.types) lazyAttrsOf str uniq;
|
inherit (lib.types) lazyAttrsOf str uniq;
|
||||||
inherit (flakelight.types) nullable optCallWith overlay packageDef;
|
inherit (flakelight.types) nullable optFunctionTo overlay packageDef;
|
||||||
|
|
||||||
genPkg = final: prev: name: pkg:
|
genPkg = final: prev: name: pkg:
|
||||||
let
|
let
|
||||||
@ -27,6 +27,8 @@ let
|
|||||||
final.callPackage pkg' overrides;
|
final.callPackage pkg' overrides;
|
||||||
genPkgs = final: prev: pkgs:
|
genPkgs = final: prev: pkgs:
|
||||||
mapAttrs (name: genPkg final prev name) pkgs;
|
mapAttrs (name: genPkg final prev name) pkgs;
|
||||||
|
|
||||||
|
getPkgDefs = pkgs: config.packages (moduleArgs // { inherit (pkgs) system; });
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@ -36,8 +38,8 @@ in
|
|||||||
};
|
};
|
||||||
|
|
||||||
packages = mkOption {
|
packages = mkOption {
|
||||||
type = optCallWith moduleArgs (lazyAttrsOf packageDef);
|
type = nullable (optFunctionTo (lazyAttrsOf packageDef));
|
||||||
default = { };
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
pname = mkOption {
|
pname = mkOption {
|
||||||
@ -57,9 +59,10 @@ in
|
|||||||
packages.default = config.package;
|
packages.default = config.package;
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (config.packages != { }) {
|
(mkIf (config.packages != null) {
|
||||||
packageOverlay = final: prev:
|
packageOverlay = final: prev:
|
||||||
let
|
let
|
||||||
|
pkgDefs = getPkgDefs prev;
|
||||||
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
|
||||||
mockPkgs = import ../misc/nameMockedPkgs.nix prev;
|
mockPkgs = import ../misc/nameMockedPkgs.nix prev;
|
||||||
|
|
||||||
@ -68,20 +71,19 @@ in
|
|||||||
"please set the `pname` flakelight option to the intended name."))
|
"please set the `pname` flakelight option to the intended name."))
|
||||||
[
|
[
|
||||||
(assert config.pname != null; config.pname)
|
(assert config.pname != null; config.pname)
|
||||||
(getName (mockPkgs.callPackage config.packages.default { }))
|
(getName (mockPkgs.callPackage pkgDefs.default { }))
|
||||||
(getName (import inputs.nixpkgs {
|
(getName (import inputs.nixpkgs {
|
||||||
inherit (prev.stdenv.hostPlatform) system;
|
inherit (prev.stdenv.hostPlatform) system;
|
||||||
inherit (config.nixpkgs) config;
|
inherit (config.nixpkgs) config;
|
||||||
overlays = config.withOverlays ++
|
overlays = config.withOverlays ++
|
||||||
[ (final: prev: genPkgs final prev config.packages) ];
|
[ (final: prev: genPkgs final prev pkgDefs) ];
|
||||||
}).default)
|
}).default)
|
||||||
];
|
];
|
||||||
in
|
in
|
||||||
(optionalAttrs (config.packages ? default) rec {
|
(optionalAttrs (pkgDefs ? default) rec {
|
||||||
default = genPkg final prev defaultPkgName
|
default = genPkg final prev defaultPkgName pkgDefs.default;
|
||||||
config.packages.default;
|
|
||||||
${defaultPkgName} = default;
|
${defaultPkgName} = default;
|
||||||
}) // genPkgs final prev (removeAttrs config.packages [ "default" ]);
|
}) // genPkgs final prev (removeAttrs pkgDefs [ "default" ]);
|
||||||
|
|
||||||
overlay = final: prev: removeAttrs
|
overlay = final: prev: removeAttrs
|
||||||
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
|
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
|
||||||
@ -89,16 +91,15 @@ in
|
|||||||
|
|
||||||
outputs = rec {
|
outputs = rec {
|
||||||
packages = genSystems (pkgs:
|
packages = genSystems (pkgs:
|
||||||
mapAttrs (k: _: pkgs.${k}) config.packages);
|
mapAttrs (k: _: pkgs.${k}) (getPkgDefs pkgs));
|
||||||
|
|
||||||
checks = mapAttrs
|
checks = mapAttrs
|
||||||
(_: mapAttrs' (n: nameValuePair ("packages-" + n)))
|
(_: mapAttrs' (n: nameValuePair ("packages-" + n)))
|
||||||
packages;
|
packages;
|
||||||
};
|
};
|
||||||
})
|
|
||||||
|
|
||||||
(mkIf (config.packages ? default) {
|
devShell.inputsFrom = pkgs:
|
||||||
devShell.inputsFrom = pkgs: [ pkgs.default ];
|
optionals ((getPkgDefs pkgs) ? default) [ pkgs.default ];
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -287,6 +287,20 @@ in
|
|||||||
})
|
})
|
||||||
(f: (import f.packages.x86_64-linux.pkg2));
|
(f: (import f.packages.x86_64-linux.pkg2));
|
||||||
|
|
||||||
|
packages-fn-has-system = test
|
||||||
|
(flakelight ./empty {
|
||||||
|
packages = { system, ... }: (if system == "x86_64-linux" then {
|
||||||
|
default = { stdenv }:
|
||||||
|
stdenv.mkDerivation {
|
||||||
|
name = "pkg1";
|
||||||
|
src = ./empty;
|
||||||
|
installPhase = "echo true > $out";
|
||||||
|
};
|
||||||
|
} else { });
|
||||||
|
})
|
||||||
|
(f: (import f.packages.x86_64-linux.default)
|
||||||
|
&& !(f.packages.aarch64-linux ? default));
|
||||||
|
|
||||||
legacyPackages-set-pkgs = test
|
legacyPackages-set-pkgs = test
|
||||||
(flakelight ./empty {
|
(flakelight ./empty {
|
||||||
inputs = { inherit nixpkgs; };
|
inputs = { inherit nixpkgs; };
|
||||||
|
Loading…
Reference in New Issue
Block a user