Skip to content

Commit

Permalink
refactor: reorg the path struct -5
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Nov 6, 2023
1 parent f8f6485 commit b3fc889
Show file tree
Hide file tree
Showing 54 changed files with 241 additions and 76 deletions.
6 changes: 3 additions & 3 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

12 changes: 6 additions & 6 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@
outputs =
{ self, flops, ... }@inputs:
let
library = import ./lib/__init.nix { inherit inputs; };
lib = library.exports.default;
srcPops = import ./src/__init.nix { inherit inputs; };
src = srcPops.exports.default;
in
lib.flakeOutputs
src.flakeOutputs
// {
pops = lib.pops // {
lib = library;
pops = src.pops // {
self = srcPops;
};

inherit lib;
inherit (src) lib;

templates = {
nixos = {
Expand Down
6 changes: 0 additions & 6 deletions lib/loaderInputs.nix

This file was deleted.

12 changes: 0 additions & 12 deletions lib/pops/load.nix

This file was deleted.

16 changes: 0 additions & 16 deletions lib/pops/scripts.nix

This file was deleted.

4 changes: 2 additions & 2 deletions local/cells/repo/pops.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
let
inherit (inputs) nixpkgs;
inputs' = (inputs.omnibus.pops.flake.setSystem nixpkgs.system).inputs;
inherit (inputs.omnibus.pops.lib.load.inputs) POP flops;
inherit (inputs.omnibus.pops.self.load.inputs) POP flops;
in
{
devshellProfiles =
Expand All @@ -13,7 +13,7 @@ in
POP.extendPop flops.haumea.pops.exporter (
self: super: {
exports = rec {
inherit (inputs.omnibus.mapPopsExports pops) self;
inherit (inputs.omnibus.lib.mapPopsExports pops) self;
pops.self =
(self.layouts.default.addLoadExtender {
load.inputs = {
Expand Down
2 changes: 1 addition & 1 deletion local/lock/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@
sops-nix.inputs.nixpkgs.follows = "nixpkgs";

nixfmt.url = "github:serokell/nixfmt/?ref=refs/pull/118/head";
# nixfmt.inputs.nixpkgs.follows = "nixpkgs";
# nixfmt.inputs.flake-compat.follows = "nixpkgs";
nixfmt.inputs.flake-compat.follows = "";
};

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/flakeOutputs.nix → src/flakeOutputs.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
let
outputs = root.mapPopsExports super.pops;
outputs = root.lib.mapPopsExports super.pops;
in
{
inherit (super) load;
Expand Down
File renamed without changes.
86 changes: 86 additions & 0 deletions src/lib/inputsToPaths.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
{ lib, flops }:
# let
# # Helper function to collect outPath attributes recursively
# collectPaths =
# input:
# lib.concatMap
# (
# attr:
# let
# # Check for outPath or sourceInfo.outPath and collect if present
# paths =
# if lib.isAttrs attr then
# if attr ? outPath then
# [ attr.outPath ]
# else if attr ? sourceInfo && attr.sourceInfo ? outPath then
# [ attr.sourceInfo.outPath ]
# else
# [ ]
# else
# [ ];
# # Recursively collect paths from nested inputs if they exist
# nestedPaths =
# if lib.isAttrs attr && attr ? inputs then collectPaths attr.inputs else [ ];
# in
# paths ++ nestedPaths
# )
# (lib.attrValues input);
# # Main function to collect outPath attributes from all inputs
# inputsToPaths = inputs: lib.flatten (collectPaths inputs);
# in
# # Example usage
# inputsToPaths
inputs:
let
l = lib;

extractAttrsFromInputs =
inputs:
l.pipe inputs [
(l.filterAttrs (_: v: l.isAttrs v && (v ? sourceInfo.outPath || v ? outPath)))
(l.mapAttrs (_: v: v.sourceInfo.outPath or v.outPath or v.path))
(l.mapAttrs (_: v: toString v))
];

attrsToPaths = i: lib.attrValues (extractAttrsFromInputs i);

inherit (flops) recursiveMerge;
updatedInputs = (recursiveMerge (l.flatten [ inputs ]));
in
l.pipe updatedInputs [
(
v:
map (x: if v.${x} ? inputs then attrsToPaths v.${x}.inputs else attrsToPaths v)
(l.attrNames (extractAttrsFromInputs v))
)
l.flatten
l.unique
]
++ attrsToPaths updatedInputs # extractPaths From the top level inputs
/* inputsToPaths {
b = {
inputs = {
d = {
outPath = "<PATH-b.d>";
};
f = {
outPath = "<PATH-b.f>";
};
};
outPath = "<PATH-b>";
};
a = {
inputs = {
b = {
outPath = "<PATH-a.b>";
};
c = {
outPath = "<PATH-a.c>";
};
};
outPath = "<PATH-a>";
};
}
=>
[ "<PATH-a>" "<PATH-a.b>" "<PATH-a.c>" "<PATH-b>" "<PATH-b.d>" "<PATH-b.f>" ]
*/
6 changes: 6 additions & 0 deletions src/lib/loaderInputs.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
inputs.self.pops.self.load.inputs
// {
omnibus =
(lib.recursiveUpdate root { pops.self = inputs.self.pops.self; })
// root.flakeOutputs;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/pops/configs.nix → src/pops/configs.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
flops.haumea.pops.default.setInit {
src = projectDir + "/units/configs";
inputs = root.loaderInputs;
inputs = root.lib.loaderInputs;
}
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion lib/pops/homeModules.nix → src/pops/homeModules.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flops.haumea.pops.default.setInit {
src = projectDir + "/units/nixos/homeModules";
type = "nixosModules";
inputs = root.loaderInputs;
inputs = root.lib.loaderInputs;
}
File renamed without changes.
19 changes: 19 additions & 0 deletions src/pops/load.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{
flops,
omnibus,
haumea,
root,
}:
let
inherit (flops) recursiveMerge';
in
load:
(flops.haumea.pops.default.setInit (
recursiveMerge' [
{
loader = with haumea; [ (matchers.nix loaders.scoped) ];
inputs = root.lib.loaderInputs;
}
load
]
))
2 changes: 1 addition & 1 deletion lib/pops/nixosModules.nix → src/pops/nixosModules.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
flops.haumea.pops.default.setInit {
src = projectDir + "/units/nixos/nixosModules";
type = "nixosModules";
inputs = root.loaderInputs;
inputs = root.lib.loaderInputs;
}
File renamed without changes.
46 changes: 46 additions & 0 deletions src/pops/scripts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
let
inherit (inputs) nixpkgs;
inherit (root.ops) makes;
inherit (makes) makeScript makeEnvVars;
in
(super.load {
inputs =
{
inherit
nixpkgs
makes
makeScript
makeEnvVars
;
}
// lib.optionalAttrs (inputs ? climod) {
climod = nixpkgs.callPackage inputs.climod { pkgs = nixpkgs; };
};
loader = with haumea; [ (matchers.nix loaders.scoped) ];
transformer = [ (_cursor: dir: if dir ? default then dir.default else dir) ];
})

/* (matchers.regex "^(default)\\.(nix)" (
_: _: path:
let
getDir = (list: builtins.elemAt list ((builtins.length list) - 3)) (
l.split "/" path
);
in
(
if l.hasPrefix "makes-" getDir then
(scopedImport
(
self.load.inputs
// {
# inherit (self.initLoad.inputs.makes) makeEnvVars;
makeEnvVars = self: self;
}
)
path
)
else
{ }
)
))
*/
File renamed without changes.
File renamed without changes.
12 changes: 6 additions & 6 deletions templates/hivebus/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/hivebus/nix/lib/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let
(lib.filterAttrs (_: v: v ? "${config}"))
(lib.mapAttrs (_: v: v.${config}))
];
inherit (omnibus) mapPopsExports;
inherit (omnibus.lib) mapPopsExports;
in
(mapPopsExports super.pops)
// {
Expand Down
2 changes: 1 addition & 1 deletion templates/hivebus/nix/lib/pops/hosts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:
let
hostsDir = lib.attrNames (lib.readDir (projectDir + "/units/nixos/hosts"));
inherit (omnibus) addLoadToPops;
inherit (omnibus.lib) addLoadToPops;
in
addLoadToPops hostsDir super.hostsLoad (
elm: n: v: {
Expand Down
2 changes: 1 addition & 1 deletion templates/hivebus/nix/lib/pops/omnibus/lib.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
omnibus.pops.lib.addLoadExtender {
omnibus.pops.self.addLoadExtender {
load.inputs = {
inputs = inputs // root.pops.subflake.inputs;
};
Expand Down
12 changes: 6 additions & 6 deletions templates/nixos/flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion templates/nixos/nix/lib/flakeOutputs.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ let
(lib.filterAttrs (_: v: v ? "${config}"))
(lib.mapAttrs (_: v: v.${config}))
];
inherit (omnibus) mapPopsExports;
inherit (omnibus.lib) mapPopsExports;
in
(mapPopsExports super.pops)
// {
Expand Down
2 changes: 1 addition & 1 deletion templates/nixos/nix/lib/pops/hosts.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
}:
let
hostsDir = lib.attrNames (lib.readDir (projectDir + "/units/nixos/hosts"));
inherit (omnibus) addLoadToPops;
inherit (omnibus.lib) addLoadToPops;
in
addLoadToPops hostsDir super.hostsLoad (
elm: n: v: {
Expand Down
2 changes: 1 addition & 1 deletion templates/nixos/nix/lib/pops/omnibus/lib.nix
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
omnibus.pops.lib.addLoadExtender {
omnibus.pops.self.addLoadExtender {
load.inputs = {
inputs = inputs // root.pops.subflake.inputs;
};
Expand Down
Loading

0 comments on commit b3fc889

Please sign in to comment.