Watch
2
0
Fork
You've already forked feel-co--hjem
0
mirror of github.com/feel-co/hjem
  • Nix 65.5%
  • Rust 33.5%
  • CUE 1%
Find a file
Repository files (latest commit first)
Filename Latest commit message Latest commit date
éclairevoyant ac916fbd74
Merge pull request #221 from feel-co/dependabot/github_actions/cachix/install-nix-action-32.1.0
build(deps): bump cachix/install-nix-action from 32.0.0 to 32.1.0
2026-12-01 12:14:23 +00:00
.github build(deps): bump cachix/install-nix-action from 32.0.0 to 32.1.0 2026-12-01 01:42:21 +00:00
cli build(deps): bump jiff in /cli in the rust-dependencies group 2026-11-30 01:44:58 +00:00
docs docs: describe dbus.packages option 2026-11-23 09:30:41 +03:00
internal docs: update ndg CLI invocations; generate manpages 2026-07-31 21:43:00 +03:00
manifest manifest: v3 2026-02-15 21:21:29 -05:00
modules modules/nixos: preserve packaged user units when applying overrides 2026-11-27 08:43:56 +03:00
npins npins: bump 2026-09-22 08:32:12 -04:00
tests tests/nixos: verify packaged user unit overrides 2026-11-27 10:00:56 +03:00
.envrc flake: unflakeify devshell, formatter 2025-10-20 22:25:29 -04:00
.gitignore flake: add direnv, devshell 2025-06-13 22:09:17 -04:00
CONTRIBUTING.md docs: mention ndg serve feature in preview instructions 2026-11-23 09:30:40 +03:00
default.nix treewide: drop smfh from checks and remove all references to pkgs.smfh 2026-07-27 13:08:45 +03:00
flake.lock flake.lock: Update 2026-11-22 20:51:21 -05:00
flake.nix flake: use zstd tarballs for nixpkgs, as xz tarballs will be deprecated 2026-09-12 12:58:14 -04:00
lib.nix modules/nixos: preserve packaged user units when applying overrides 2026-11-27 08:43:56 +03:00
LICENSE meta: relicense 2025-02-18 17:46:13 +03:00
README.md docs: reword & reorganize README; move non-flakes usage to CONTRIBUTING.md 2026-11-23 09:30:28 +03:00

Hjem [ˈjɛmˀ]

A streamlined way to manage your $HOME anywhere with Nix.


Synopsis
Features | Interface
Future Plans

What is this?

Hjem (meaning "home" in Danish) is a module system framework that implements simple, streamlined and polished primitives for managing files in your $HOME such as but not limited to the files that belong in ~/.config. Hjem aims to approach the domain as an alternative, easy-to-grasp utility for managing your $HOME purely and safely.

Features

We have learned from the mistakes made in the ecosystem. Therefore, Hjem is a lean module system and its super-fast Rust companion with the following features emphasized:

  1. Powerful $HOME management functionality and potential extensibility.
  2. Small, simple and performant codebase with minimal abstraction.
  3. Robust, atomic and manifest based file handling with smfh & Hjem CLI.
  4. Multi-user by design, works with any number of users and anywhere Nix runs.
  5. Designed for ease of extensibility and integration.

No compromises, only performance and comfort.

How to use

Hjem features extensive documentation for your convenience, meticulously describing each component and how to use them in various situations. Please refer to the rendered documentation at https://hjem.feel-co.org for an overview, usage guides and a NixOS module options reference.

Implementation

At its core Hjem exposes a streamlined module interface with multi-tenant capabilities, which you may use to manage individual users' homes by leveraging the Nix module system.

{ inputs, lib, pkgs, ... }:
{
  /*
    other NixOS configuration here...
  */

  hjem = {
    users = {
      alice = {
        enable = true;

        files = {
          # Write a text file in `/home/alice/.foo`
          # with the contents bar
          ".foo".text = "bar";

          # Alternatively, create the file source using a writer.
          # This can be used to generate config files with various
          # formats expected by different programs.
          ".bar".source = pkgs.writeText "file-foo" "file contents";

          # You can also use generators to transform Nix values
          ".baz" = {
            # Works with `pkgs.formats` too!
            generator = lib.generators.toJSON { };
            value = {
              some = "contents";
            };
          };
        };

        # this will write into `/home/alice/.config/test/bar.json`
        xdg.config.files."test/bar.json" = {
          generator = lib.generators.toJSON { };
          value = {
            foo = 1;
            bar = "Hello world!";
            baz = false;
          };
          # overwrite existing unmanaged file, if present
          clobber = true;
        };
      };
    };
  };
}

Note

Each attribute under hjem.users, e.g., hjem.users.alice or hjem.users.jane represent a user managed via users.users in NixOS. If a user does not exist, then Hjem will refuse to manage their $HOME by filtering non-existent users in file creation.

Similar to what you might be used to, Hjem manages both sources (i.e. files you are version-controlling in your configuration repository) and build-time generated files via the generators API. This gives you the option to pick between traditional dotfile management akin to GNU Stow or the Nix-for-everything approach where you generate other files (TOML, ini, KDL, JSON, YAML, etc.) from Nix while building your configuration using generators from Nixpkgs or even your own.

Module Interface

The module interface for the hjem module is conceptually very simple, and it is very similar to prior art (e.g., Home Manager) but unlike Home Manager Hjem does not act as module collection that must be maintained until the end of time. Instead, we implement minimal features (mostly around file linking and service management) and leave application-specific abstractions to the user to write and maintain as they see fit. This design choice is grounded on the reality that most users already have their own module system inside their configurations, which causes an overlap. Of course, the lean design of Hjem does not mean a module collection cannot exist. We strongly encourage software authors to ship their own Hjem modules, and build their own module collections. As a matter of fact, one already exists!

Below is a live implementation of the module interface, represented in JSON as will be written in the manifest:

$ nix eval .#nixosConfigurations.test.config.hjem.users.alice.files.'".foo"' --json | jq
{
  "clobber": false,
  "enable": true,
  "executable": false,
  "generator": null,
  "relativeTo": "/home/alice",
  "source": "/nix/store/22yfhzhk0w5mgaq6c943vimsg6qlr1sh-foo",
  "target": "/home/alice/.foo",
  "text": "bar",
  "value": null
}

Linker Implementation

Hjem is powered by the Hjem CLI, powered by the atomic and reliable file linking utility smfh initially designed by the awesome [Gerg-l]. Hjem utilizes smfh and Systemd services 1 to correctly link files into place without any unwanted side effects, and provides additional observability (and manual intervention tooling) into what really happens during linking.

smfh is developed alongside Hjem as a standalone Rust library, and the smfh CLI is provided in Nixpkgs as pkgs.smfh if you wish to develop your own linker or simply utilize smfh for atomic activation. For UX and quality of life additions, please consider sending a pull request to the Hjem CLI!

Environment Management

Hjem does not manage user environments as one might expect, but it provides a convenient environment.sessionVariables option that you can use to store your variables. This script will be used to store your environment variables in a POSIX-compliant script generated by Hjem, which you can source in your shell configurations.

Things to do

Hjem is considered mostly feature complete, in the sense that it is a clean, modular and reliable system for managing your $HOME and a clean implementation of the home.files API in Home Manager. It was never a goal to dive into abstracting files into modules, so the core functionality is entirely complete with clean linking semantics and Systemd user service management.

There are, however, things that we might be interested in doing. Below is a list of things that are currently on the agenda.

Attributions / Prior Art

Hjem is built on various ideas, projects and goals. First and foremost, our sincerest thanks to everyone who has used, contributed to or just talked about Hjem in public spaces. Thank you for the support!

Prior Art

Secondly, but no less importantly, our sincerest thanks go to Nixpkgs and Home Manager. The interface of the hjem.users module is inspired by Home Manager's home.file and Nixpkgs' users.users modules. What is now Hjem started as an experimental module addition to Nixpkgs' users.users. Hjem would not be possible without any of those projects, thank you!

We also extend our thanks to systemd-tmpfiles, which Hjem used previously to link files in place. This served us well for the short duration that we relied on them, but we have ultimately decided to go with our in-house file linker and CLI. The new linker implementation is, of course, infinitely more powerful and while we are not looking back, we thank systemd-tmpfiles for the excellent foundation it has provided.

Hjem-Rum

Last, but not least, a project worthy of note is Hjem Rum initially by @Lunarnovaa and @nezia1 (who have also contributed to Hjem and the surrounding ecosystem!) and now maintained by the awesome @GetPsyched. Hjem-Rum is a project establishes a Home Manager-like module system for users less comfortable with manually linking files in place. If you wish to utilize the power of Hjem, but want an easier interface, we encourage you to take a look at Hjem Rum.

License

This project is made available under Mozilla Public License (MPL) version 2.0. See LICENSE for more details on the exact conditions. An online copy is provided here.


  1. Which is preferable to hacky activation scripts that may or may not break. Systemd services allow for ordered dependency management across all services, and easy monitoring of Hjem-related services from the central systemctl interface. ↩︎