Skip to content

Commit

Permalink
feat(pops.hive): add homeConfiguration
Browse files Browse the repository at this point in the history
  • Loading branch information
GTrunSec committed Apr 26, 2024
1 parent 3a2a6f7 commit 3f16ddb
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 1 deletion.
2 changes: 1 addition & 1 deletion examples
54 changes: 54 additions & 0 deletions src/hive/collectors/homeConfigurations.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
# SPDX-FileCopyrightText: 2024 The divnix/hive Authors
#
# SPDX-License-Identifier: Unlicense

{
lib,
root,
super,
}:
let
inherit (lib) pipe;
l = lib // builtins;
inherit (root.hive) checks transformers;

# Error reporting
showAssertions =
let
collectFailed =
cfg: l.map (x: x.message) (l.filter (x: !x.assertion) cfg.assertions);
showWarnings =
res:
let
f = w: x: l.trace "warning: ${w}" x;
in
l.fold f res res.config.warnings;
in
evaled:
showWarnings (
let
failed = collectFailed evaled.config;
failedStr = l.concatStringsSep "\n" (map (x: "- ${x}") failed);
in
if failed == [ ] then evaled else throw "\nFailed assertions:\n${failedStr}"
);

hmCliSchema =
evaled:
let
asserted = showAssertions evaled;
in
{
# __schema = "v0";
inherit (asserted) options config;
inherit (asserted.config.home) activationPackage;
newsDisplay = evaled.config.news.display;
newsEntries = l.sort (a: b: a.time > b.time) (
l.filter (a: a.condition) evaled.config.news.entries
);
};
in
super.walk transformers.homeConfiguration [
(config: config.bee._evaled)
hmCliSchema
]
50 changes: 50 additions & 0 deletions src/hive/transformers/homeConfiguration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
# SPDX-FileCopyrightText: 2024 The divnix/hive Authors
#
# SPDX-License-Identifier: Unlicense

{ lib, root }:
{
evaled,
locatedConfig,
inputs ? { },
}:
let
inherit (root.hive) beeModule;

l = lib // builtins;

hmLib = import (evaled.config.bee.home + /modules/lib/stdlib-extended.nix) lib;

hmModules = import (evaled.config.bee.home + /modules/modules.nix) {
inherit (evaled.config.bee) pkgs;
lib = hmLib;
check = true;
# we switch off the nixpkgs module, package instantiation needs
# to happen on the `std` layer
useNixpkgsModule = false;
};
eval =
extra:
lib.evalModules {
specialArgs = {
modulesPath = l.toString (evaled.config.bee.home + /modules);
};
modules = [
beeModule
locatedConfig
extra
] ++ hmModules;
};
bee = evaled.config.bee // {
_evaled = eval { config._module.check = true; };
_unchecked = eval { config._module.check = false; };
};
in
{
inherit bee;
# complete module set, can be lib.evalModuled as-is
imports = [
beeModule
locatedConfig
] ++ hmModules;
}
28 changes: 28 additions & 0 deletions src/ops/readEnv.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# copyright: @domenkozar https://github.com/cachix/devenv/issues/516#issue-1652139691

{ lib }:
let
parseLine =
line:
let
parts = builtins.match "(.+) *= *(.+)" line;
in
if (!builtins.isNull parts) && (builtins.length parts) == 2 then
{
name = builtins.elemAt parts 0;
value = builtins.elemAt parts 1;
}
else
null;

parseEnvFile =
content:
builtins.listToAttrs (
lib.filter (x: !builtins.isNull x) (
map parseLine (lib.splitString "\n" content)
)
);

envContent = file: builtins.readFile file;
in
parseEnvFile envContent
6 changes: 6 additions & 0 deletions src/pops/hive.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ in
nixosConfigurationRenamer = "nixosConfiguration";
darwinConfigurationRenamer = "darwinConfiguration";
colmenaConfigurationRenamer = "colmenaConfiguration";
homeConfigurationRenamer = "homeConfiguration";
exports = {
hosts = { };
};
Expand Down Expand Up @@ -72,6 +73,9 @@ in
setNixosConfigurationsRenamer =
renamer: extendPop final (_: _: { nixosConfigurationRenamer = renamer; });

setHomeConfigurationsRenamer =
renamer: extendPop final (_: _: { homeConfigurationRenamer = renamer; });

setDarwinConfigurationsRenamer =
renamer: extendPop final (_: _: { darwinConfigurationRenamer = renamer; });

Expand All @@ -85,6 +89,8 @@ in
colmenaHive = root.hive.collectors.colmenaConfigurations final.colmenaConfigurationRenamer hostsArgs;

nixosConfigurations = root.hive.collectors.nixosConfigurations final.nixosConfigurationRenamer hostsArgs;

homeConfigurations = root.hive.collectors.homeConfigurations final.homeConfigurationRenamer hostsArgs;
# hosts = lib.omnibus.mkHosts {
# # hostsDir = projectRoot + "/units/nixos/hosts";
# hostsDir = ./.;
Expand Down
6 changes: 6 additions & 0 deletions tests/hive/expr.nix
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,12 @@ let
bee.system = system;
bee.pkgs = import nixpkgs { system = system; };
};

homeConfiguration = {
bee.system = system;
bee.pkgs = import nixpkgs { system = system; };
bee.home = omnibus.flake.inputs.home-manager;
};
};
};
hivePop =
Expand Down

0 comments on commit 3f16ddb

Please sign in to comment.