mirror of
https://github.com/kittywitch/nixfiles.git
synced 2026-02-09 04:19:19 -08:00
feat: lurching towards relative usability
This commit is contained in:
parent
a0fb7eb402
commit
961ec369ba
51 changed files with 1349 additions and 407 deletions
312
outputs.nix
312
outputs.nix
|
|
@ -1,138 +1,194 @@
|
|||
{ self, utils, nixpkgs, darwin, home-manager, ragenix, scalpel, mach-nix, arcexprs, ... }@inputs: let
|
||||
tree = (inputs.tree.tree {
|
||||
inherit inputs;
|
||||
folder = ./.;
|
||||
config = {
|
||||
"/" = {
|
||||
excludes = [
|
||||
"flake"
|
||||
"default"
|
||||
];
|
||||
};
|
||||
"system/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
"nixos/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = with (import (arcexprs + "/modules")).nixos; [
|
||||
base16
|
||||
base16-shared
|
||||
{
|
||||
utils,
|
||||
nixpkgs,
|
||||
darwin,
|
||||
home-manager,
|
||||
ragenix,
|
||||
scalpel,
|
||||
nix-index-database,
|
||||
arcexprs,
|
||||
...
|
||||
} @ inputs: let
|
||||
tree =
|
||||
(inputs.tree.tree {
|
||||
inherit inputs;
|
||||
folder = ./.;
|
||||
config = {
|
||||
"/" = {
|
||||
excludes = [
|
||||
"flake"
|
||||
"default"
|
||||
];
|
||||
};
|
||||
};
|
||||
"home/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = with (import (arcexprs + "/modules")).home-manager; [
|
||||
base16
|
||||
base16-shared
|
||||
];
|
||||
"darwin/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external = [
|
||||
home-manager.darwinModules.home-manager
|
||||
ragenix.nixosModules.age
|
||||
];
|
||||
};
|
||||
};
|
||||
"system/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
};
|
||||
};
|
||||
"nixos/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external =
|
||||
[
|
||||
nix-index-database.nixosModules.nix-index
|
||||
home-manager.nixosModules.home-manager
|
||||
ragenix.nixosModules.age
|
||||
]
|
||||
++ (with (import (arcexprs + "/modules")).nixos; [
|
||||
base16
|
||||
base16-shared
|
||||
]);
|
||||
};
|
||||
};
|
||||
"home/modules" = {
|
||||
functor = {
|
||||
enable = true;
|
||||
external =
|
||||
[
|
||||
nix-index-database.hmModules.nix-index
|
||||
]
|
||||
++ (with (import (arcexprs + "/modules")).home-manager; [
|
||||
base16
|
||||
base16-shared
|
||||
]);
|
||||
};
|
||||
};
|
||||
};
|
||||
};
|
||||
}).impure;
|
||||
lib = inputs.nixpkgs.lib;
|
||||
})
|
||||
.impure;
|
||||
inherit (inputs.nixpkgs) lib;
|
||||
inherit (lib.lists) fold;
|
||||
inherit (lib.attrsets) mapAttrs recursiveUpdate;
|
||||
recursiveMergeAttrs = listOfAttrsets: fold (attrset: acc: recursiveUpdate attrset acc) {} listOfAttrsets;
|
||||
in recursiveMergeAttrs [
|
||||
(utils.lib.mkFlake {
|
||||
inherit self inputs;
|
||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" ];
|
||||
channelsConfig.allowUnfree = true;
|
||||
|
||||
hostDefaults = {
|
||||
system = "x86_64-linux";
|
||||
modules = [
|
||||
tree.system.modules
|
||||
inherit (lib.attrsets) mapAttrs mapAttrsToList recursiveUpdate;
|
||||
inherit (lib.strings) toLower;
|
||||
inherit (lib.options) mkOption;
|
||||
inherit (lib.types) str listOf attrs unspecified;
|
||||
inherit (lib.modules) evalModules;
|
||||
recursiveMergeAttrs = fold recursiveUpdate {};
|
||||
defaultSpecialArgs = {
|
||||
inherit inputs tree;
|
||||
};
|
||||
hostModule = {
|
||||
config,
|
||||
machine,
|
||||
...
|
||||
}: {
|
||||
options = {
|
||||
arch = mkOption {
|
||||
description = "Processor architecture of the host";
|
||||
type = str;
|
||||
default = "x86_64";
|
||||
};
|
||||
type = mkOption {
|
||||
description = "Operating system type of the host";
|
||||
type = str;
|
||||
default = "NixOS";
|
||||
};
|
||||
folder = mkOption {
|
||||
type = str;
|
||||
internal = true;
|
||||
};
|
||||
system = mkOption {
|
||||
type = str;
|
||||
internal = true;
|
||||
};
|
||||
modules = mkOption {
|
||||
type = listOf unspecified;
|
||||
};
|
||||
specialArgs = mkOption {
|
||||
type = attrs;
|
||||
internal = true;
|
||||
};
|
||||
builder = mkOption {
|
||||
type = unspecified;
|
||||
internal = true;
|
||||
};
|
||||
};
|
||||
config = {
|
||||
system = let
|
||||
kernel =
|
||||
{
|
||||
nixos = "linux";
|
||||
macos = "darwin";
|
||||
darwin = "darwin";
|
||||
linux = "linux";
|
||||
}
|
||||
.${toLower config.type};
|
||||
in "${config.arch}-${kernel}";
|
||||
folder =
|
||||
{
|
||||
nixos = "nixos";
|
||||
macos = "darwin";
|
||||
darwin = "darwin";
|
||||
linux = "linux";
|
||||
}
|
||||
.${toLower config.type};
|
||||
modules = with tree; [
|
||||
tree.${config.folder}.modules
|
||||
home.system
|
||||
];
|
||||
extraArgs = {
|
||||
inherit inputs tree;
|
||||
};
|
||||
builder =
|
||||
{
|
||||
nixos = nixpkgs.lib.nixosSystem;
|
||||
darwin = darwin.lib.darwinSystem;
|
||||
macos = darwin.lib.darwinSystem;
|
||||
}
|
||||
.${toLower config.type};
|
||||
specialArgs = {inherit machine;} // defaultSpecialArgs;
|
||||
};
|
||||
|
||||
hosts = let
|
||||
outputForSystem = system: {
|
||||
"x86_64-linux" = "nixosConfigurations";
|
||||
"aarch64-darwin" = "darwinConfigurations";
|
||||
}.${system};
|
||||
builderForSystem = system: {
|
||||
"x86_64-linux" = nixpkgs.lib.nixosSystem;
|
||||
"aarch64-darwin" = darwin.lib.darwinSystem;
|
||||
}.${system};
|
||||
modulesForSystem = system: {
|
||||
"x86_64-linux" = [
|
||||
home-manager.nixosModules.home-manager
|
||||
ragenix.nixosModules.age
|
||||
tree.nixos.modules
|
||||
];
|
||||
"aarch64-darwin" = [
|
||||
home-manager.darwinModules.home-manager
|
||||
ragenix.nixosModules.age
|
||||
tree.darwin.modules
|
||||
];
|
||||
}.${system};
|
||||
mapSystem = system: name: path: {
|
||||
inherit system;
|
||||
output = outputForSystem system;
|
||||
builder = builderForSystem system;
|
||||
modules = (modulesForSystem system) ++ [
|
||||
path
|
||||
];
|
||||
extraArgs = {
|
||||
};
|
||||
hostConfigs = mapAttrs (name: path:
|
||||
evalModules {
|
||||
modules = [
|
||||
hostModule
|
||||
path
|
||||
];
|
||||
specialArgs =
|
||||
{
|
||||
machine = name;
|
||||
};
|
||||
};
|
||||
in mapAttrs (mapSystem "x86_64-linux") tree.nixos.systems
|
||||
// mapAttrs (mapSystem "aarch64-darwin") tree.darwin.systems;
|
||||
|
||||
outputsBuilder = channels: {
|
||||
nixosConfigurations = mapAttrs(_: sys: sys.extendModules {
|
||||
modules = [ scalpel.nixosModule ];
|
||||
specialArgs = {
|
||||
prev = sys;
|
||||
};
|
||||
}) self.nixosConfigurations;
|
||||
|
||||
homeManagerConfigurations = mapAttrs (name: path: home-manager.lib.homeManagerConfiguration {
|
||||
pkgs = channels.nixpkgs;
|
||||
extraSpecialArgs = {
|
||||
inherit channels inputs tree;
|
||||
machine = name;
|
||||
nixos = {};
|
||||
};
|
||||
modules = [
|
||||
tree.system.modules
|
||||
tree.home.common
|
||||
path
|
||||
];
|
||||
}) tree.home.profiles;
|
||||
|
||||
devShells = {
|
||||
rust = with channels.nixpkgs; mkShell {
|
||||
nativeBuildInputs = [
|
||||
cargo
|
||||
rustc
|
||||
rustfmt
|
||||
rustPackages.clippy
|
||||
rust-analyzer
|
||||
];
|
||||
RUST_SRC_PATH = rustPlatform.rustLibSrc;
|
||||
};
|
||||
};
|
||||
inherit tree;
|
||||
};
|
||||
})
|
||||
(utils.lib.eachDefaultSystem (system: {
|
||||
devShells.python = nixpkgs.legacyPackages."${system}".mkShell {
|
||||
buildInputs = let
|
||||
pythonWithPkgs = mach-nix.lib."${system}".mkPython {
|
||||
ignoreDataOutdated = true;
|
||||
python = "python310";
|
||||
}; in [ pythonWithPkgs ];
|
||||
}
|
||||
// defaultSpecialArgs;
|
||||
})
|
||||
tree.systems;
|
||||
processHost = name: cfg: let
|
||||
host = cfg.config;
|
||||
in {
|
||||
"${host.folder}Configurations".${name} = let
|
||||
hostConfig = host.builder {
|
||||
inherit (host) system modules specialArgs;
|
||||
};
|
||||
in
|
||||
if host.folder == "nixos"
|
||||
then
|
||||
hostConfig.extendModules {
|
||||
modules = [scalpel.nixosModule];
|
||||
specialArgs = {
|
||||
prev = hostConfig;
|
||||
};
|
||||
}
|
||||
else hostConfig;
|
||||
};
|
||||
in
|
||||
recursiveMergeAttrs (mapAttrsToList processHost hostConfigs)
|
||||
// {
|
||||
inherit inputs tree hostConfigs;
|
||||
}
|
||||
// (utils.lib.eachDefaultSystem (system: {
|
||||
devShells = let
|
||||
shells = mapAttrs (_: path:
|
||||
import path rec {
|
||||
inherit tree inputs system;
|
||||
pkgs = nixpkgs.legacyPackages.${system};
|
||||
inherit (nixpkgs) lib;
|
||||
})
|
||||
tree.shells;
|
||||
in shells // { default = shells.repo; };
|
||||
}))
|
||||
]
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue