refactor(inputs): integrate mkDep into mkInput and improve mkHyprDep
All checks were successful
Discord / discord commits (push) Has been skipped

This commit is contained in:
matt1432 2025-01-25 14:17:53 -05:00
parent d89900c4be
commit 1981620f46
5 changed files with 74 additions and 73 deletions

View file

@ -1,6 +1,6 @@
{ {
inputs = let inputs = let
inherit (import ./inputs) mkDep mkInput extraInputs; inherit (import ./inputs) mkInput extraInputs;
mainInputs = { mainInputs = {
systems = mkInput { systems = mkInput {
@ -14,24 +14,24 @@
ref = "nixos-unstable-small"; ref = "nixos-unstable-small";
}; };
home-manager = mkDep { home-manager = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "home-manager"; repo = "home-manager";
}; };
nix-on-droid = mkDep { nix-on-droid = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "nix-on-droid"; repo = "nix-on-droid";
inputs.home-manager.follows = "home-manager"; inputs.home-manager.follows = "home-manager";
}; };
sops-nix = mkDep { sops-nix = mkInput {
owner = "Mic92"; owner = "Mic92";
repo = "sops-nix"; repo = "sops-nix";
}; };
secrets = mkDep { secrets = mkInput {
type = "git"; type = "git";
url = "ssh://git@git.nelim.org/matt1432/nixos-secrets"; url = "ssh://git@git.nelim.org/matt1432/nixos-secrets";

Binary file not shown.

BIN
flake.nix

Binary file not shown.

View file

@ -1,31 +1,31 @@
# TODO: add README # TODO: add README
let let
inherit (import ./lib.nix) mkDep mkInput mkHyprDep mkSrc; inherit (import ./lib.nix) mkInput mkHyprDep mkSrc;
inherit (builtins) listToAttrs map removeAttrs; inherit (builtins) listToAttrs map removeAttrs;
# Inputs # Inputs
nixTools = { nixTools = {
nix-fast-build = mkDep { nix-fast-build = mkInput {
owner = "Mic92"; owner = "Mic92";
repo = "nix-fast-build"; repo = "nix-fast-build";
}; };
nix-eval-jobs = mkDep { nix-eval-jobs = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "nix-eval-jobs"; repo = "nix-eval-jobs";
}; };
nix-index-db = mkDep { nix-index-db = mkInput {
owner = "Mic92"; owner = "Mic92";
repo = "nix-index-database"; repo = "nix-index-database";
}; };
nh = mkDep { nh = mkInput {
owner = "viperML"; owner = "viperML";
repo = "nh"; repo = "nh";
}; };
nurl = mkDep { nurl = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "nurl"; repo = "nurl";
}; };
@ -44,7 +44,7 @@ let
repo = "flake-parts"; repo = "flake-parts";
inputs.nixpkgs-lib.follows = "nixpkgs"; inputs.nixpkgs-lib.follows = "nixpkgs";
}; };
treefmt-nix = mkDep { treefmt-nix = mkInput {
owner = "numtide"; owner = "numtide";
repo = "treefmt-nix"; repo = "treefmt-nix";
}; };
@ -52,11 +52,11 @@ let
owner = "nix-community"; owner = "nix-community";
repo = "lib-aggregate"; repo = "lib-aggregate";
}; };
nix-github-actions = mkDep { nix-github-actions = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "nix-github-actions"; repo = "nix-github-actions";
}; };
pre-commit-hooks = mkDep { pre-commit-hooks = mkInput {
owner = "cachix"; owner = "cachix";
repo = "git-hooks.nix"; repo = "git-hooks.nix";
inputs.flake-compat.follows = "flake-compat"; inputs.flake-compat.follows = "flake-compat";
@ -64,55 +64,55 @@ let
}; };
overlays = { overlays = {
nixpkgs-wayland = mkDep { nixpkgs-wayland = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "nixpkgs-wayland"; repo = "nixpkgs-wayland";
}; };
nix-gaming = mkDep { nix-gaming = mkInput {
owner = "fufexan"; owner = "fufexan";
repo = "nix-gaming"; repo = "nix-gaming";
}; };
}; };
nvimInputs = { nvimInputs = {
nixd = mkDep { nixd = mkInput {
owner = "nix-community"; owner = "nix-community";
repo = "nixd"; repo = "nixd";
}; };
}; };
clusterInputs = { clusterInputs = {
pcsd = mkDep { pcsd = mkInput {
owner = "matt1432"; owner = "matt1432";
repo = "nixos-pcsd"; repo = "nixos-pcsd";
}; };
}; };
serviviInputs = { serviviInputs = {
minix = mkDep { minix = mkInput {
owner = "matt1432"; owner = "matt1432";
repo = "Minix"; repo = "Minix";
}; };
pr-tracker = mkDep { pr-tracker = mkInput {
owner = "matt1432"; owner = "matt1432";
repo = "pr-tracker"; repo = "pr-tracker";
}; };
}; };
nosInputs = { nosInputs = {
khepri = mkDep { khepri = mkInput {
owner = "matt1432"; owner = "matt1432";
repo = "khepri"; repo = "khepri";
}; };
jellyfin-flake = mkDep { jellyfin-flake = mkInput {
owner = "matt1432"; owner = "matt1432";
repo = "nixos-jellyfin"; repo = "nixos-jellyfin";
}; };
bazarr-bulk = mkDep { bazarr-bulk = mkInput {
owner = "mateoradman"; owner = "mateoradman";
repo = "bazarr-bulk"; repo = "bazarr-bulk";
}; };
@ -120,16 +120,9 @@ let
desktopInputs = { desktopInputs = {
hyprlandInputs = { hyprlandInputs = {
hyprutils = mkDep { hyprland = mkInput {
owner = "hyprwm";
repo = "hyprutils";
};
hyprland = mkDep {
owner = "hyprwm"; owner = "hyprwm";
repo = "Hyprland"; repo = "Hyprland";
inputs.hyprutils.follows = "hyprutils";
}; };
hyprland-plugins = mkHyprDep { hyprland-plugins = mkHyprDep {
@ -142,36 +135,29 @@ let
repo = "hyprgrass"; repo = "hyprgrass";
}; };
hyprpaper = mkDep { hyprpaper = mkHyprDep {
owner = "hyprwm"; owner = "hyprwm";
repo = "hyprpaper"; repo = "hyprpaper";
inputs = {
hyprgraphics.follows = "hyprland/hyprgraphics";
hyprlang.follows = "hyprland/hyprlang";
hyprutils.follows = "hyprland/hyprutils";
hyprwayland-scanner.follows = "hyprland/hyprwayland-scanner";
};
}; };
grim-hyprland = mkDep { grim-hyprland = mkInput {
owner = "eriedaberrie"; owner = "eriedaberrie";
repo = "grim-hyprland"; repo = "grim-hyprland";
}; };
nixcord = mkDep { nixcord = mkInput {
owner = "kaylorben"; owner = "kaylorben";
repo = "nixcord"; repo = "nixcord";
}; };
}; };
agsInputs = { agsInputs = {
astal = mkDep { astal = mkInput {
owner = "Aylur"; owner = "Aylur";
repo = "astal"; repo = "astal";
}; };
ags = mkDep { ags = mkInput {
owner = "Aylur"; owner = "Aylur";
repo = "ags"; repo = "ags";
@ -185,12 +171,12 @@ let
inputs.astal.follows = "astal"; inputs.astal.follows = "astal";
}; };
gtk-session-lock = mkDep { gtk-session-lock = mkInput {
owner = "Cu3PO42"; owner = "Cu3PO42";
repo = "gtk-session-lock"; repo = "gtk-session-lock";
}; };
virtualkeyboard-adapter = mkDep { virtualkeyboard-adapter = mkInput {
owner = "horriblename"; owner = "horriblename";
repo = "fcitx-virtualkeyboard-adapter"; repo = "fcitx-virtualkeyboard-adapter";
}; };
@ -198,7 +184,7 @@ let
}; };
bbsteamieInputs = { bbsteamieInputs = {
jovian = mkDep { jovian = mkInput {
owner = "Jovian-Experiments"; owner = "Jovian-Experiments";
repo = "Jovian-NixOS"; repo = "Jovian-NixOS";
}; };
@ -400,7 +386,7 @@ let
} }
]; ];
in { in {
inherit mkDep mkInput mkSrc; inherit mkInput mkSrc;
extraInputs = extraInputs =
{ {

View file

@ -7,10 +7,20 @@ let
sha256 = lock.nodes.nixpkgs.locked.narHash; sha256 = lock.nodes.nixpkgs.locked.narHash;
}}/lib"; }}/lib";
inherit (lib) attrValues findFirst foldl' hasAttr matchAttrs optionalAttrs recursiveUpdate; inherit (lib) attrNames attrValues findFirst foldl' hasAttr matchAttrs optionalAttrs optionals recursiveUpdate;
in rec { in rec {
recursiveUpdateList = list: foldl' recursiveUpdate {} list; recursiveUpdateList = list: foldl' recursiveUpdate {} list;
findInput = info:
findFirst
(x: matchAttrs (removeAttrs info ["inputs"]) (x.original or {})) {}
(attrValues lock.nodes);
mkFollowsFrom = info: target: follows:
optionalAttrs
(hasAttr target ((findInput info).inputs or {}))
{inputs.${target} = {inherit follows;};};
/* /*
* From an attrset, returns a flake input that has its type defaulted * From an attrset, returns a flake input that has its type defaulted
* to `github` and has some of its inputs following this flake's input * to `github` and has some of its inputs following this flake's input
@ -19,20 +29,18 @@ in rec {
* It gets information from the `flake.lock` file and can be used thanks * It gets information from the `flake.lock` file and can be used thanks
* to flakegen * to flakegen
*/ */
mkInput = {type ? "github", ...} @ info: let mkInput = {
input = type ? "github",
findFirst overrideNixpkgs ? true,
(x: matchAttrs (removeAttrs info ["inputs"]) (x.original or {})) {} ...
(attrValues lock.nodes); } @ info: let
mkOverride = i: mkFollowsFrom info i i;
mkOverride = i:
optionalAttrs
(hasAttr i (input.inputs or {}))
{inputs.${i}.follows = i;};
in in
recursiveUpdateList [ recursiveUpdateList ([
info (removeAttrs info ["overrideNixpkgs"])
{inherit type;} {inherit type;}
# Generic inputs
(mkOverride "systems") (mkOverride "systems")
(mkOverride "flake-compat") (mkOverride "flake-compat")
(mkOverride "flake-utils") (mkOverride "flake-utils")
@ -42,11 +50,18 @@ in rec {
(mkOverride "nix-github-actions") (mkOverride "nix-github-actions")
(mkOverride "pre-commit-hooks") (mkOverride "pre-commit-hooks")
(mkOverride "treefmt-nix") (mkOverride "treefmt-nix")
]; ]
# Specify if we can't make an input use this flake's nixpkgs
++ optionals overrideNixpkgs [(mkOverride "nixpkgs")]);
mkDep = info: mkInput (recursiveUpdate info {inputs.nixpkgs.follows = "nixpkgs";}); mkHyprDep = info: let
inherit (lock.nodes) hyprland;
mkHyprDep = info: mkInput (recursiveUpdate info {inputs.hyprland.follows = "hyprland";}); mkOverride = i: mkFollowsFrom info i i;
mkHyprOverride = i: mkFollowsFrom info i "hyprland/${i}";
in
mkInput (recursiveUpdateList ([info (mkOverride "hyprland")]
++ (map mkHyprOverride (attrNames hyprland.inputs))));
mkSrc = info: mkInput (info // {flake = false;}); mkSrc = info: mkInput (info // {flake = false;});
} }