1
1
forked from extern/flakelight

Allow packages values to depend on system

This commit is contained in:
Archit Gupta 2024-06-29 16:37:49 -07:00
parent cc0bcddf07
commit 32bf894a50
2 changed files with 30 additions and 15 deletions

View File

@ -6,9 +6,9 @@
let
inherit (builtins) hasAttr parseDrvName tryEval;
inherit (lib) findFirst functionArgs mapAttrs' mapAttrs mkIf mkMerge mkOption
nameValuePair optionalAttrs;
nameValuePair optionalAttrs optionals;
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:
let
@ -27,6 +27,8 @@ let
final.callPackage pkg' overrides;
genPkgs = final: prev: pkgs:
mapAttrs (name: genPkg final prev name) pkgs;
getPkgDefs = pkgs: config.packages (moduleArgs // { inherit (pkgs) system; });
in
{
options = {
@ -36,8 +38,8 @@ in
};
packages = mkOption {
type = optCallWith moduleArgs (lazyAttrsOf packageDef);
default = { };
type = nullable (optFunctionTo (lazyAttrsOf packageDef));
default = null;
};
pname = mkOption {
@ -57,9 +59,10 @@ in
packages.default = config.package;
})
(mkIf (config.packages != { }) {
(mkIf (config.packages != null) {
packageOverlay = final: prev:
let
pkgDefs = getPkgDefs prev;
getName = pkg: pkg.pname or (parseDrvName pkg.name).name;
mockPkgs = import ../misc/nameMockedPkgs.nix prev;
@ -68,20 +71,19 @@ in
"please set the `pname` flakelight option to the intended name."))
[
(assert config.pname != null; config.pname)
(getName (mockPkgs.callPackage config.packages.default { }))
(getName (mockPkgs.callPackage pkgDefs.default { }))
(getName (import inputs.nixpkgs {
inherit (prev.stdenv.hostPlatform) system;
inherit (config.nixpkgs) config;
overlays = config.withOverlays ++
[ (final: prev: genPkgs final prev config.packages) ];
[ (final: prev: genPkgs final prev pkgDefs) ];
}).default)
];
in
(optionalAttrs (config.packages ? default) rec {
default = genPkg final prev defaultPkgName
config.packages.default;
(optionalAttrs (pkgDefs ? default) rec {
default = genPkg final prev defaultPkgName pkgDefs.default;
${defaultPkgName} = default;
}) // genPkgs final prev (removeAttrs config.packages [ "default" ]);
}) // genPkgs final prev (removeAttrs pkgDefs [ "default" ]);
overlay = final: prev: removeAttrs
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
@ -89,16 +91,15 @@ in
outputs = rec {
packages = genSystems (pkgs:
mapAttrs (k: _: pkgs.${k}) config.packages);
mapAttrs (k: _: pkgs.${k}) (getPkgDefs pkgs));
checks = mapAttrs
(_: mapAttrs' (n: nameValuePair ("packages-" + n)))
packages;
};
})
(mkIf (config.packages ? default) {
devShell.inputsFrom = pkgs: [ pkgs.default ];
devShell.inputsFrom = pkgs:
optionals ((getPkgDefs pkgs) ? default) [ pkgs.default ];
})
];
}

View File

@ -287,6 +287,20 @@ in
})
(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
(flakelight ./empty {
inputs = { inherit nixpkgs; };