Restructured glue
This commit is contained in:
parent
e134b3db6e
commit
4a644607c6
12
flake.lock
generated
12
flake.lock
generated
@ -34,17 +34,6 @@
|
|||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"glue": {
|
|
||||||
"locked": {
|
|
||||||
"path": "./glue",
|
|
||||||
"type": "path"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"path": "./glue",
|
|
||||||
"type": "path"
|
|
||||||
},
|
|
||||||
"parent": []
|
|
||||||
},
|
|
||||||
"home-manager": {
|
"home-manager": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"nixpkgs": [
|
"nixpkgs": [
|
||||||
@ -125,7 +114,6 @@
|
|||||||
},
|
},
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"glue": "glue",
|
|
||||||
"home-manager": "home-manager",
|
"home-manager": "home-manager",
|
||||||
"nix-minecraft": "nix-minecraft",
|
"nix-minecraft": "nix-minecraft",
|
||||||
"nix-modpack": "nix-modpack",
|
"nix-modpack": "nix-modpack",
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
description = "System configuration for NixOS";
|
description = "System configuration for NixOS";
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
glue.url = "./glue";
|
|
||||||
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||||
home-manager.url = "github:nix-community/home-manager";
|
home-manager.url = "github:nix-community/home-manager";
|
||||||
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
home-manager.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
@ -12,5 +11,5 @@
|
|||||||
nix-modpack.inputs.nixpkgs.follows = "nixpkgs";
|
nix-modpack.inputs.nixpkgs.follows = "nixpkgs";
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = inputs: inputs.glue inputs;
|
outputs = inputs: import ./glue inputs;
|
||||||
}
|
}
|
||||||
|
167
glue/default.nix
Normal file
167
glue/default.nix
Normal file
@ -0,0 +1,167 @@
|
|||||||
|
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);
|
||||||
|
|
||||||
|
eachSystem = fn: lib.genAttrs lib.systems.flakeExposed 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";
|
||||||
|
inputNixosModules = lib.map (flake: flake.outputs.nixosModules.default) (
|
||||||
|
lib.filter (flake: lib.hasAttrByPath [ "outputs" "nixosModules" "default" ] flake) (
|
||||||
|
lib.attrValues inputs
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
homeModules = collectModules "${flake}/modules/home";
|
||||||
|
inputHomeModules = lib.map (flake: flake.outputs.homeManagerModules.default) (
|
||||||
|
lib.filter (flake: lib.hasAttrByPath [ "outputs" "homeManagerModules" "default" ] flake) (
|
||||||
|
lib.attrValues inputs
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
inputOverlays = lib.map (flake: flake.outputs.overlays.default) (
|
||||||
|
lib.filter (flake: lib.hasAttrByPath [ "outputs" "overlays" "default" ] flake) (
|
||||||
|
lib.attrValues inputs
|
||||||
|
)
|
||||||
|
);
|
||||||
|
|
||||||
|
overlayModule =
|
||||||
|
{ ... }:
|
||||||
|
{
|
||||||
|
nixpkgs.overlays = [ overlay ] ++ inputOverlays;
|
||||||
|
};
|
||||||
|
|
||||||
|
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 ++ inputHomeModules;
|
||||||
|
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
|
||||||
|
]
|
||||||
|
++ nixosModules
|
||||||
|
++ inputNixosModules;
|
||||||
|
}
|
||||||
|
) (lib.attrsets.filterAttrs (name: entry: entry.type == "directory") attrs)
|
||||||
|
);
|
||||||
|
|
||||||
|
in
|
||||||
|
{
|
||||||
|
inherit packages nixosConfigurations overlay;
|
||||||
|
overlays.default = overlay;
|
||||||
|
}
|
@ -1,14 +0,0 @@
|
|||||||
{
|
|
||||||
description = "Some glue";
|
|
||||||
|
|
||||||
inputs = { };
|
|
||||||
|
|
||||||
outputs =
|
|
||||||
inputs:
|
|
||||||
let
|
|
||||||
glue = import ./lib { inherit inputs; };
|
|
||||||
in
|
|
||||||
{
|
|
||||||
__functor = _: glue;
|
|
||||||
};
|
|
||||||
}
|
|
@ -1,173 +0,0 @@
|
|||||||
{ ... }:
|
|
||||||
|
|
||||||
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);
|
|
||||||
|
|
||||||
eachSystem = fn: lib.genAttrs lib.systems.flakeExposed 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";
|
|
||||||
inputNixosModules = lib.map (flake: flake.outputs.nixosModules.default) (
|
|
||||||
lib.filter (flake: lib.hasAttrByPath [ "outputs" "nixosModules" "default" ] flake) (
|
|
||||||
lib.attrValues inputs
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
homeModules = collectModules "${flake}/modules/home";
|
|
||||||
inputHomeModules = lib.map (flake: flake.outputs.homeManagerModules.default) (
|
|
||||||
lib.filter (flake: lib.hasAttrByPath [ "outputs" "homeManagerModules" "default" ] flake) (
|
|
||||||
lib.attrValues inputs
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
inputOverlays = lib.map (flake: flake.outputs.overlays.default) (
|
|
||||||
lib.filter (flake: lib.hasAttrByPath [ "outputs" "overlays" "default" ] flake) (
|
|
||||||
lib.attrValues inputs
|
|
||||||
)
|
|
||||||
);
|
|
||||||
|
|
||||||
overlayModule =
|
|
||||||
{ ... }:
|
|
||||||
{
|
|
||||||
nixpkgs.overlays = [ overlay ] ++ inputOverlays;
|
|
||||||
};
|
|
||||||
|
|
||||||
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 ++ inputHomeModules;
|
|
||||||
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
|
|
||||||
]
|
|
||||||
++ nixosModules
|
|
||||||
++ inputNixosModules;
|
|
||||||
}
|
|
||||||
) (lib.attrsets.filterAttrs (name: entry: entry.type == "directory") attrs)
|
|
||||||
);
|
|
||||||
|
|
||||||
in
|
|
||||||
{
|
|
||||||
inherit packages nixosConfigurations;
|
|
||||||
overlays.default = overlay;
|
|
||||||
};
|
|
||||||
in
|
|
||||||
mkGlue
|
|
Loading…
x
Reference in New Issue
Block a user