Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
59 changes: 52 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@ A module collection for managing your `$HOME` with [Hjem].
> Hjem, the tooling Hjem Rum is built off of, is still unfinished. Use at your
> own risk, and beware of bugs, issues, and missing features. If you do not feel
> like being a beta tester, wait until Hjem is more finished. It is not yet
> ready to fully replace Home Manager in the average user's config, but if you
> truly want to, an option could be to use both in conjunction. Either way, as
> Hjem continues to be developed, Hjem Rum will be worked on as we build modules
> and functionality out to support average users.
> ready to fully replace Home Manager in the average user's configuration, but
> if you truly want to, an option could be to use both in conjunction. Either
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There's a lot of unrelated changes in this commit, that should be split into their own commit.

> way, as Hjem continues to be developed, Hjem Rum will be worked on as we build
> modules and functionality out to support average users.

Based on the Hjem tooling, Hjem Rum (literally meaning "home rooms") is a
collection of modules for various programs and services to simplify the use of
Expand All @@ -33,7 +33,7 @@ Hjem was initially created as an improved implementation of the `home`
functionality that Home Manager provides. Its purpose was minimal. Hjem Rum's
purpose is to create a module collection based on that tooling in order to
recreate the functionality that Home Manager's large collection of modules
provides, allowing you to simply install and config a program.
provides, allowing you to simply install and configure a program.

## Setup

Expand Down Expand Up @@ -101,8 +101,8 @@ hjem = {
};
```

You can then configure any of the options defined in this flake in any nix
module:
You may then configure any of the options defined in imported modules in your
own configuration:

```nix
# configuration.nix
Expand All @@ -127,6 +127,51 @@ hjem.users.<username>.rum.programs.alacritty = {
> [!TIP]
> Consult the [documentation] for an overview of all available options.

### Optional: Manual Module Importing

> [!WARNING]
> Manual module importing is an advanced user feature and is not recommended for
> the average user. While it is supported and tested for, you may encounter more
> problems with it, and we advise users to become more familiar with the NixOS
> module system and Hjem Rum in particular before attempting to leave behind the
> automatic importing of all modules. Please skip ahead to [Environmental
> Variables] if you are not interested in this. While the default hjemModule
> imports all modules in the collection recursively, we have implemented
> functionality to support users who would prefer to only import modules that
> they plan to use. If you would like to do so, rather than importing the
> default hjemModule we provide, you will have to use the special `bare` module:

```nix
hjem.extraModules = [
inputs.hjem-rum.hjemModules.bare # The alternative module
# inputs.hjem-rum.hjemModules.default
];
```

This alternative module does not import any of our modules, which means that you
will not be able to do anything with Hjem Rum without manually importing our
modules yourself. To this end, we offer a `modulesPath` output for you to import
modules from.

```nix
hjem.extraModules = [
# Notice the similarity to the programs.alacritty namespace
"${inputs.hjem-rum.modulesPath}/programs/alacritty.nix" # Importing the alacritty module
];
```

We strongly recommend importing `environment/warning.nix`
when setting up Hjem Rum, as it offers useful checking and a warning if your
session variables are not actually being used.

```nix
hjem.extraModules = [
"${modulesPath}/environment/warning.nix"
];
```

See more information below.

## Environmental Variables

Hjem provides attribute set "environment.sessionVariables" that allows the user
Expand Down
12 changes: 9 additions & 3 deletions docs/TESTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
[nix.dev provides a useful guide]: https://nix.dev/tutorials/nixos/integration-testing-using-virtual-machines.html
[NixOS Manual]: https://nixos.org/manual/nixos/stable/index.html#sec-calling-nixos-tests
[internal NixOS lib]: https://github.com/NixOS/nixpkgs/tree/master/nixos/lib/testing
[README.md]: ../README.md#optional-importing

Hjem Rum's testing system is designed with simplicity in mind, so we shy away
from other testing frameworks and stick with `runTest`, from the
Expand Down Expand Up @@ -57,9 +58,8 @@ Our test system has some pre-defined things aiming at avoid boilerplate code:
- A user named "bob" is already created, with no groups, `isNormalUser` set to
true and no password.
- Both Hjem and Hjem Rum are already imported by default.

`self`, `lib` and `pkgs` are also passed to every test module, so you're free to
use them as you will.
- `self`, `lib` and `pkgs` are passed to every test module, so you're free to
use them as you will.

The [ncmpcpp test module] was written to serve as an example for future tests,
and provides comments for each step of the `testScript`. Care should be taken to
Expand All @@ -69,6 +69,12 @@ configuration is to have a file for each configuration alongside it, which then
gets passed to the test VM and gets evaluated with diff. You can use other
approaches if it's more convenient, that's just a suggestion.

You will need to import the module itself as well as any dependent modules. This
is not done automatically as to check for dependency changes and to ensure our
table of module dependencies remain up to date. If your test requires the
importing of modules other than the program being tested, ensure that is noted
in [README.md].

You can also debug your tests through a Python REPL by running:

```bash
Expand Down
8 changes: 6 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -46,18 +46,22 @@
});
in {
hjemModules = {
hjem-rum = import ./modules/hjem.nix {
complete = import ./modules/hjem.nix {
inherit (nixpkgs) lib;
inherit rumLib;
};
default = self.hjemModules.hjem-rum;
bare = {_module.args = {inherit rumLib;};};
default = self.hjemModules.complete;
};
packages = forAllSystems (pkgs: {
docs = pkgs.callPackage ./docs/package.nix {
inherit (ndg.packages.${pkgs.system}) ndg;
inherit rumLib;
};
});

modulesPath = ./modules/collection;

lib = rumLib;

devShells = forAllSystems (
Expand Down
8 changes: 4 additions & 4 deletions modules/collection/environment/warning.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
# will evaluate to true, disabled will evaluate to false. Results
# in a list of bools, allowing us to
variableLoaders = [
config.rum.programs.zsh.enable
config.rum.programs.fish.enable
config.rum.programs.nushell.enable
config.rum.desktops.hyprland.enable
(config.rum.programs.zsh.enable or false)
(config.rum.programs.fish.enable or false)
(config.rum.programs.nushell.enable or false)
(config.rum.desktops.hyprland.enable or false)
];

cfg = config.rum.environment;
Expand Down
37 changes: 22 additions & 15 deletions modules/collection/programs/direnv.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
config,
...
}: let
inherit (lib.attrsets) optionalAttrs;
inherit (lib.meta) getExe;
inherit (lib.modules) mkAfter mkIf;
inherit (lib.options) mkEnableOption mkOption mkPackageOption;
Expand Down Expand Up @@ -69,21 +70,27 @@ in {
};
};

config = mkIf cfg.enable {
packages = mkIf (cfg.package != null) [cfg.package];
files = {
".config/direnv/direnv.toml".source = mkIf (cfg.settings != {}) (
toml.generate "direnv-config.toml" cfg.settings
config = let
fishIntegration = optionalAttrs (config.rum.programs.fish.enable or false) {
fish.config = mkIf cfg.integrations.fish.enable (
mkAfter "${getExe cfg.package} hook fish | source"
);
".config/direnv/direnvrc".text = mkIf (cfg.direnvrc != "") cfg.direnvrc;
".config/direnv/lib/nix-direnv.sh".source = mkIf cfg.integrations.nix-direnv.enable "${cfg.integrations.nix-direnv.package}/share/nix-direnv/direnvrc";
};

rum.programs.fish.config = mkIf cfg.integrations.fish.enable (
mkAfter "${getExe cfg.package} hook fish | source"
);
rum.programs.zsh.initConfig = mkIf cfg.integrations.zsh.enable (
mkAfter "eval \"$(${getExe cfg.package} hook zsh)\""
);
};
zshIntegration = optionalAttrs (config.rum.programs.zsh.enable or false) {
zsh.initConfig = mkIf cfg.integrations.zsh.enable (
mkAfter "eval \"$(${getExe cfg.package} hook zsh)\""
);
};
in
mkIf cfg.enable {
packages = mkIf (cfg.package != null) [cfg.package];
files = {
".config/direnv/direnv.toml".source = mkIf (cfg.settings != {}) (
toml.generate "direnv-config.toml" cfg.settings
);
".config/direnv/direnvrc".text = mkIf (cfg.direnvrc != "") cfg.direnvrc;
".config/direnv/lib/nix-direnv.sh".source = mkIf cfg.integrations.nix-direnv.enable "${cfg.integrations.nix-direnv.package}/share/nix-direnv/direnvrc";
};
rum.programs = fishIntegration // zshIntegration;
};
}
42 changes: 23 additions & 19 deletions modules/collection/programs/starship.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
config,
...
}: let
inherit (lib.attrsets) optionalAttrs;
inherit (lib.meta) getExe;
inherit (lib.modules) mkAfter mkIf;
inherit (lib.options) mkEnableOption mkOption mkPackageOption;
Expand Down Expand Up @@ -57,24 +58,27 @@ in {
toml.generate "starship.toml" cfg.settings
);

rum.programs = {
fish.config = mkIf cfg.integrations.fish.enable (
mkAfter ("starship init fish | source" + (optionalString cfg.transience.enable "\nenable_transience"))
);

nushell.extraConfig = mkIf cfg.integrations.nushell.enable (
mkAfter ''
use ${
pkgs.runCommand "starship-init-nu" {} ''
${getExe cfg.package} init nu >> "$out"
''
}
''
);

zsh.initConfig = mkIf cfg.integrations.zsh.enable (
mkAfter ''eval "$(${getExe cfg.package} init zsh)"''
);
};
rum.programs =
(optionalAttrs (config.rum.programs.fish.enable or false) {
fish.config = mkIf cfg.integrations.fish.enable (
mkAfter ("starship init fish | source" + (optionalString cfg.transience.enable "\nenable_transience"))
);
})
// (optionalAttrs (config.rum.programs.nushell.enable or false) {
nushell.extraConfig = mkIf cfg.integrations.nushell.enable (
mkAfter ''
use ${
pkgs.runCommand "starship-init-nu" {} ''
${getExe cfg.package} init nu >> "$out"
''
}
''
);
})
// (optionalAttrs (config.rum.programs.zsh.enable or false) {
zsh.initConfig = mkIf cfg.integrations.zsh.enable (
mkAfter ''eval "$(${getExe cfg.package} init zsh)"''
);
});
};
}
7 changes: 0 additions & 7 deletions modules/collection/programs/zsh.nix
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,6 @@

cfg = config.rum.programs.zsh;
in {
imports = [
(
mkRenamedOptionModule
["rum" "programs" "zsh" "integrations" "starship" "enable"]
["rum" "programs" "starship" "integrations" "zsh" "enable"]
)
];
options.rum.programs.zsh = {
enable = mkEnableOption "zsh";
package = mkPackageOption pkgs "zsh" {nullable = true;};
Expand Down
10 changes: 4 additions & 6 deletions modules/hjem.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,11 @@
lib,
rumLib,
}: {
# Import the Hjem Rum module collection as an extraModule available under `hjem.users.<username>`
# This allows the definition of rum modules under `hjem.users.<username>.rum`

# Import the collection modules recursively so that all files
# are imported. This then gets imported into the user's
# 'hjem.extraModules' to make them available under 'hjem.users.<username>'
/*
Import all modules contained within the collection directory recursively so that all files are passed into`imports` as a list. The user then imports this into `hjem.extraModules` to make them available under `hjem.users.<username>`.
*/
imports = lib.filesystem.listFilesRecursive ./collection;

# We declare special args needed within the Hjem Modules.
_module.args.rumLib = rumLib;
}
2 changes: 1 addition & 1 deletion modules/tests/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ Usage: (import ./location-of-lib.nix) {test-script-here}
defaults = {
documentation.enable = lib.mkDefault false;
imports = [self.inputs.hjem.nixosModules.default];
hjem.extraModules = [self.hjemModules.default];
hjem.extraModules = [self.hjemModules.bare]; # We import the bare module to check for module dependencies
users.groups.bob = {};
users.users.bob = {
isNormalUser = true;
Expand Down
13 changes: 8 additions & 5 deletions modules/tests/programs/beets/bad-settings.nix
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
{
name = "programs-beets-no-file-created";
nodes.machine = {
hjem.users.bob.rum = {
programs.beets = {
enable = true;
settings = {};
nodes.machine = {self, ...}: {
hjem = {
extraModules = ["${self.modulesPath}/programs/beets.nix"];
users.bob.rum = {
programs.beets = {
enable = true;
settings = {};
};
};
};
};
Expand Down
15 changes: 9 additions & 6 deletions modules/tests/programs/beets/beets.nix
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,15 @@
settingsFile = yaml.generate "settings.yaml" settings;
in {
name = "programs-beets";
nodes.machine = {
hjem.users.bob.rum = {
programs.beets = {
enable = true;
package = pkgs.beets.override {pluginOverrides.duplicates.enable = true;};
inherit settings;
nodes.machine = {self, ...}: {
hjem = {
extraModules = ["${self.modulesPath}/programs/beets.nix"];
users.bob.rum = {
programs.beets = {
enable = true;
package = pkgs.beets.override {pluginOverrides.duplicates.enable = true;};
inherit settings;
};
};
};
};
Expand Down
8 changes: 7 additions & 1 deletion modules/tests/programs/direnv/direnv.nix
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
{
name = "programs-direnv";
nodes.machine = {
nodes.machine = {self, ...}: {
# TODO: Separate fish and zsh integration tests into their own tests
hjem.extraModules = [
"${self.modulesPath}/programs/direnv.nix"
"${self.modulesPath}/programs/fish.nix"
"${self.modulesPath}/programs/zsh.nix"
];
hjem.users.bob.rum = {
programs.direnv = {
enable = true;
Expand Down
Loading
Loading