forked from fabian/nix_config
trivionomicon/flake: rewrite broken implementation of mkSystemFlake
This commit is contained in:
parent
111d3dabf2
commit
bf39923f9c
1 changed files with 113 additions and 92 deletions
111
flake.nix
111
flake.nix
|
@ -16,15 +16,24 @@
|
|||
"${namespace}" = builtins.removeAttrs overlayPkgs ["override"];
|
||||
}
|
||||
// (overlayPkgs.override or {});
|
||||
|
||||
doctrineNoPkgs = self.lib.mkDoctrine {
|
||||
lib = nixpkgs.lib;
|
||||
pkgs = null;
|
||||
};
|
||||
in
|
||||
flake-utils.lib.eachDefaultSystem (system: {
|
||||
formatter = (import nixpkgs {inherit system;}).alejandra;
|
||||
flake-utils.lib.eachDefaultSystem (system: let
|
||||
pkgs = import nixpkgs {inherit system;};
|
||||
in {
|
||||
formatter = pkgs.alejandra;
|
||||
|
||||
packages =
|
||||
(import nixpkgs {
|
||||
inherit system;
|
||||
overlays = [(mapOverlayOverride "local" (import ./pkgs))];
|
||||
}).local;
|
||||
overlays = [(mapOverlayOverride doctrineNoPkgs.prefix (import ./pkgs))];
|
||||
}).${
|
||||
doctrineNoPkgs.prefix
|
||||
};
|
||||
})
|
||||
// {
|
||||
templates = let
|
||||
|
@ -39,33 +48,37 @@
|
|||
};
|
||||
|
||||
overlays = let
|
||||
overlay = mapOverlayOverride "trivium" (import ./pkgs);
|
||||
overlay = mapOverlayOverride doctrineNoPkgs.prefix (import ./pkgs);
|
||||
in {
|
||||
default = overlay;
|
||||
trivium = overlay;
|
||||
${doctrineNoPkgs.prefix} = overlay;
|
||||
};
|
||||
|
||||
homeManagerModules.default = ./modules;
|
||||
nixosModules.default = ./modules;
|
||||
|
||||
lib = {
|
||||
mkDoctrine = import ./doctrine;
|
||||
|
||||
mkSystemFlake = {
|
||||
flakes,
|
||||
system,
|
||||
doctrinePrefix ? null,
|
||||
formatter ? "alejandra",
|
||||
localOverlayPath ? /. + "${flakes.self}" + /pkgs,
|
||||
nixpkgsConfigPath ? localOverlayPath + /config,
|
||||
nixosSourcePath ? /. + "${flakes.self}" + /sys,
|
||||
nixosPlatformsPath ?
|
||||
if nixosSourcePath != null
|
||||
then nixosSourcePath + /platform
|
||||
else null,
|
||||
hmSourcePath ? /. + "${flakes.self}" + /home,
|
||||
hmPlatformsPath ?
|
||||
if hmSourcePath != null
|
||||
then hmSourcePath + /platform
|
||||
else null,
|
||||
paths ? {},
|
||||
}: let
|
||||
mkDoctrine = args:
|
||||
self.lib.mkDoctrine
|
||||
(args
|
||||
// optionalAttrs (doctrinePrefix != null) {
|
||||
prefix = doctrinePrefix;
|
||||
});
|
||||
|
||||
doctrineNoPkgs = mkDoctrine {
|
||||
lib = nixpkgs.lib;
|
||||
pkgs = null;
|
||||
};
|
||||
|
||||
optionalFlake = name:
|
||||
if flakes ? "${name}"
|
||||
then flakes.${name}
|
||||
|
@ -74,7 +87,7 @@
|
|||
requireFlake = name:
|
||||
if flakes ? "${name}"
|
||||
then flakes.${name}
|
||||
else throw "Required flake input '${name}' is required but was not provided";
|
||||
else throw "Required flake input '${name}' is missing";
|
||||
|
||||
nur = optionalFlake "nur";
|
||||
nixpkgs = requireFlake "nixpkgs";
|
||||
|
@ -85,13 +98,21 @@
|
|||
then requireFlake "home-manager"
|
||||
else null;
|
||||
|
||||
pathFromSelf = path: builtins.toPath "${flakes.self}" + "/${path}";
|
||||
|
||||
localOverlayPath = pathFromSelf paths.localOverlay;
|
||||
nixpkgsConfigPath = pathFromSelf paths.nixpkgsConfig;
|
||||
nixosSourcePath = pathFromSelf paths.nixosSource;
|
||||
nixosPlatformsPath = pathFromSelf paths.nixosPlatforms;
|
||||
hmSourcePath = pathFromSelf paths.hmSource;
|
||||
hmPlatformsPath = pathFromSelf paths.hmPlatforms;
|
||||
|
||||
pkgs = importPkgs nixpkgs;
|
||||
|
||||
importPkgs = flake:
|
||||
import flake ({
|
||||
inherit system;
|
||||
|
||||
config = import ./pkgs/config nixpkgs.lib;
|
||||
overlays = let
|
||||
conditions = [
|
||||
{
|
||||
|
@ -100,7 +121,7 @@
|
|||
}
|
||||
# NB: Preserve the relative order
|
||||
{
|
||||
overlay = self.overlays.trivium;
|
||||
overlay = self.overlays.default;
|
||||
condition = true;
|
||||
}
|
||||
{
|
||||
|
@ -111,17 +132,15 @@
|
|||
in
|
||||
builtins.map (cond: cond.overlay) (builtins.filter (cond: cond.condition) conditions);
|
||||
}
|
||||
// (
|
||||
if nixpkgsConfigPath != null
|
||||
then {
|
||||
// optionalAttrs (paths ? nixpkgsConfig) {
|
||||
config = import nixpkgsConfigPath {inherit (nixpkgs) lib;};
|
||||
}
|
||||
else {}
|
||||
));
|
||||
});
|
||||
|
||||
inherit (pkgs.trivium.lib) importAll;
|
||||
inherit (pkgs) lib;
|
||||
inherit (nixpkgs.lib) optionalAttrs; # Prevents infinite recursion
|
||||
inherit (doctrineNoPkgs) prefix;
|
||||
inherit (doctrineNoPkgs.lib) importAll;
|
||||
in
|
||||
with pkgs.lib;
|
||||
{
|
||||
formatter.${system} =
|
||||
if formatter == "alejandra"
|
||||
|
@ -130,27 +149,32 @@
|
|||
then pkgs.nixpkgs-fmt
|
||||
else throw "Unknown formatter: '${formatter}'";
|
||||
|
||||
packages.${system} = pkgs.local;
|
||||
packages.${system} = pkgs.${prefix};
|
||||
|
||||
overlays.default = final: prev: let
|
||||
overlay =
|
||||
if localOverlayPath != null
|
||||
if paths ? localOverlay
|
||||
then import localOverlayPath
|
||||
else (final: prev: {});
|
||||
in
|
||||
mapOverlayOverride "local" overlay final prev
|
||||
mapOverlayOverride prefix overlay final prev
|
||||
// optionalAttrs (unstable != null) {
|
||||
unstable = importPkgs unstable;
|
||||
};
|
||||
}
|
||||
// optionalAttrs (nixosSourcePath != null) {
|
||||
// optionalAttrs (paths ? nixosSource) {
|
||||
nixosConfigurations = let
|
||||
nixosSystem = {modules}:
|
||||
makeOverridable nixpkgs.lib.nixosSystem {
|
||||
lib.makeOverridable nixpkgs.lib.nixosSystem {
|
||||
inherit modules pkgs system;
|
||||
|
||||
specialArgs = {
|
||||
inherit flakes;
|
||||
|
||||
doctrine = mkDoctrine {
|
||||
inherit pkgs;
|
||||
namespace = "sys";
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
|
@ -163,34 +187,31 @@
|
|||
];
|
||||
};
|
||||
in
|
||||
mapAttrs (_: hostConfig) (importAll {root = nixosPlatformsPath;});
|
||||
lib.mapAttrs (_: hostConfig) (importAll {root = nixosPlatformsPath;});
|
||||
}
|
||||
// optionalAttrs (hmSourcePath != null) {
|
||||
// optionalAttrs (paths ? hmSource) {
|
||||
homeConfigurations = let
|
||||
registry = {...}: {
|
||||
config.nix.registry =
|
||||
mapAttrs
|
||||
(_: value: {flake = value;})
|
||||
flakes;
|
||||
};
|
||||
|
||||
home = name: platform:
|
||||
home-manager.lib.homeManagerConfiguration {
|
||||
inherit pkgs;
|
||||
|
||||
extraSpecialArgs = {
|
||||
inherit flakes;
|
||||
|
||||
doctrine = mkDoctrine {
|
||||
inherit pkgs;
|
||||
namespace = "hm";
|
||||
};
|
||||
};
|
||||
|
||||
modules = [
|
||||
self.homeManagerModules.default
|
||||
hmSourcePath
|
||||
platform
|
||||
registry
|
||||
];
|
||||
};
|
||||
in
|
||||
mapAttrs home (importAll {root = hmPlatformsPath;});
|
||||
lib.mapAttrs home (importAll {root = hmPlatformsPath;});
|
||||
};
|
||||
};
|
||||
};
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue