mirror of
https://github.com/sadan4/dotfiles.git
synced 2025-06-19 10:47:01 -04:00
work
This commit is contained in:
parent
f5431cbae8
commit
3b9f424694
7 changed files with 95 additions and 40 deletions
11
common/util/array.nix
Normal file
11
common/util/array.nix
Normal file
|
@ -0,0 +1,11 @@
|
|||
{ lib, ... }:
|
||||
{
|
||||
array = rec {
|
||||
popHead = list: lib.lists.ifilter0 (index: _element: index != 0) list;
|
||||
popTail = list: lib.lists.ifilter0 (index: _element: index - 1 != length list) list;
|
||||
head = list: at 0 list;
|
||||
tail = list: at (length list - 1) list;
|
||||
at = index: list: builtins.elemAt list index;
|
||||
length = list: builtins.length list;
|
||||
};
|
||||
}
|
13
common/util/default.nix
Normal file
13
common/util/default.nix
Normal file
|
@ -0,0 +1,13 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
util =
|
||||
(import ./modules.nix { }) // (import ./array.nix { }) // (import ./paths.nix { inherit lib; });
|
||||
in
|
||||
{
|
||||
_module.args = {
|
||||
inherit util;
|
||||
};
|
||||
home-manager.extraSpecialArgs = {
|
||||
inherit util;
|
||||
};
|
||||
}
|
4
common/util/modules.nix
Normal file
4
common/util/modules.nix
Normal file
|
@ -0,0 +1,4 @@
|
|||
{ ... }:
|
||||
{
|
||||
modulesFromPath = root: modules: builtins.map (mod: root + "/" + mod) modules;
|
||||
}
|
28
common/util/paths.nix
Normal file
28
common/util/paths.nix
Normal file
|
@ -0,0 +1,28 @@
|
|||
{ lib, ... }:
|
||||
let
|
||||
array = import ./array.nix { };
|
||||
in
|
||||
{
|
||||
path = rec {
|
||||
split = { path }: builtins.split "/" "${path}";
|
||||
removeSuffix = suffix: path: lib.removeSuffix suffix "${path}";
|
||||
# ====
|
||||
basename =
|
||||
{
|
||||
path,
|
||||
suffix ? "",
|
||||
}:
|
||||
let
|
||||
basename = if array.length (split path) >= 2 then array.tail (split path);
|
||||
in
|
||||
removeSuffix suffix basename;
|
||||
# nix doesnt support windows
|
||||
delimiter = ":";
|
||||
dirname =
|
||||
path:
|
||||
let
|
||||
ending = basename { inherit path; };
|
||||
in
|
||||
removeSuffix ending path;
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue