Format using nixfmt rfc style
This commit is contained in:
parent
d07a224bbc
commit
f6be5f8b80
37 changed files with 934 additions and 612 deletions
|
|
@ -1,26 +1,22 @@
|
|||
{ lib, ... }:
|
||||
|
||||
with builtins;
|
||||
with lib;
|
||||
rec {
|
||||
# attrsToList
|
||||
attrsToList = attrs:
|
||||
mapAttrsToList (name: value: { inherit name value; }) attrs;
|
||||
attrsToList = attrs: lib.mapAttrsToList (name: value: { inherit name value; }) attrs;
|
||||
|
||||
# mapFilterAttrs ::
|
||||
# (name -> value -> bool)
|
||||
# (name -> value -> { name = any; value = any; })
|
||||
# attrs
|
||||
mapFilterAttrs = pred: f: attrs: filterAttrs pred (mapAttrs' f attrs);
|
||||
mapFilterAttrs =
|
||||
pred: f: attrs:
|
||||
lib.filterAttrs pred (lib.mapAttrs' f attrs);
|
||||
|
||||
# Generate an attribute set by mapping a function over a list of values.
|
||||
genAttrs' = values: f: listToAttrs (map f values);
|
||||
genAttrs' = values: f: lib.listToAttrs (map f values);
|
||||
|
||||
# anyAttrs :: (name -> value -> bool) attrs
|
||||
anyAttrs = pred: attrs:
|
||||
any (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
anyAttrs = pred: attrs: lib.any (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
|
||||
# countAttrs :: (name -> value -> bool) attrs
|
||||
countAttrs = pred: attrs:
|
||||
count (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
countAttrs = pred: attrs: lib.count (attr: pred attr.name attr.value) (attrsToList attrs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,9 @@
|
|||
{ inputs, lib, pkgs, ... }:
|
||||
{
|
||||
inputs,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
let
|
||||
inherit (lib) makeExtensible attrValues foldr;
|
||||
|
|
@ -6,13 +11,25 @@ let
|
|||
|
||||
modules = import ./modules.nix {
|
||||
inherit lib;
|
||||
self.attrs = import ./attrs.nix { inherit lib; self = { }; };
|
||||
self.attrs = import ./attrs.nix {
|
||||
inherit lib;
|
||||
self = { };
|
||||
};
|
||||
};
|
||||
|
||||
mylib = makeExtensible (self:
|
||||
with self; mapModules ./.
|
||||
(file: import file { inherit self lib pkgs inputs; }));
|
||||
mylib = makeExtensible (
|
||||
self:
|
||||
mapModules ./. (
|
||||
file:
|
||||
import file {
|
||||
inherit
|
||||
self
|
||||
lib
|
||||
pkgs
|
||||
inputs
|
||||
;
|
||||
}
|
||||
)
|
||||
);
|
||||
in
|
||||
mylib.extend
|
||||
(self: super:
|
||||
foldr (a: b: a // b) { } (attrValues super))
|
||||
mylib.extend (self: super: foldr (a: b: a // b) { } (attrValues super))
|
||||
|
|
|
|||
|
|
@ -1,52 +1,62 @@
|
|||
{ self, lib, ... }:
|
||||
|
||||
let
|
||||
inherit (builtins) attrValues readDir pathExists concatLists;
|
||||
inherit (lib) id mapAttrsToList filterAttrs hasPrefix hasSuffix nameValuePair removeSuffix;
|
||||
inherit (builtins)
|
||||
attrValues
|
||||
readDir
|
||||
pathExists
|
||||
concatLists
|
||||
;
|
||||
inherit (lib)
|
||||
id
|
||||
mapAttrsToList
|
||||
filterAttrs
|
||||
hasPrefix
|
||||
hasSuffix
|
||||
nameValuePair
|
||||
removeSuffix
|
||||
;
|
||||
inherit (self.attrs) mapFilterAttrs;
|
||||
in
|
||||
rec {
|
||||
mapModules = dir: fn:
|
||||
mapFilterAttrs
|
||||
(n: v:
|
||||
v != null &&
|
||||
!(hasPrefix "_" n))
|
||||
(n: v:
|
||||
let path = "${toString dir}/${n}"; in
|
||||
if v == "directory" && pathExists "${path}/default.nix"
|
||||
then nameValuePair n (fn path)
|
||||
else if v == "regular" &&
|
||||
n != "default.nix" &&
|
||||
hasSuffix ".nix" n
|
||||
then nameValuePair (removeSuffix ".nix" n) (fn path)
|
||||
else nameValuePair "" null)
|
||||
(readDir dir);
|
||||
mapModules =
|
||||
dir: fn:
|
||||
mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (
|
||||
n: v:
|
||||
let
|
||||
path = "${toString dir}/${n}";
|
||||
in
|
||||
if v == "directory" && pathExists "${path}/default.nix" then
|
||||
nameValuePair n (fn path)
|
||||
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n then
|
||||
nameValuePair (removeSuffix ".nix" n) (fn path)
|
||||
else
|
||||
nameValuePair "" null
|
||||
) (readDir dir);
|
||||
|
||||
mapModules' = dir: fn:
|
||||
attrValues (mapModules dir fn);
|
||||
mapModules' = dir: fn: attrValues (mapModules dir fn);
|
||||
|
||||
mapModulesRec = dir: fn:
|
||||
mapFilterAttrs
|
||||
(n: v:
|
||||
v != null &&
|
||||
!(hasPrefix "_" n))
|
||||
(n: v:
|
||||
let path = "${toString dir}/${n}"; in
|
||||
if v == "directory"
|
||||
then nameValuePair n (mapModulesRec path fn)
|
||||
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n
|
||||
then nameValuePair (removeSuffix ".nix" n) (fn path)
|
||||
else nameValuePair "" null)
|
||||
(readDir dir);
|
||||
mapModulesRec =
|
||||
dir: fn:
|
||||
mapFilterAttrs (n: v: v != null && !(hasPrefix "_" n)) (
|
||||
n: v:
|
||||
let
|
||||
path = "${toString dir}/${n}";
|
||||
in
|
||||
if v == "directory" then
|
||||
nameValuePair n (mapModulesRec path fn)
|
||||
else if v == "regular" && n != "default.nix" && hasSuffix ".nix" n then
|
||||
nameValuePair (removeSuffix ".nix" n) (fn path)
|
||||
else
|
||||
nameValuePair "" null
|
||||
) (readDir dir);
|
||||
|
||||
mapModulesRec' = dir: fn:
|
||||
mapModulesRec' =
|
||||
dir: fn:
|
||||
let
|
||||
dirs =
|
||||
mapAttrsToList
|
||||
(k: _: "${dir}/${k}")
|
||||
(filterAttrs
|
||||
(n: v: v == "directory" && !(hasPrefix "_" n))
|
||||
(readDir dir));
|
||||
dirs = mapAttrsToList (k: _: "${dir}/${k}") (
|
||||
filterAttrs (n: v: v == "directory" && !(hasPrefix "_" n)) (readDir dir)
|
||||
);
|
||||
files = attrValues (mapModules dir id);
|
||||
paths = files ++ concatLists (map (d: mapModulesRec' d id) dirs);
|
||||
in
|
||||
|
|
|
|||
|
|
@ -1,26 +1,42 @@
|
|||
{ inputs, lib, pkgs, ... }:
|
||||
{
|
||||
inputs,
|
||||
lib,
|
||||
pkgs,
|
||||
...
|
||||
}:
|
||||
|
||||
with lib;
|
||||
with lib.my;
|
||||
let sys = "x86_64-linux";
|
||||
in {
|
||||
mkHost = path: attrs @ { system ? sys, ... }:
|
||||
nixosSystem {
|
||||
let
|
||||
sys = "x86_64-linux";
|
||||
in
|
||||
rec {
|
||||
mkHost =
|
||||
path:
|
||||
attrs@{
|
||||
system ? sys,
|
||||
...
|
||||
}:
|
||||
lib.nixosSystem {
|
||||
inherit system;
|
||||
specialArgs = { inherit lib inputs system; };
|
||||
specialArgs = {
|
||||
inherit lib inputs system;
|
||||
};
|
||||
modules = [
|
||||
{
|
||||
nixpkgs.pkgs = pkgs;
|
||||
nix.registry.nixpkgs.flake = inputs.nixpkgs;
|
||||
networking.hostName = mkDefault (removeSuffix ".nix" (baseNameOf path));
|
||||
networking.hostName = lib.mkDefault (lib.removeSuffix ".nix" (baseNameOf path));
|
||||
}
|
||||
(filterAttrs (n: v: !elem n [ "system" ]) attrs)
|
||||
(lib.filterAttrs (n: v: !lib.elem n [ "system" ]) attrs)
|
||||
../common.nix
|
||||
(import path)
|
||||
];
|
||||
};
|
||||
|
||||
mapHosts = dir: attrs @ { system ? system, ... }:
|
||||
mapModules dir
|
||||
(hostPath: mkHost hostPath attrs);
|
||||
mapHosts =
|
||||
dir:
|
||||
attrs@{
|
||||
system ? system,
|
||||
...
|
||||
}:
|
||||
lib.my.mapModules dir (hostPath: mkHost hostPath attrs);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,16 +3,18 @@
|
|||
let
|
||||
inherit (lib) mkOption types;
|
||||
in
|
||||
rec {
|
||||
mkOpt = type: default:
|
||||
mkOption { inherit type default; };
|
||||
{
|
||||
mkOpt = type: default: mkOption { inherit type default; };
|
||||
|
||||
mkOpt' = type: default: description:
|
||||
mkOpt' =
|
||||
type: default: description:
|
||||
mkOption { inherit type default description; };
|
||||
|
||||
mkBoolOpt = default: mkOption {
|
||||
inherit default;
|
||||
type = types.bool;
|
||||
example = true;
|
||||
};
|
||||
mkBoolOpt =
|
||||
default:
|
||||
mkOption {
|
||||
inherit default;
|
||||
type = types.bool;
|
||||
example = true;
|
||||
};
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue