Skip to content

Commit 392fa71

Browse files
committed
feat: remove lib-extras input
1 parent 7a8460b commit 392fa71

File tree

6 files changed

+118
-65
lines changed

6 files changed

+118
-65
lines changed

flake.lock

Lines changed: 0 additions & 47 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

flake.nix

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -39,25 +39,15 @@
3939
inputs.nixpkgs.follows = "nixpkgs";
4040
};
4141
flake-compat.url = "github:nix-community/flake-compat";
42-
lib-extras = {
43-
url = "github:aldoborrero/lib-extras/v0.2.2";
44-
inputs.devshell.follows = "devshell";
45-
inputs.flake-parts.follows = "flake-parts";
46-
inputs.nixpkgs.follows = "nixpkgs";
47-
inputs.treefmt-nix.follows = "treefmt-nix";
48-
};
4942
};
5043

5144
outputs = inputs @ {
5245
flake-parts,
5346
nixpkgs,
54-
lib-extras,
5547
systems,
5648
...
5749
}: let
58-
lib = nixpkgs.lib.extend (l: _: {
59-
extras = (lib-extras.lib l) // (import ./lib.nix l);
60-
});
50+
lib = nixpkgs.lib.extend (l: _: (import ./lib.nix l));
6151
in
6252
flake-parts.lib.mkFlake {
6353
inherit inputs;
@@ -82,15 +72,15 @@
8272
}: {
8373
# pkgs
8474
_module.args = {
85-
pkgs = lib.extras.nix.mkNixpkgs {
75+
pkgs = lib.mkNixpkgs {
8676
inherit system;
8777
inherit (inputs) nixpkgs;
8878
};
89-
pkgsUnstable = lib.extras.nix.mkNixpkgs {
79+
pkgsUnstable = lib.mkNixpkgs {
9080
inherit system;
9181
nixpkgs = inputs.nixpkgs-unstable;
9282
};
93-
pkgs2311 = lib.extras.nix.mkNixpkgs {
83+
pkgs2311 = lib.mkNixpkgs {
9484
inherit system;
9585
nixpkgs = inputs.nixpkgs-2311;
9686
};

lib.nix

Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,114 @@
11
lib: rec {
2+
/*
3+
Function: mkNixpkgs
4+
Synopsis: Creates a custom Nixpkgs configuration.
5+
6+
Parameters:
7+
- system (string): Target system, e.g., "x86_64-linux".
8+
- inputs (attrset, optional): Custom inputs for the Nixpkgs configuration.
9+
- overlays (list, optional): List of overlays to apply.
10+
- nixpkgs (path, optional): Path to the Nixpkgs repository. Defaults to inputs.nixpkgs.
11+
- config (attrset, optional): Additional Nixpkgs configuration settings.
12+
13+
Returns:
14+
- A configured Nixpkgs environment suitable for importing.
15+
16+
Example:
17+
mkNixpkgs {
18+
system = "x86_64-linux";
19+
overlays = [ myOverlay ];
20+
}
21+
22+
Description:
23+
The function imports a Nixpkgs environment with the specified target system, custom inputs,
24+
and overlays. It also accepts additional Nixpkgs configuration settings.
25+
*/
26+
mkNixpkgs = {
27+
system,
28+
nixpkgs,
29+
overlays ? [],
30+
config ? {allowUnfree = true;},
31+
}:
32+
import nixpkgs {inherit system config overlays;};
33+
34+
/*
35+
Function: mkApp
36+
Synopsis: Creates an "app" type for Nix flakes.
37+
38+
Parameters:
39+
- drv (derivation): The Nix derivation.
40+
- name (string, optional): Name of the application.
41+
- exePath (string, optional): Executable path.
42+
43+
Returns:
44+
- An "app" type attribute with 'type' and 'program' keys.
45+
*/
46+
mkApp = {
47+
drv,
48+
name ? drv.pname or drv.name,
49+
exePath ? drv.passthru.exePath or "/bin/${name}",
50+
}: {
51+
type = "app";
52+
program = "${drv}${exePath}";
53+
};
54+
55+
/*
56+
Function: buildApps
57+
Synopsis: Constructs attribute set of applications from Nix packages and custom apps specification.
58+
59+
Parameters:
60+
- packages (attrset): An attribute set of Nix packages.
61+
- apps (attrset): Custom apps specification.
62+
63+
Returns:
64+
- An attribute set representing built applications.
65+
*/
66+
buildApps = packages: apps:
67+
lib.listToAttrs
68+
(lib.collect (attrs: lib.attrNames attrs == ["name" "value"])
69+
(lib.mapAttrsRecursiveCond lib.isAttrs (path: v: let
70+
drvName = lib.head path;
71+
drv = packages.${drvName};
72+
name = lib.last (lib.init path);
73+
exePath = "/bin/${v}";
74+
in
75+
lib.nameValuePair name {inherit drv name exePath;})
76+
apps));
77+
78+
/*
79+
Function: platformPkgs
80+
Synopsis: Filters Nix packages based on the target system platform.
81+
82+
Parameters:
83+
- system (string): Target system platform (e.g., "x86_64-linux").
84+
85+
Returns:
86+
- A filtered attribute set of Nix packages compatible with the target system.
87+
*/
88+
platformPkgs = system:
89+
lib.filterAttrs
90+
(_: value: let
91+
platforms = lib.attrByPath ["meta" "platforms"] [] value;
92+
in
93+
lib.elem system platforms);
94+
95+
/*
96+
Function: platformApps
97+
Synopsis: Filters and builds platform-specific applications.
98+
99+
Parameters:
100+
- packages (attrset): An attribute set of Nix packages.
101+
- apps (attrset): Custom apps specification.
102+
103+
Returns:
104+
- An attribute set of platform-specific applications.
105+
*/
106+
platformApps = packages: apps: let
107+
apps' = lib.filterAttrs (name: _: lib.elem name (lib.attrNames packages)) apps;
108+
bapps = buildApps packages apps';
109+
in
110+
lib.mapAttrs (_: mkApp) bapps;
111+
2112
/*
3113
Function: flattenTree
4114
Synopsis: Flattens a nested attribute set (tree) into a single-level attribute set.

mkdocs.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@
3131
docsPath = "./docs/nixos/modules";
3232
nixosMarkdownDocs = runCommand "nixos-options" {} ''
3333
mkdir $out
34-
${lib.extras.mkdocs.createNixosMarkdownDocs {modulesPath = ./modules;}}
34+
${lib.createNixosMarkdownDocs {modulesPath = ./modules;}}
3535
'';
3636
in
3737
stdenv.mkDerivation {

modules/testing.nix

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@
3737
eachTest =
3838
filterAttrs
3939
(_: (hasSuffix ".test.nix"))
40-
(extras.flattenTree {
41-
tree = extras.rakeLeaves ./.;
40+
(flattenTree {
41+
tree = rakeLeaves ./.;
4242
separator = "-";
4343
});
4444

pkgs/default.nix

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
...
2222
}: let
2323
inherit (pkgs) callPackage;
24-
inherit (lib.extras.flakes) platformPkgs platformApps;
24+
inherit (lib) platformPkgs platformApps;
2525
callPackageUnstable = pkgsUnstable.callPackage;
2626
callPackage2311 = pkgs2311.callPackage;
2727
in {

0 commit comments

Comments
 (0)