clan template: reduce autogenerate code to a minimum
This commit is contained in:
28
lib/build-clan/default.nix
Normal file
28
lib/build-clan/default.nix
Normal file
@@ -0,0 +1,28 @@
|
||||
{ nixpkgs, clan, lib }:
|
||||
{ directory # The directory containing the machines subdirectory
|
||||
, specialArgs ? { } # Extra arguments to pass to nixosSystem i.e. useful to make self available
|
||||
, machines ? { } # allows to include machine-specific modules i.e. machines.${name} = { ... }
|
||||
}:
|
||||
let
|
||||
machinesDirs =
|
||||
if builtins.pathExists (directory + /machines)
|
||||
then builtins.readDir (directory + /machines)
|
||||
else { };
|
||||
|
||||
machineSettings = machineName:
|
||||
if builtins.pathExists (directory + /machines/${machineName}/settings.json)
|
||||
then builtins.fromJSON (builtins.readFile (directory + /machines/${machineName}/settings.json))
|
||||
else { };
|
||||
|
||||
nixosConfigurations = lib.mapAttrs
|
||||
(name: _mod:
|
||||
nixpkgs.lib.nixosSystem {
|
||||
modules = [
|
||||
(machineSettings name)
|
||||
(machines.${name} or { })
|
||||
] ++ lib.attrValues clan.clanModules;
|
||||
specialArgs = specialArgs;
|
||||
})
|
||||
machinesDirs;
|
||||
in
|
||||
nixosConfigurations
|
||||
@@ -1,4 +1,4 @@
|
||||
{ lib, ... }:
|
||||
{ lib, clan, nixpkgs, ... }:
|
||||
{
|
||||
findNixFiles = folder:
|
||||
lib.mapAttrs'
|
||||
@@ -13,4 +13,6 @@
|
||||
(builtins.readDir folder);
|
||||
|
||||
jsonschema = import ./jsonschema { inherit lib; };
|
||||
|
||||
buildClan = import ./build-clan { inherit lib clan nixpkgs; };
|
||||
}
|
||||
|
||||
@@ -1,8 +1,12 @@
|
||||
{ lib
|
||||
, inputs
|
||||
, ...
|
||||
}: {
|
||||
imports = [
|
||||
./jsonschema/flake-module.nix
|
||||
];
|
||||
flake.lib = import ./default.nix { inherit lib; };
|
||||
flake.lib = import ./default.nix {
|
||||
inherit lib;
|
||||
inherit (inputs) clan nixpkgs;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user