Restructure to focus on nix.
This commit is contained in:
parent
6952570818
commit
588fdbd9f2
19 changed files with 4 additions and 25 deletions
5
lib/default.nix
Normal file
5
lib/default.nix
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
nixpkgs: withSystem: {
|
||||
utils = import ./utils.nix;
|
||||
getSSHKeys = (import ./keys.nix).getSSHKeys;
|
||||
mkSystem = (import ./nixos.nix nixpkgs withSystem).mkSystem;
|
||||
}
|
||||
22
lib/keys.nix
Normal file
22
lib/keys.nix
Normal file
|
|
@ -0,0 +1,22 @@
|
|||
let
|
||||
utils = import ./utils.nix;
|
||||
in 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 = utils.getName name;
|
||||
value = builtins.attrValues (import path);
|
||||
}
|
||||
]
|
||||
else [];
|
||||
in
|
||||
builtins.listToAttrs (builtins.concatLists (builtins.attrValues (builtins.mapAttrs procEntry entries)));
|
||||
}
|
||||
25
lib/nixos.nix
Normal file
25
lib/nixos.nix
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
nixpkgs: withSystem: let
|
||||
foelib = import ./default.nix nixpkgs withSystem;
|
||||
in {
|
||||
mkSystem = hostname: host-platform: modules:
|
||||
withSystem host-platform
|
||||
({pkgs, ...}:
|
||||
nixpkgs.lib.nixosSystem {
|
||||
modules =
|
||||
[
|
||||
{
|
||||
nix.registry = {
|
||||
nixpkgs.flake = nixpkgs;
|
||||
p.flake = nixpkgs;
|
||||
};
|
||||
nixpkgs.pkgs = pkgs;
|
||||
|
||||
networking.hostName = hostname;
|
||||
}
|
||||
]
|
||||
++ modules;
|
||||
specialArgs = {
|
||||
inherit hostname foelib;
|
||||
};
|
||||
});
|
||||
}
|
||||
28
lib/packages.nix
Normal file
28
lib/packages.nix
Normal 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))
|
||||
47
lib/utils.nix
Normal file
47
lib/utils.nix
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
rec {
|
||||
findNixFiles = dir: let
|
||||
inherit (builtins) attrNames readDir pathExists concatMap;
|
||||
|
||||
# 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;
|
||||
|
||||
getName = filename: let
|
||||
parts = builtins.split "\\." filename;
|
||||
base = builtins.head (builtins.split "\\." filename);
|
||||
in
|
||||
if builtins.length parts == 1
|
||||
then filename
|
||||
else base;
|
||||
|
||||
getSuffix = filename: let
|
||||
parts = builtins.split "\\." filename;
|
||||
end = builtins.tail (builtins.split "\\." filename);
|
||||
in
|
||||
if builtins.length parts == 1
|
||||
then filename
|
||||
else builtins.elemAt end (builtins.length end - 1);
|
||||
|
||||
hasSuffix = suffix: filename:
|
||||
if (getSuffix filename) == suffix
|
||||
then true
|
||||
else false;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue