refactor: remove unused library functions, start removing with lib

This commit is contained in:
Kat Inskip 2022-07-10 15:18:00 -07:00
parent abbb3f8899
commit 600d890b7f
Signed by: kat
GPG key ID: 465E64DECEA8CF0F
23 changed files with 91 additions and 248 deletions

View file

@ -1,25 +0,0 @@
{ lib }: rec {
hexChars =
[ "0" "1" "2" "3" "4" "5" "6" "7" "8" "9" "a" "b" "c" "d" "e" "f" ];
hexCharToInt = char:
let
pairs = lib.imap0 (lib.flip lib.nameValuePair) hexChars;
idx = builtins.listToAttrs pairs;
in
idx.${lib.toLower char};
hexToInt = str:
lib.foldl (value: chr: value * 16 + hexCharToInt chr) 0
(lib.stringToCharacters str);
hextorgba = hex: alpha:
(
let
r_hex = lib.substring 1 2 hex;
g_hex = lib.substring 3 2 hex;
b_hex = lib.substring 5 2 hex;
r_dec = hexToInt r_hex;
g_dec = hexToInt g_hex;
b_dec = hexToInt b_hex;
in
"rgba(${toString r_dec}, ${toString g_dec}, ${toString b_dec}, ${toString alpha})"
);
}

View file

@ -1,13 +0,0 @@
{ lib }: { folder, defaultFile ? "default.nix", folderPaths ? [ ] }: with lib; let
defaultFileFinal =
if (defaultFile == "default.nix" && folder == "hosts") then
"nixos.nix"
else defaultFile;
folderModLists = map
(folderPath: modList {
modulesDir = folderPath;
defaultFile = defaultFileFinal;
})
(filter builtins.pathExists folderPaths);
in
foldl modListMerge { } folderModLists

View file

@ -1,7 +0,0 @@
{ lib }: path: excludes:
let
filterAttrNamesToList = filter: set:
lib.foldl' (a: b: a ++ b) [ ]
(map (e: if (filter e set.${e}) then [ e ] else [ ]) (lib.attrNames set));
in
(filterAttrNamesToList (name: type: ! (builtins.elem name excludes) && type == "directory") (builtins.readDir path))

View file

@ -1,5 +0,0 @@
{ lib }: pathsA: pathsB: with lib; let
pathIntersection = intersectLists (attrNames pathsA) (attrNames pathsB);
pathMerger = pathA: pathB: { imports = [ pathA pathB ]; };
in
pathsA // pathsB // genAttrs pathIntersection (key: (pathMerger pathsA.${key} pathsB.${key}))

View file

@ -1,29 +0,0 @@
{ lib }: { modulesDir, defaultFile ? "default.nix", importAll ? false }:
with builtins;
let
isModule = m: lib.isFunction m && (m.isModule or true);
filterAttrNamesToList = filter: set:
foldl' (a: b: a ++ b) [ ]
(map (e: if (filter e set.${e}) then [ e ] else [ ]) (attrNames set));
nameValuePair = name: value: { inherit name value; };
listToAttrs = foldl' (acc: val: acc // { ${val.name} = val.value; }) { };
directories =
filterAttrNamesToList (_: type: type == "directory") (readDir modulesDir);
files = map (dir: nameValuePair dir (modulesDir + "/${dir}/${defaultFile}"))
(filter (f: builtins.pathExists (modulesDir + "/${f}/${defaultFile}")) directories);
modules = map
({ name, value }:
# if the file contains a function, assume it to be a module and pass the path
# (for dedup and such). if it contains anything else, pass that.
let m = import value;
in
{
inherit name;
value = if lib.isFunction m && ! isModule m then m { inherit lib; } else if isModule m && !importAll then value else m;
})
files;
modList = (listToAttrs modules);
in
modList

View file

@ -7,17 +7,10 @@
, isOverlayLib ? false
}@args:
let
colorHelpers = import ./color-helpers.nix { inherit lib; };
lib = before // katlib // self;
katlib = with before; with katlib; with self;
{
inherit (colorHelpers) hextorgba;
nodeImport = import ./node-import.nix { inherit lib; };
virtualHostGen = import ./virtual-host-gen.nix { inherit lib; };
domainMerge = import ./domain-merge.nix { inherit lib; };
modListMerge = import ./intersect-merge.nix { inherit lib; };
modList = import ./module-list.nix { inherit lib; };
folderList = import ./folder-list.nix { inherit lib; };
};
in
katlib

View file

@ -1,11 +0,0 @@
{ lib }: { config, networkFilter ? [ ], addresses ? [ ], block }: with lib;
let
networks = config.network.addresses;
filteredNetworks = filterAttrs (n: v: elem n networkFilter) networks;
networkValues = attrValues filteredNetworks;
addressList' = concatMap (n: n.out.identifierList) networkValues;
addressList = map (n: builtins.unsafeDiscardStringContext n) addressList';
hostBlocks = map (host: nameValuePair host block) addressList;
in
listToAttrs hostBlocks

View file

@ -1,63 +0,0 @@
{ lib
, stdenv
, fetchFromGitHub
, rustPlatform
, cmake
, pkg-config
, zlib
, installShellFiles
, Security
, libiconv
}:
rustPlatform.buildRustPackage rec {
pname = "exa";
version = "0.10.1";
src = fetchFromGitHub {
owner = "ogham";
repo = pname;
rev = "v${version}";
sha256 = "sha256-vChsy/FrJEzTO5O+XFycPMP3jqOeea/hfsC0jJbqUVI=";
};
# Cargo.lock is outdated
cargoPatches = [ ./update-cargo-lock.diff ];
cargoSha256 = "sha256-ah8IjShmivS6IWL3ku/4/j+WNr/LdUnh1YJnPdaFdcM=";
nativeBuildInputs = [
cmake
pkg-config
installShellFiles
];
buildInputs = [ zlib ] ++ lib.optionals stdenv.isDarwin [ libiconv Security ];
outputs = [ "out" ];
postInstall = ''
installShellCompletion \
--name exa completions/completions.bash \
--name exa.fish completions/completions.fish \
--name _exa completions/completions.zsh
'';
# Some tests fail, but Travis ensures a proper build
doCheck = false;
meta = with lib; {
description = "Replacement for 'ls' written in Rust";
longDescription = ''
exa is a modern replacement for ls. It uses colours for information by
default, helping you distinguish between many types of files, such as
whether you are the owner, or in the owning group. It also has extra
features not present in the original ls, such as viewing the Git status
for a directory, or recursing into directories with a tree view. exa is
written in Rust, so its small, fast, and portable.
'';
changelog = "https://github.com/ogham/exa/releases/tag/v${version}";
homepage = "https://the.exa.website";
license = licenses.mit;
maintainers = with maintainers; [ ehegnes lilyball globin fortuneteller2k ];
};
}

View file

@ -1,13 +0,0 @@
diff --git a/Cargo.lock b/Cargo.lock
index df94188..ed3a068 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -57,7 +57,7 @@ dependencies = [
[[package]]
name = "exa"
-version = "0.11.0-pre"
+version = "0.10.1"
dependencies = [
"ansi_term",
"datetime",

View file

@ -25,11 +25,11 @@ stdenv.mkDerivation rec {
mv * $out
'';
meta = with lib; {
meta = {
description = "A lightweight file manager with full ShareX, Screencloud support and more";
homepage = "https://xbackbone.app/";
license = with licenses; agpl3;
maintainers = with maintainers; [ kittywitch ];
platforms = with platforms; unix;
license = lib.licenses.agpl3;
maintainers = [ lib.maintainers.kittywitch ];
platforms = lib.platforms.unix;
};
}