From 116971f60d713550264cdebf5e78d809f4ef42d0 Mon Sep 17 00:00:00 2001 From: Jake Hamilton Date: Wed, 16 Aug 2023 23:46:29 -0700 Subject: [PATCH] wip: initial frost support --- flake.nix | 27 ++++++++++++- modules/nixos/user/default.nix | 39 +++++++++++-------- {lib => snowfall-lib}/attrs/default.nix | 0 {lib => snowfall-lib}/default.nix | 10 ++++- {lib => snowfall-lib}/flake/default.nix | 8 +++- {lib => snowfall-lib}/fp/default.nix | 0 {lib => snowfall-lib}/fs/default.nix | 0 {lib => snowfall-lib}/home/default.nix | 23 +++++++---- .../home/nix-registry-module.nix | 0 {lib => snowfall-lib}/internal/default.nix | 2 +- {lib => snowfall-lib}/module/default.nix | 0 {lib => snowfall-lib}/overlay/default.nix | 0 {lib => snowfall-lib}/package/default.nix | 12 +++++- {lib => snowfall-lib}/path/default.nix | 0 {lib => snowfall-lib}/shell/default.nix | 0 {lib => snowfall-lib}/system/default.nix | 0 .../system/virtual-systems.nix | 0 {lib => snowfall-lib}/template/default.nix | 0 18 files changed, 91 insertions(+), 30 deletions(-) rename {lib => snowfall-lib}/attrs/default.nix (100%) rename {lib => snowfall-lib}/default.nix (89%) rename {lib => snowfall-lib}/flake/default.nix (96%) rename {lib => snowfall-lib}/fp/default.nix (100%) rename {lib => snowfall-lib}/fs/default.nix (100%) rename {lib => snowfall-lib}/home/default.nix (94%) rename {lib => snowfall-lib}/home/nix-registry-module.nix (100%) rename {lib => snowfall-lib}/internal/default.nix (96%) rename {lib => snowfall-lib}/module/default.nix (100%) rename {lib => snowfall-lib}/overlay/default.nix (100%) rename {lib => snowfall-lib}/package/default.nix (86%) rename {lib => snowfall-lib}/path/default.nix (100%) rename {lib => snowfall-lib}/shell/default.nix (100%) rename {lib => snowfall-lib}/system/default.nix (100%) rename {lib => snowfall-lib}/system/virtual-systems.nix (100%) rename {lib => snowfall-lib}/template/default.nix (100%) diff --git a/flake.nix b/flake.nix index e0deb3d..3a6cf7e 100644 --- a/flake.nix +++ b/flake.nix @@ -22,7 +22,7 @@ # `lib.flake-utils-plus.mkApp`. # Usage: mkLib { inherit inputs; src = ./.; } # result: lib - mkLib = import ./lib core-inputs; + mkLib = import ./snowfall-lib core-inputs; # A convenience wrapper to create the library and then call `lib.mkFlake`. # Usage: mkFlake { inherit inputs; src = ./.; ... } @@ -50,5 +50,30 @@ homeModules = { user = ./modules/home/user/default.nix; }; + + _snowfall = rec { + raw-config = config; + + config = { + root = ./.; + src = ./.; + namespace = "snowfall"; + lib-dir = "snowfall-lib"; + }; + + internal-lib = + let + lib = mkLib { + src = ./.; + + inputs = inputs // { + self = { }; + }; + }; + in + builtins.removeAttrs + lib.snowfall + [ "internal" ]; + }; }; } diff --git a/modules/nixos/user/default.nix b/modules/nixos/user/default.nix index 757997d..e8483f1 100644 --- a/modules/nixos/user/default.nix +++ b/modules/nixos/user/default.nix @@ -1,10 +1,12 @@ -{ pkgs, lib, options, config, inputs, ... }: +args@{ pkgs, lib, options, config, ... }: let inherit (lib) types mkOption mkDefault foldl optionalAttrs optional; cfg = config.snowfallorg; + inputs = args.inputs or { }; + user-names = builtins.attrNames cfg.user; create-system-users = system-users: name: @@ -58,29 +60,32 @@ in config = mkOption { # HM-compatible options taken from: # https://github.com/nix-community/home-manager/blob/0ee5ab611dc1fbb5180bd7d88d2aeb7841a4d179/nixos/common.nix#L14 + # @NOTE(jakehamilton): This has been adapted to support documentation generation without + # having home-manager options fully declared. type = types.submoduleWith { specialArgs = { osConfig = config; - modulesPath = "${inputs.home-manager}/modules"; - } // config.home-manager.extraSpecialArgs; + modulesPath = "${inputs.home-manager or "/"}/modules"; + } // (config.home-manager.extraSpecialArgs or { }); modules = [ - ({ lib, modulesPath, ... }: { - imports = import "${modulesPath}/modules.nix" { - inherit pkgs lib; - useNixpkgsModule = !config.home-manager.useGlobalPkgs; - }; + ({ lib, modulesPath, ... }: + if inputs ? home-manager then { + imports = import "${modulesPath}/modules.nix" { + inherit pkgs lib; + useNixpkgsModule = !(config.home-manager.useGlobalPkgs or false); + }; - config = { - submoduleSupport.enable = true; - submoduleSupport.externalPackageInstall = cfg.useUserPackages; + config = { + submoduleSupport.enable = true; + submoduleSupport.externalPackageInstall = cfg.useUserPackages; - home.username = config.users.users.${name}.name; - home.homeDirectory = config.users.users.${name}.home; + home.username = config.users.users.${name}.name; + home.homeDirectory = config.users.users.${name}.home; - nix.package = config.nix.package; - }; - }) - ] ++ config.home-manager.sharedModules; + nix.package = config.nix.package; + }; + } else { }) + ] ++ (config.home-manager.sharedModules or [ ]); }; }; }; diff --git a/lib/attrs/default.nix b/snowfall-lib/attrs/default.nix similarity index 100% rename from lib/attrs/default.nix rename to snowfall-lib/attrs/default.nix diff --git a/lib/default.nix b/snowfall-lib/default.nix similarity index 89% rename from lib/default.nix rename to snowfall-lib/default.nix index 05f0c3d..988142c 100644 --- a/lib/default.nix +++ b/snowfall-lib/default.nix @@ -8,7 +8,13 @@ user-options: let raw-snowfall-config = user-options.snowfall or { }; snowfall-config = raw-snowfall-config // { + src = user-options.src; root = raw-snowfall-config.root or user-options.src; + namespace = raw-snowfall-config.namespace or "internal"; + meta = { + name = raw-snowfall-config.meta.name or null; + title = raw-snowfall-config.meta.title or null; + }; }; user-inputs = user-options.inputs // { src = user-options.src; }; @@ -53,7 +59,9 @@ let core-inputs-libs = get-libs (without-self core-inputs); user-inputs-libs = get-libs (without-self user-inputs); - snowfall-lib-root = "${core-inputs.src}/lib"; + # @NOTE(jakehamilton): This root is different to accomodate the creation + # of a fake user-lib in order to run documentation on this flake. + snowfall-lib-root = "${core-inputs.src}/snowfall-lib"; snowfall-lib-dirs = let files = builtins.readDir snowfall-lib-root; diff --git a/lib/flake/default.nix b/snowfall-lib/flake/default.nix similarity index 96% rename from lib/flake/default.nix rename to snowfall-lib/flake/default.nix index 15de25a..3178e3e 100644 --- a/lib/flake/default.nix +++ b/snowfall-lib/flake/default.nix @@ -71,7 +71,7 @@ rec { mkFlake = full-flake-options: let - package-namespace = full-flake-options.package-namespace or "internal"; + package-namespace = full-flake-options.package-namespace or snowfall-config.namespace or "internal"; custom-flake-options = flake.without-snowfall-options full-flake-options; alias = full-flake-options.alias or { }; homes = snowfall-lib.home.create-homes (full-flake-options.homes or { }); @@ -149,6 +149,12 @@ rec { }; outputsBuilder = outputs-builder; + + _snowfall = { + config = snowfall-config; + raw-config = full-flake-options.snowfall or { }; + user-lib = snowfall-lib.internal.user-lib; + }; }; flake-utils-plus-outputs = diff --git a/lib/fp/default.nix b/snowfall-lib/fp/default.nix similarity index 100% rename from lib/fp/default.nix rename to snowfall-lib/fp/default.nix diff --git a/lib/fs/default.nix b/snowfall-lib/fs/default.nix similarity index 100% rename from lib/fs/default.nix rename to snowfall-lib/fs/default.nix diff --git a/lib/home/default.nix b/snowfall-lib/home/default.nix similarity index 94% rename from lib/home/default.nix rename to snowfall-lib/home/default.nix index c2ea41b..fe81473 100644 --- a/lib/home/default.nix +++ b/snowfall-lib/home/default.nix @@ -31,14 +31,21 @@ in { home = rec { # Modules in home-manager expect `hm` to be available directly on `lib` itself. - home-lib = snowfall-lib.internal.system-lib.extend (final: prev: - # @NOTE(jakehamilton): This order is important, this library's extend and other utilities must write - # _over_ the original `system-lib`. - snowfall-lib.internal.system-lib - // prev - // { - hm = snowfall-lib.internal.system-lib.home-manager.hm; - }); + home-lib = + # @NOTE(jakehamilton): This prevents an error during evaluation if the input does + # not exist. + if user-inputs ? home-manager then + snowfall-lib.internal.system-lib.extend + (final: prev: + # @NOTE(jakehamilton): This order is important, this library's extend and other utilities must write + # _over_ the original `system-lib`. + snowfall-lib.internal.system-lib + // prev + // { + hm = snowfall-lib.internal.system-lib.home-manager.hm; + }) + else + { }; # Get the user and host from a combined string. # Type: String -> Attrs diff --git a/lib/home/nix-registry-module.nix b/snowfall-lib/home/nix-registry-module.nix similarity index 100% rename from lib/home/nix-registry-module.nix rename to snowfall-lib/home/nix-registry-module.nix diff --git a/lib/internal/default.nix b/snowfall-lib/internal/default.nix similarity index 96% rename from lib/internal/default.nix rename to snowfall-lib/internal/default.nix index 40aa8b3..e61eb73 100644 --- a/lib/internal/default.nix +++ b/snowfall-lib/internal/default.nix @@ -42,7 +42,7 @@ let system-lib = snowfall-lib.attrs.merge-shallow [ base-lib - { internal = user-lib; } + { "${snowfall-config.namespace}" = user-lib; } ]; in { diff --git a/lib/module/default.nix b/snowfall-lib/module/default.nix similarity index 100% rename from lib/module/default.nix rename to snowfall-lib/module/default.nix diff --git a/lib/overlay/default.nix b/snowfall-lib/overlay/default.nix similarity index 100% rename from lib/overlay/default.nix rename to snowfall-lib/overlay/default.nix diff --git a/lib/package/default.nix b/snowfall-lib/package/default.nix similarity index 86% rename from lib/package/default.nix rename to snowfall-lib/package/default.nix index b77b51c..f2b5a6d 100644 --- a/lib/package/default.nix +++ b/snowfall-lib/package/default.nix @@ -40,7 +40,17 @@ in in { name = builtins.unsafeDiscardStringContext (snowfall-lib.path.get-parent-directory package); - drv = callPackageWith extra-inputs package { }; + drv = + let + pkg = callPackageWith extra-inputs package { }; + in + pkg // { + meta = (pkg.meta or { }) // { + snowfall = { + path = package; + }; + }; + }; }; packages-metadata = builtins.map create-package-metadata user-packages; merge-packages = packages: metadata: diff --git a/lib/path/default.nix b/snowfall-lib/path/default.nix similarity index 100% rename from lib/path/default.nix rename to snowfall-lib/path/default.nix diff --git a/lib/shell/default.nix b/snowfall-lib/shell/default.nix similarity index 100% rename from lib/shell/default.nix rename to snowfall-lib/shell/default.nix diff --git a/lib/system/default.nix b/snowfall-lib/system/default.nix similarity index 100% rename from lib/system/default.nix rename to snowfall-lib/system/default.nix diff --git a/lib/system/virtual-systems.nix b/snowfall-lib/system/virtual-systems.nix similarity index 100% rename from lib/system/virtual-systems.nix rename to snowfall-lib/system/virtual-systems.nix diff --git a/lib/template/default.nix b/snowfall-lib/template/default.nix similarity index 100% rename from lib/template/default.nix rename to snowfall-lib/template/default.nix