patched the packagesFromDirectoryRecursive function mkLocalMod uses to use default.nix instead of package.nix so we can e.g. enable a module at modules/sops/default.nix with only [prefix].sops.enable instead of [prefix].sops.default.enable. ALSO this fixed the broken users.lyn module introduced in the last commit

This commit is contained in:
server 2024-10-19 00:15:34 +02:00
parent c09b1e8e17
commit 7848fa4d96
3 changed files with 58 additions and 2 deletions

View file

@ -1,5 +1,6 @@
{lib, ...}:
let
inherit (import ./packagesFromDirectoryRecursive.nix {inherit lib;} ) packagesFromDirectoryRecursive;
mapAttrKVs = mapFn: attrs: builtins.foldl' (acc: cur: acc // {${cur.key} = cur.value;}) {} (builtins.attrValues (builtins.mapAttrs mapFn attrs));
#kv = key: value: {inherit key value;};
recurseNaive = curPath: fn: mapAttrKVs (k: v: let
@ -14,7 +15,7 @@ let
else [{path = prefix ++ [k]; value = v;}]
) as);
getPathKVsRec = prefix: dir: getAttrKVsRec prefix (lib.packagesFromDirectoryRecursive { callPackage = path: x: path; directory = dir; });
getPathKVsRec = prefix: dir: getAttrKVsRec prefix (packagesFromDirectoryRecursive { callPackage = path: x: path; directory = dir; });
unifyMod = (import ./modules-extracted.nix {lib = lib;}).unifyModuleSyntax;
transformLocalMod = {path, value}: let

View file

@ -0,0 +1,55 @@
{lib, ...}: with lib;{packagesFromDirectoryRecursive =
{
callPackage,
directory,
...
} :
let
# Determine if a directory entry from `readDir` indicates a package or
# directory of packages.
directoryEntryIsPackage = basename: type:
type == "directory" || hasSuffix ".nix" basename;
# List directory entries that indicate packages in the given `path`.
packageDirectoryEntries = path:
filterAttrs directoryEntryIsPackage (builtins.readDir path);
# Transform a directory entry (a `basename` and `type` pair) into a
# package.
directoryEntryToAttrPair = subdirectory: basename: type:
let
path = subdirectory + "/${basename}";
in
if type == "regular"
then
{
name = removeSuffix ".nix" basename;
value = callPackage path { };
}
else
if type == "directory"
then
{
name = basename;
value = packagesFromDirectory path;
}
else
throw
''
lib.filesystem.packagesFromDirectoryRecursive: Unsupported file type ${type} at path ${toString subdirectory}
'';
# Transform a directory into a package but its edited to use default.nix because package.nix is nonstandard or
# set of packages (otherwise).
packagesFromDirectory = path:
let
defaultPackagePath = path + "/default.nix";
in
if pathExists defaultPackagePath
then callPackage defaultPackagePath { }
else mapAttrs'
(directoryEntryToAttrPair path)
(packageDirectoryEntries path);
in
packagesFromDirectory directory;
}

View file

@ -1,5 +1,5 @@
{lib, config, pkgs, ...}: {
lyn.sops.default.enable = true;
lyn.sops.enable = true;
nix.settings.experimental-features = [ "nix-command" "flakes" ];
nixpkgs.config.allowUnfree = true;
nix.package = config.pkgsInstances.unstable.lix;