From 7848fa4d968693f0518929f8b8a6e0060dfb38b8 Mon Sep 17 00:00:00 2001 From: server Date: Sat, 19 Oct 2024 00:15:34 +0200 Subject: [PATCH] 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 --- meta/mkLocalMods.nix | 3 +- meta/packagesFromDirectoryRecursive.nix | 55 +++++++++++++++++++++++++ modules/profiles/base.nix | 2 +- 3 files changed, 58 insertions(+), 2 deletions(-) create mode 100644 meta/packagesFromDirectoryRecursive.nix diff --git a/meta/mkLocalMods.nix b/meta/mkLocalMods.nix index 333af67..285624d 100644 --- a/meta/mkLocalMods.nix +++ b/meta/mkLocalMods.nix @@ -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 diff --git a/meta/packagesFromDirectoryRecursive.nix b/meta/packagesFromDirectoryRecursive.nix new file mode 100644 index 0000000..2800a8a --- /dev/null +++ b/meta/packagesFromDirectoryRecursive.nix @@ -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; +} diff --git a/modules/profiles/base.nix b/modules/profiles/base.nix index 4d03f40..e113504 100644 --- a/modules/profiles/base.nix +++ b/modules/profiles/base.nix @@ -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;