forked from tiiuae/ghaf
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlib.nix
57 lines (51 loc) · 1.45 KB
/
lib.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
46
47
48
49
50
51
52
53
54
55
56
57
# Copyright 2022-2024 TII (SSRC) and the Ghaf contributors
# Copyright 2020-2023 Pacman99 and the Digga Contributors
#
# SPDX-License-Identifier: MIT
# FlattenTree and rakeLeaves originate from
# https://github.com/divnix/digga
{ inputs, ... }:
let
inherit (inputs) nixpkgs;
in
nixpkgs.lib.extend (
lib: _: {
/*
*
Filters Nix packages based on the target system platform.
Returns a filtered attribute set of Nix packages compatible with the target system.
# Example
```
lib.platformPkgs "x86_64-linux" {
hello-compatible = pkgs.hello.overrideAttrs (old: { meta.platforms = ["x86_64-linux"]; });
hello-inccompatible = pkgs.hello.overrideAttrs (old: { meta.platforms = ["aarch-linux"]; });
}
=> { hello-compatible = «derivation /nix/store/g2mxdrkwr1hck4y5479dww7m56d1x81v-hello-2.12.1.drv»; }
```
# Type
```
filterAttrs :: String -> AttrSet -> AttrSet
```
# Arguments
- [system] Target system platform (e.g., "x86_64-linux").
- [pkgsSet] a set of Nix packages.
*/
# TODO should this be replaced with flake-parts pkgs-by-name
platformPkgs =
system:
lib.filterAttrs (
_: value:
let
platforms =
lib.attrByPath
[
"meta"
"platforms"
]
[ ]
value;
in
lib.elem system platforms
);
}
)