Initial Commit

This commit is contained in:
Lorenzo Good 2025-01-26 18:49:45 -06:00
commit d07ba813bf
Signed by: lorenzo
GPG key ID: 7FCD64BD81180ED0
14 changed files with 360 additions and 0 deletions

4
nixos/lib/default.nix Normal file
View file

@ -0,0 +1,4 @@
{
utils = import ./utils.nix;
getSSHKeys = (import ./keys.nix).getSSHKeys;
}

28
nixos/lib/keys.nix Normal file
View file

@ -0,0 +1,28 @@
rec {
getSSHKeys = name: (getKeySets ../keys)."${name}";
getKeySets = dir: let
entries = builtins.readDir dir;
procEntry = name: type: let
path = dir + "/${name}";
in
if type == "regular"
then [
{
name = getName name;
value = builtins.attrValues (import path);
}
]
else [];
in
builtins.listToAttrs (builtins.concatLists (builtins.attrValues (builtins.mapAttrs procEntry entries)));
getName = filename: let
parts = builtins.split "\\." filename;
base = builtins.head (builtins.split "\\." filename);
in
if builtins.length parts == 1
then filename
else base;
}

28
nixos/lib/packages.nix Normal file
View file

@ -0,0 +1,28 @@
pkgs: let
getPackages = dir: let
entries = builtins.readDir dir;
procEntry = name: type: let
path = dir + "/${name}";
in
if type == "directory"
then
(
if builtins.pathExists (path + "/default.nix")
then [path]
else []
)
else [];
in
builtins.concatLists (
builtins.attrValues (
builtins.mapAttrs procEntry entries
)
);
buildPackage = path: {
name = builtins.baseNameOf (toString path);
value = pkgs.callPackage (path + "/default.nix") {};
};
in
builtins.listToAttrs (builtins.map buildPackage (getPackages ../packages))

26
nixos/lib/utils.nix Normal file
View file

@ -0,0 +1,26 @@
rec {
findNixFiles = dir: let
inherit (builtins) attrNames readDir pathExists concatMap hasSuffix;
# Helper function to build full paths
fullPath = name: dir + "/${name}";
# Get directory contents
contents = readDir dir;
# Convert contents attrset to list of names
names = attrNames contents;
# Filter and process each item
processItem = name: let
path = fullPath name;
type = contents.${name};
in
if type == "regular" && hasSuffix ".nix" name
then [path]
else if type == "directory" && pathExists path
then findNixFiles path
else [];
in
concatMap processItem names;
}