-
-
Notifications
You must be signed in to change notification settings - Fork 14.1k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
treewide/nixos: remove with lib;
part 1
#335603
treewide/nixos: remove with lib;
part 1
#335603
Conversation
099da41
to
6b78fcd
Compare
with lib;
with lib;
part 1
6b78fcd
to
dda01b2
Compare
dda01b2
to
7e5b373
Compare
@philiptaron would you consider this "size" of MR ok to review? I am going to split up the individual services. (I have already written a shitty script to generate these changes, with a total of 1241 changed files. I will review all files by hand before I submit them via PR.) |
7e5b373
to
7878f35
Compare
@Stunkymonkey: I think a few things 🙂
Thank you for tackling this refactor! |
@philiptaron my "shitty" script (simple replace): shitty-patch.sh#!/usr/bin/env bash
# Get the list of files containing "with lib;"
files=$(grep -rlFx "with lib;" /home/felix/code/system-installs/nixpkgs/nixos/)
options=(
"any"
"attrByPath"
"attrNames"
"attrValues"
"boolToString"
"cli."
"concatLists"
"concatMap"
"concatStrings"
"const"
"elem"
"escape"
"filter"
"flatten"
"flip"
"foldAttrs"
"foldl"
"foldr"
"generators."
"getBin"
"getDev"
"getExe"
"hasAttr"
"hasPrefix"
"hasSuffix"
"imap1"
"isAttrs"
"isBool"
"isDerivation"
"isInt"
"isList"
"isPath"
"isString"
"last"
"length"
"lessThan"
"lists"
"listToAttrs"
"literalExpression"
"literalMD"
"maintainers."
"makeBinPath"
"makeLibraryPath"
"mapAttrs"
"maybeEnv"
"mergeOneOption"
"mkAliasOptionModuleMD"
"mkBefore"
"mkDefault"
"mkEnableOption"
"mkForce"
"mkIf"
"mkImageMediaOverride"
"mkMerge"
"mkOption"
"mkOrder"
"mkOverride"
"mkPackageOption"
"mkRemovedOptionModule"
"mkRenamedOptionModule"
"nameValuePair"
"optional"
"recursiveUpdate"
"removePrefix"
"replaceStrings"
"setPrio"
"singleton"
"sort"
"stringAfter"
"stringLength"
"stringToCharacters"
"substring"
"subtractLists"
"teams."
"toList"
"toUpper"
"types."
"unique"
"versionAtLeast"
"versionOlder"
"zipAttrs"
# "all" too many other instances
# "partition" too many other instances
)
# Function to escape special characters for sed
escape_sed_pattern() {
echo "$1" | sed 's/[.[\*^$+()|]/\\&/g'
}
# Loop over each file
for file in $files; do
# delete empty before
sed -i '/with lib;/,$ b; /^$/d;' "$file"
# delete empty after
sed -i '/with lib;/{N;s/\n$//}' "$file"
# delete match
sed -i '/^\s*with lib;\s*$/d' "$file"
for str in "${options[@]}"; do
# Escape the string for use in sed
escaped_str=$(escape_sed_pattern "$str")
# Prepend "lib." to the current string
lib_str="lib.$str"
# Escape the lib_str for use in sed
escaped_lib_str=$(escape_sed_pattern "$lib_str")
# Use sed to replace occurrences in the temporary file
sed -i '/inherit/!s/'"$escaped_str"'/'"$escaped_lib_str"'/g' "$file"
done
sed -i "s/with maintainers;/with lib.maintainers;/g" "$file"
sed -i "s/with types;/with lib.types;/g" "$file"
# revert wrong locations
sed -i "s/mlib.any/many/g" "$file"
done
I guess you wanted to say about "lines of changes"? I started with #336404 |
No, I'm saying 150 commits (150 files) 😁 I feel quite adept at reviewing patterns. |
The tool sadly makes a few bugs -- see if you can evolve it a bit so it doesn't make this: |
7878f35
to
c691398
Compare
34f9a0c
to
060641e
Compare
79d18dc
to
14dad27
Compare
3b7622d#diff-9bd6954b6c183d51a0dcbf1f540c61b89a2427e1d3ee7af1dccd98ca2c859279R118 This must've slipped. |
How do we currently ensure that the rest of the changes are correct and not just because others haven't used them yet? |
easiest way imo would be to fix the script and then rerun it before this PR to identify the differences. one problem is the missing |
Okay I've started running it locally, but it seems to be quite slow, not sure when it'll finish.
|
Description of changes
part of #208242
Things done
nix.conf
? (See Nix manual)sandbox = relaxed
sandbox = true
nix-shell -p nixpkgs-review --run "nixpkgs-review rev HEAD"
. Note: all changes have to be committed, also see nixpkgs-review usage./result/bin/
)Add a 👍 reaction to pull requests you find important.