Skip to content

Commit 6bce99c

Browse files
committed
Remove uses of "with lib;"
Avoids a Nix "anti-pattern"
1 parent e8a0789 commit 6bce99c

34 files changed

+235
-199
lines changed

default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,10 @@
66
lib ? pkgs.stdenv.lib
77
}:
88

9-
with lib;
109
let
11-
eval = (evalModules {
10+
inherit (lib) mkOption types;
11+
12+
eval = (lib.evalModules {
1213
modules = [
1314
({ config, ... }: {
1415
options.nixpkgs.overlays = mkOption {

example.nix

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,6 @@
66

77
{ config, pkgs, lib, ... }:
88

9-
with pkgs;
10-
with lib;
11-
129
let
1310
myDomain = "daniel.fullmer.me";
1411
in
@@ -41,7 +38,7 @@ in
4138
};
4239

4340
# Custom hosts file
44-
hosts = fetchurl { # 2019-08-14
41+
hosts = pkgs.fetchurl { # 2019-08-14
4542
url = "https://raw.githubusercontent.com/StevenBlack/hosts/449a0d7f613e6518ede4f3333e94f8071d3f1cd3/hosts";
4643
sha256 = "1mcn77l2m45qms7ynww2hzx0d6mja03bzj4di0s9j7spycp4540i";
4744
};

flavors/grapheneos/default.nix

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,11 @@
22
# SPDX-License-Identifier: MIT
33

44
{ config, pkgs, lib, ... }:
5-
with lib;
65
let
6+
inherit (lib)
7+
optional optionalString optionalAttrs elem
8+
mkIf mkMerge mkDefault mkForce;
9+
710
grapheneOSRelease = "${config.apv.buildID}.2021.04.22.20";
811

912
phoneDeviceFamilies = [ "crosshatch" "bonito" "coral" "sunfish" "redfin" ];

flavors/lineageos/default.nix

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,16 @@
22
# SPDX-License-Identifier: MIT
33

44
{ config, pkgs, lib, ... }:
5-
with lib;
65
let
6+
inherit (lib)
7+
optional optionals optionalString optionalAttrs
8+
elem mapAttrs mapAttrs' nameValuePair filterAttrs
9+
attrNames getAttrs flatten remove
10+
mkIf mkMerge mkDefault mkForce
11+
importJSON toLower;
12+
713
LineageOSRelease = "lineage-17.1";
8-
repoDirs = lib.importJSON (./. + "/repo-${LineageOSRelease}.json");
14+
repoDirs = importJSON (./. + "/repo-${LineageOSRelease}.json");
915
deviceMetadata = importJSON ./device-metadata.json;
1016
_deviceDirs = importJSON ./device-dirs.json;
1117
vendorDirs = importJSON ./vendor-dirs.json;

flavors/vanilla/default.nix

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22
# SPDX-License-Identifier: MIT
33

44
{ config, pkgs, lib, ... }:
5-
with lib;
65
let
7-
# https://source.android.com/setup/start/build-numbers
6+
inherit (lib)
7+
optional optionalString optionalAttrs elem
8+
mkIf mkMerge mkDefault;
89

10+
# https://source.android.com/setup/start/build-numbers
911
phoneDeviceFamilies =
1012
(optional (config.androidVersion <= 10) "marlin")
1113
++ [ "taimen" "muskie" "crosshatch" "bonito" "coral" "sunfish" "redfin" ];
@@ -203,7 +205,7 @@ in mkIf (config.flavor == "vanilla") (mkMerge [
203205
"arch/arm64/boot/dts/vendor/qcom/display" = fetchRepo "private/msm-google/arch/arm64/boot/dts/vendor/qcom/display";
204206
};
205207
in pkgs.runCommand "kernel-src" {}
206-
(concatStringsSep "\n" (lib.mapAttrsToList (relpath: repo: ''
208+
(lib.concatStringsSep "\n" (lib.mapAttrsToList (relpath: repo: ''
207209
${lib.optionalString (relpath != "") "mkdir -p $out/$(dirname ${relpath})"}
208210
cp -r ${repo} $out/${relpath}
209211
chmod u+w -R $out/${relpath}

lib/default.nix

Lines changed: 12 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,34 +3,33 @@
33

44
lib:
55

6-
with lib; # Android stuff that might come in handy across multiple modules, profiles, etc
76
rec {
87
# Guess resource type. Should normally work fine, but can't detect color/dimension types
98
resourceTypeName = r:
10-
if isBool r then "bool"
11-
else if isInt r then "integer"
12-
else if isString r then "string"
13-
else if isList r then
14-
(assert (length r != 0); # Cannot autodetect type of empty list
15-
if isInt (head r) then "integer-array"
16-
else if isString (head r) then "string-array"
9+
if lib.isBool r then "bool"
10+
else if lib.isInt r then "integer"
11+
else if lib.isString r then "string"
12+
else if lib.isList r then
13+
(assert (lib.length r != 0); # Cannot autodetect type of empty list
14+
if lib.isInt (lib.head r) then "integer-array"
15+
else if lib.isString (lib.head r) then "string-array"
1716
else assert false; "Unknown type"
1817
)
1918
else assert false; "Unknown type";
2019
resourceValueXML = value: type: {
21-
bool = boolToString value;
20+
bool = lib.boolToString value;
2221
color = value; # define our own specialized type for these?
2322
dimension = value;
2423
integer = toString value;
2524
string = value;
26-
integer-array = concatMapStringsSep "" (i: "<item>${toString i}</item>") value;
27-
string-array = concatMapStringsSep "" (i: "<item>${i}</item>") value;
25+
integer-array = lib.concatMapStringsSep "" (i: "<item>${toString i}</item>") value;
26+
string-array = lib.concatMapStringsSep "" (i: "<item>${i}</item>") value;
2827
# Ignoring other typed arrays for now
2928
}.${type};
3029

3130
resourceXML = name: value: let
3231
resourceXMLEntity = name: value: type: ''<${type} name="${name}">${resourceValueXML value type}</${type}>'';
33-
in if isAttrs value then
32+
in if lib.isAttrs value then
3433
# Submodule with manually specified resource type
3534
resourceXMLEntity name value.value value.type
3635
else
@@ -40,7 +39,7 @@ rec {
4039
configXML = resources: ''
4140
<?xml version="1.0" encoding="utf-8"?>
4241
<resources>
43-
${concatStringsSep "\n" (mapAttrsToList resourceXML resources)}
42+
${lib.concatStringsSep "\n" (lib.mapAttrsToList resourceXML resources)}
4443
</resources>
4544
'';
4645

modules/10/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
{ config, pkgs, lib, ... }:
55

6-
with lib;
76
let
7+
inherit (lib) mkIf mkDefault;
8+
89
# Some mostly-unique data used as input for filesystem UUIDs, hash_seeds, and AVB salt.
910
# TODO: Maybe include all source hashes except from build/make to avoid infinite recursion?
1011
hash = builtins.hashString "sha256" "${config.buildNumber} ${builtins.toString config.buildDateTime}";
@@ -15,7 +16,7 @@ mkIf (config.androidVersion == 10) {
1516
source.dirs."build/make" = {
1617
patches = [
1718
./build_make/0001-Readonly-source-fix.patch
18-
] ++ (optional (config.flavor != "lineageos")
19+
] ++ (lib.optional (config.flavor != "lineageos")
1920
(pkgs.substituteAll {
2021
src = ./build_make/0002-Partition-size-fix.patch;
2122
inherit (pkgs) coreutils;

modules/11/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
{ config, pkgs, lib, ... }:
55

6-
with lib;
76
let
7+
inherit (lib) mkIf mkDefault;
8+
89
# Some mostly-unique data used as input for filesystem UUIDs, hash_seeds, and AVB salt.
910
# TODO: Maybe include all source hashes except from build/make to avoid infinite recursion?
1011
hash = builtins.hashString "sha256" "${config.buildNumber} ${builtins.toString config.buildDateTime}";
@@ -15,7 +16,7 @@ mkIf (config.androidVersion == 11) {
1516
source.dirs."build/make" = {
1617
patches = [
1718
./build_make/0001-Readonly-source-fix.patch
18-
] ++ (optional (!(elem config.flavor [ "grapheneos" "lineageos" ]))
19+
] ++ (lib.optional (!(lib.elem config.flavor [ "grapheneos" "lineageos" ]))
1920
(pkgs.substituteAll {
2021
src = ./build_make/0002-Partition-size-fix.patch;
2122
inherit (pkgs) coreutils;

modules/12/default.nix

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,9 @@
33

44
{ config, pkgs, lib, ... }:
55

6-
with lib;
7-
6+
let
7+
inherit (lib) mkIf;
8+
in
89
mkIf (config.androidVersion == 12) {
910
apiLevel = 31;
1011

modules/9/default.nix

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@
22
# SPDX-License-Identifier: MIT
33
{ config, pkgs, lib, ... }:
44

5-
with lib;
65
let
6+
inherit (lib) mkIf mkDefault;
7+
78
flex = pkgs.callPackage ./flex-2.5.39.nix {};
89
in
910
mkIf (config.androidVersion == 9) {

0 commit comments

Comments
 (0)