Progress
This commit is contained in:
1 parent
760815da50
commit
5e23488cae
42 files changed
+2205
-144
No files matched your search
@@ -0,0 +1,14 @@
|
||||
{
|
||||
description = "Some glue";
|
||||
|
||||
inputs = { };
|
||||
|
||||
outputs =
|
||||
inputs:
|
||||
let
|
||||
glue = import ./lib { inherit inputs; };
|
||||
in
|
||||
{
|
||||
__functor = _: glue;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,167 @@
|
||||
{ ... }:
|
||||
|
||||
let
|
||||
mkGlue =
|
||||
{
|
||||
inputs,
|
||||
...
|
||||
}:
|
||||
let
|
||||
flake = inputs.self;
|
||||
nixpkgs = inputs.nixpkgs;
|
||||
lib = nixpkgs.lib;
|
||||
|
||||
importDir =
|
||||
path: fn:
|
||||
let
|
||||
entries = builtins.readDir path;
|
||||
|
||||
# Get paths to directories
|
||||
dirs = lib.filterAttrs (_: type: type == "directory") entries;
|
||||
dirPaths = lib.mapAttrs (name: type: {
|
||||
path = "${path}/${name}";
|
||||
type = type;
|
||||
}) dirs;
|
||||
|
||||
# Get paths to nix files
|
||||
nixName = name: builtins.match "(.*)\\.nix" name;
|
||||
files = lib.filterAttrs (name: type: (type != "directory") && ((nixName name) != null)) entries;
|
||||
filePaths = lib.mapAttrs' (name: type: {
|
||||
name = builtins.head (nixName name);
|
||||
value = {
|
||||
path = "${path}/${name}";
|
||||
type = type;
|
||||
};
|
||||
}) files;
|
||||
|
||||
combined = dirPaths // filePaths;
|
||||
in
|
||||
fn (lib.optionalAttrs (builtins.pathExists path) combined);
|
||||
|
||||
# Split out into getNixFiles, getNixFilesRecursive, getDirs
|
||||
importDirRecursive =
|
||||
path: fn:
|
||||
let
|
||||
entries = importDir path lib.id;
|
||||
|
||||
# Dig down recursively
|
||||
dirs = lib.filterAttrs (_: entry: entry.type == "directory") entries;
|
||||
recursedEntries = lib.mapAttrs (name: entry: (importDirRecursive entry.path lib.id)) dirs;
|
||||
in
|
||||
fn (entries // recursedEntries);
|
||||
|
||||
systems = [
|
||||
"x86_64-linux"
|
||||
"aarch64-linux"
|
||||
];
|
||||
|
||||
eachSystem = fn: lib.genAttrs systems fn;
|
||||
|
||||
systemArgs = eachSystem (system: {
|
||||
pkgs = (
|
||||
import inputs.nixpkgs {
|
||||
inherit system;
|
||||
}
|
||||
);
|
||||
});
|
||||
|
||||
allPackages = importDir "${flake}/packages" (
|
||||
attrs:
|
||||
lib.mapAttrs (
|
||||
name: entry: (if entry.type == "directory" then "${entry.path}/default.nix" else entry.path)
|
||||
) attrs
|
||||
);
|
||||
|
||||
packages =
|
||||
let
|
||||
# TODO: Filter out packages that are not supported on the platform?
|
||||
mkPackages =
|
||||
system:
|
||||
let
|
||||
args = systemArgs."${system}";
|
||||
pkgs = args.pkgs;
|
||||
in
|
||||
lib.mapAttrs (name: package: pkgs.callPackage package { }) allPackages;
|
||||
in
|
||||
eachSystem mkPackages;
|
||||
|
||||
overlay = final: prev: (lib.mapAttrs (name: package: prev.callPackage package { }) allPackages);
|
||||
|
||||
collectEntries =
|
||||
attrs:
|
||||
lib.attrsets.collect (
|
||||
entry: (lib.isAttrs entry) && (lib.hasAttr "path" entry) && (lib.hasAttr "type" entry)
|
||||
) attrs;
|
||||
|
||||
collectModules =
|
||||
path:
|
||||
importDirRecursive path (
|
||||
attrs:
|
||||
map (entry: if entry.type == "directory" then entry.path + "/default.nix" else entry.path) (
|
||||
collectEntries attrs
|
||||
)
|
||||
);
|
||||
|
||||
nixosModules = collectModules "${flake}/modules/nixos";
|
||||
|
||||
homeModules = collectModules "${flake}/modules/home";
|
||||
|
||||
overlayModule =
|
||||
{ ... }:
|
||||
{
|
||||
nixpkgs.overlays = [ overlay ];
|
||||
};
|
||||
|
||||
homeManager = inputs.home-manager.nixosModules.home-manager;
|
||||
|
||||
nixosConfigurations = importDir "${flake}/hosts" (
|
||||
attrs:
|
||||
lib.mapAttrs (
|
||||
name: entry:
|
||||
lib.nixosSystem {
|
||||
specialArgs = {
|
||||
inherit inputs;
|
||||
};
|
||||
modules =
|
||||
let
|
||||
systemPath = "${entry.path}/configuration.nix";
|
||||
|
||||
userEntries = importDir "${entry.path}/users" lib.id;
|
||||
|
||||
usersConfiguration = lib.mapAttrs (name: entry: {
|
||||
isNormalUser = true;
|
||||
group = name;
|
||||
}) userEntries;
|
||||
groupsConfiguration = lib.mapAttrs (name: entry: {
|
||||
}) userEntries;
|
||||
homesConfiguration = lib.mapAttrs (name: entry: entry.path) userEntries;
|
||||
|
||||
usersModule =
|
||||
{ ... }:
|
||||
{
|
||||
home-manager.sharedModules = homeModules;
|
||||
home-manager.useUserPackages = false; # TODO: See if this should be changed to true?
|
||||
home-manager.useGlobalPkgs = true;
|
||||
home-manager.users = homesConfiguration;
|
||||
users.users = usersConfiguration;
|
||||
users.groups = groupsConfiguration;
|
||||
};
|
||||
in
|
||||
[
|
||||
systemPath
|
||||
overlayModule
|
||||
usersModule
|
||||
homeManager
|
||||
]
|
||||
++ nixosModules;
|
||||
}
|
||||
) (lib.attrsets.filterAttrs (name: entry: entry.type == "directory") attrs)
|
||||
);
|
||||
|
||||
in
|
||||
{
|
||||
inherit packages nixosConfigurations;
|
||||
overlays.default = overlay;
|
||||
};
|
||||
in
|
||||
mkGlue
|
||||
Reference in new issue
Block a user