mirror of
https://github.com/nix-community/flakelight.git
synced 2025-02-17 18:00:52 +01:00
Improve performance of per-system attributes
Using `perSystem` to implement per-system attributes ties all the per-system attributes together; all the `perSystem` functions must run to determine output attrs. By generating them separately, the generation can be done lazily.
This commit is contained in:
parent
bcaa85757e
commit
82f9fe67c3
@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, lib, flakelight, ... }:
|
{ config, lib, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) isFunction mapAttrs mkIf mkMerge mkOption;
|
inherit (lib) isFunction mapAttrs mkIf mkMerge mkOption;
|
||||||
inherit (lib.types) lazyAttrsOf nullOr raw;
|
inherit (lib.types) lazyAttrsOf nullOr raw;
|
||||||
@ -35,9 +35,8 @@ in
|
|||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (config.apps != null) {
|
(mkIf (config.apps != null) {
|
||||||
perSystem = pkgs: {
|
outputs.apps = genSystems (pkgs:
|
||||||
apps = mapAttrs (_: mkApp pkgs) (config.apps pkgs);
|
mapAttrs (_: mkApp pkgs) (config.apps pkgs));
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, lib, flakelight, ... }:
|
{ config, lib, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) isFunction mapAttrs mkMerge mkOption mkIf;
|
inherit (lib) isFunction mapAttrs mkMerge mkOption mkIf;
|
||||||
inherit (lib.types) lazyAttrsOf nullOr;
|
inherit (lib.types) lazyAttrsOf nullOr;
|
||||||
@ -30,9 +30,8 @@ in
|
|||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (config.bundlers != null) {
|
(mkIf (config.bundlers != null) {
|
||||||
perSystem = pkgs: {
|
outputs.bundlers = genSystems (pkgs:
|
||||||
bundlers = mapAttrs (_: wrapBundler pkgs) (config.bundlers pkgs);
|
mapAttrs (_: wrapBundler pkgs) (config.bundlers pkgs));
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, src, lib, flakelight, ... }:
|
{ config, src, lib, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) isDerivation isFunction mkOption mkIf mapAttrs;
|
inherit (lib) isDerivation isFunction mkOption mkIf mapAttrs;
|
||||||
inherit (lib.types) lazyAttrsOf nullOr raw;
|
inherit (lib.types) lazyAttrsOf nullOr raw;
|
||||||
@ -26,7 +26,8 @@ in
|
|||||||
default = null;
|
default = null;
|
||||||
};
|
};
|
||||||
|
|
||||||
config.perSystem = mkIf (config.checks != null) (pkgs: {
|
config.outputs = mkIf (config.checks != null) {
|
||||||
checks = mapAttrs (mkCheck pkgs src) (config.checks pkgs);
|
checks = genSystems (pkgs:
|
||||||
});
|
mapAttrs (mkCheck pkgs src) (config.checks pkgs));
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
@ -26,6 +26,8 @@ let
|
|||||||
inherit (config.nixpkgs) config;
|
inherit (config.nixpkgs) config;
|
||||||
overlays = config.withOverlays ++ [ config.packageOverlay ];
|
overlays = config.withOverlays ++ [ config.packageOverlay ];
|
||||||
});
|
});
|
||||||
|
|
||||||
|
genSystems = f: genAttrs config.systems (system: f pkgsFor.${system});
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
@ -62,7 +64,7 @@ in
|
|||||||
config = {
|
config = {
|
||||||
_module.args = {
|
_module.args = {
|
||||||
inherit (config) inputs outputs;
|
inherit (config) inputs outputs;
|
||||||
inherit pkgsFor;
|
inherit pkgsFor genSystems;
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = foldAttrs mergeAttrs { } (map
|
outputs = foldAttrs mergeAttrs { } (map
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, lib, flakelight, ... }:
|
{ config, lib, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) filterAttrs mapAttrs mkDefault mkIf mkMerge mkOption;
|
inherit (lib) filterAttrs mapAttrs mkDefault mkIf mkMerge mkOption;
|
||||||
inherit (lib.types) coercedTo functionTo lazyAttrsOf lines listOf nullOr
|
inherit (lib.types) coercedTo functionTo lazyAttrsOf lines listOf nullOr
|
||||||
@ -71,10 +71,9 @@ in
|
|||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (config.devShells != { }) {
|
(mkIf (config.devShells != { }) {
|
||||||
perSystem = pkgs: {
|
outputs.devShells = genSystems (pkgs:
|
||||||
devShells = filterAttrs (_: supportedSystem pkgs)
|
filterAttrs (_: supportedSystem pkgs)
|
||||||
(mapAttrs (_: v: pkgs.callPackage v { }) config.devShells);
|
(mapAttrs (_: v: pkgs.callPackage v { }) config.devShells));
|
||||||
};
|
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, src, lib, flakelight, ... }:
|
{ config, src, lib, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (lib) mkDefault mkMerge mkOption mkIf mapAttrsToList;
|
inherit (lib) mkDefault mkMerge mkOption mkIf mapAttrsToList;
|
||||||
inherit (lib.types) lazyAttrsOf nullOr package str;
|
inherit (lib.types) lazyAttrsOf nullOr package str;
|
||||||
@ -22,28 +22,26 @@ in
|
|||||||
|
|
||||||
config = mkMerge [
|
config = mkMerge [
|
||||||
(mkIf (config.formatter != null) {
|
(mkIf (config.formatter != null) {
|
||||||
perSystem = pkgs: {
|
outputs.formatter = genSystems config.formatter;
|
||||||
formatter = config.formatter pkgs;
|
|
||||||
};
|
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf (config.formatters != null) {
|
(mkIf (config.formatters != null) {
|
||||||
perSystem = { pkgs, lib, fd, coreutils, ... }: {
|
outputs.formatter = mkDefault (genSystems
|
||||||
formatter = mkDefault (pkgs.writeShellScriptBin "formatter" ''
|
({ pkgs, lib, fd, coreutils, ... }:
|
||||||
PATH=${lib.makeBinPath ((config.devShell.packages or (_: [ ])) pkgs)}
|
pkgs.writeShellScriptBin "formatter" ''
|
||||||
for f in "$@"; do
|
PATH=${lib.makeBinPath (config.devShell.packages or (_: [ ]) pkgs)}
|
||||||
if [ -d "$f" ]; then
|
for f in "$@"; do
|
||||||
${fd}/bin/fd "$f" -Htf -x "$0" &
|
if [ -d "$f" ]; then
|
||||||
else
|
${fd}/bin/fd "$f" -Htf -x "$0" &
|
||||||
case "$(${coreutils}/bin/basename "$f")" in
|
else
|
||||||
${toString (mapAttrsToList
|
case "$(${coreutils}/bin/basename "$f")" in
|
||||||
(n: v: "${n}) ${v} \"$f\" & ;;") (config.formatters pkgs))}
|
${toString (mapAttrsToList
|
||||||
esac
|
(n: v: "${n}) ${v} \"$f\" & ;;") (config.formatters pkgs))}
|
||||||
fi
|
esac
|
||||||
done &>/dev/null
|
fi
|
||||||
wait
|
done &>/dev/null
|
||||||
'');
|
wait
|
||||||
};
|
''));
|
||||||
})
|
})
|
||||||
|
|
||||||
(mkIf ((config.formatters != null) || (config.formatter != null)) {
|
(mkIf ((config.formatters != null) || (config.formatter != null)) {
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
, inputs
|
, inputs
|
||||||
, outputs
|
, outputs
|
||||||
, pkgsFor
|
, pkgsFor
|
||||||
|
, genSystems
|
||||||
, specialArgs
|
, specialArgs
|
||||||
, modulesPath
|
, modulesPath
|
||||||
, moduleArgs
|
, moduleArgs
|
||||||
|
@ -2,7 +2,7 @@
|
|||||||
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
# Copyright (C) 2023 Archit Gupta <archit@accelbread.com>
|
||||||
# SPDX-License-Identifier: MIT
|
# SPDX-License-Identifier: MIT
|
||||||
|
|
||||||
{ config, lib, inputs, flakelight, ... }:
|
{ config, lib, inputs, flakelight, genSystems, ... }:
|
||||||
let
|
let
|
||||||
inherit (builtins) parseDrvName;
|
inherit (builtins) parseDrvName;
|
||||||
inherit (lib) filterAttrs mapAttrs mapAttrs' mkIf mkMerge mkOption
|
inherit (lib) filterAttrs mapAttrs mapAttrs' mkIf mkMerge mkOption
|
||||||
@ -56,10 +56,13 @@ in
|
|||||||
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
|
(config.packageOverlay (final.appendOverlays config.withOverlays) prev)
|
||||||
[ "default" ];
|
[ "default" ];
|
||||||
|
|
||||||
perSystem = pkgs: rec {
|
outputs = rec {
|
||||||
packages = filterAttrs (_: supportedSystem pkgs) (genPkgs pkgs);
|
packages = genSystems (pkgs:
|
||||||
|
filterAttrs (_: supportedSystem pkgs) (genPkgs pkgs));
|
||||||
|
|
||||||
checks = mapAttrs' (n: nameValuePair ("packages-" + n)) packages;
|
checks = mapAttrs
|
||||||
|
(_: mapAttrs' (n: nameValuePair ("packages-" + n)))
|
||||||
|
packages;
|
||||||
};
|
};
|
||||||
})
|
})
|
||||||
];
|
];
|
||||||
|
Loading…
Reference in New Issue
Block a user