Moving to modules. Structural changes.

This commit is contained in:
kat witch 2021-07-05 22:47:28 +01:00
parent 3903bc1766
commit 060d4c6d1e
No known key found for this signature in database
GPG key ID: 1B477797DCA5EC72
258 changed files with 621 additions and 407 deletions

View file

@ -1,6 +1,15 @@
{ sources, system ? builtins.currentSystem, ... }@args:
{ sources, system ? builtins.currentSystem, ... }@args:
let
liboverlay = self: super: {
lib = super.lib.extend (self: super: import ./lib
{
inherit super;
lib = self;
isOverlayLib = true;
}
);
};
overlay = self: super: rec {
dino = super.dino.overrideAttrs (
{ patches ? [], ... }: {
@ -55,8 +64,6 @@ let
nerdfonts = super.nerdfonts.override { fonts = [ "Iosevka" ]; };
hextorgba = (import ../lib/colorhelpers.nix { inherit (super) lib; }).hextorgba;
konawall = super.konawall.overide { swaySupport = true; };
imv = super.imv.override {
@ -77,11 +84,12 @@ let
kat-scrot = self.callPackage ./kat-scrot { };
} // super.lib.optionalAttrs (builtins.pathExists ../trusted/pkgs)
(import ../trusted/pkgs { inherit super self; });
} // super.lib.optionalAttrs (builtins.pathExists ../config/trusted/pkgs)
(import ../config/trusted/pkgs { inherit super self; });
pkgs = import sources.nixpkgs {
overlays = [
overlay
liboverlay
(import (sources.nixexprs + "/overlay.nix"))
];
config = {

View file

@ -0,0 +1,25 @@
{ 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})"
);
}

16
pkgs/lib/default.nix Normal file
View file

@ -0,0 +1,16 @@
{ pkgs ? import <nixpkgs> { }
, lib ? pkgs.lib
# for internal use...
, super ? if !isOverlayLib then lib else { }
, self ? if isOverlayLib then lib else { }
, before ? if !isOverlayLib then lib else { }
, 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;
hostImport = import ./host-import.nix { inherit lib; };
modList = import ./module-list.nix;
}; in katlib

6
pkgs/lib/host-import.nix Normal file
View file

@ -0,0 +1,6 @@
{ lib }: hostName: lib.filter builtins.pathExists [
(../../config/hosts + "/${hostName}/nixos")
(../../config/trusted/hosts + "/${hostName}/nixos")
../../config/trusted/profile
../../config/nixos.nix
]

27
pkgs/lib/module-list.nix Normal file
View file

@ -0,0 +1,27 @@
{ modulesDir, defaultFile ? "default.nix", importAll ? false }:
with builtins;
let
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}"))
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 (isFunction m) && !importAll then value else m;
})
files;
in
(listToAttrs modules)