whole entire revamp
This commit is contained in:
parent
7b3e28f66d
commit
1c86119fbb
21 changed files with 652 additions and 272 deletions
15
lib/default.nix
Normal file
15
lib/default.nix
Normal file
|
@ -0,0 +1,15 @@
|
|||
{ inputs, lib, pkgs, ... }:
|
||||
|
||||
lib.extend (self: super:
|
||||
let
|
||||
inherit (lib) attrValues foldr;
|
||||
inherit (modules) mapModules;
|
||||
|
||||
modules = import ./modules.nix { inherit lib; };
|
||||
in {
|
||||
_ = foldr (a: b: a // b) {} (attrValues (mapModules ./. (file: import file {
|
||||
inherit pkgs inputs;
|
||||
lib = self;
|
||||
})));
|
||||
}
|
||||
)
|
27
lib/modules.nix
Normal file
27
lib/modules.nix
Normal file
|
@ -0,0 +1,27 @@
|
|||
{ lib, ... }:
|
||||
|
||||
let
|
||||
inherit (builtins) attrValues readDir pathExists;
|
||||
inherit (lib) id filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix mapAttrs' trace fix fold isAttrs;
|
||||
in rec {
|
||||
mapModules' = dir: fn: dirfn:
|
||||
filterAttrs
|
||||
(name: type: type != null && !(hasPrefix "_" name))
|
||||
(mapAttrs'
|
||||
(name: type:
|
||||
let path = "${toString dir}/${name}"; in
|
||||
if type == "directory"
|
||||
then nameValuePair name (dirfn path)
|
||||
else if
|
||||
type == "regular" &&
|
||||
name != "default.nix" &&
|
||||
hasSuffix ".nix" name
|
||||
then nameValuePair (removeSuffix ".nix" name) (fn path)
|
||||
else nameValuePair "" null
|
||||
)
|
||||
(readDir dir));
|
||||
|
||||
mapModules = dir: fn: mapModules' dir fn (path: if pathExists "${path}/default.nix" then fn path else null);
|
||||
mapModulesRec = dir: fn: mapModules' dir fn (path: mapModulesRec path fn);
|
||||
mapModulesRec' = dir: fn: fix (f: attrs: fold (x: xs: (if isAttrs x then f x else [x]) ++ xs) [] (attrValues attrs)) (mapModulesRec dir fn);
|
||||
}
|
21
lib/nixos.nix
Normal file
21
lib/nixos.nix
Normal file
|
@ -0,0 +1,21 @@
|
|||
{ inputs, lib, pkgs, ... }:
|
||||
|
||||
with lib;
|
||||
{
|
||||
mkHost = path: attrs@{ system, ... }:
|
||||
nixosSystem {
|
||||
inherit system;
|
||||
specialArgs = { inherit lib inputs system; };
|
||||
modules = [
|
||||
{
|
||||
nixpkgs.pkgs = pkgs;
|
||||
networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path));
|
||||
}
|
||||
(filterAttrs (n: v: !elem n [ "system" ]) attrs)
|
||||
|
||||
../.
|
||||
|
||||
(import path)
|
||||
];
|
||||
};
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue