Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

hjem: migrate to new linker #20

Draft
wants to merge 2 commits into
base: main
Choose a base branch
from
Draft
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
75 changes: 74 additions & 1 deletion flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

10 changes: 8 additions & 2 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
{
inputs.nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs?ref=nixos-unstable";
smfh.url = "github:Gerg-L/smfh";
};

outputs = {
self,
nixpkgs,
...
}: let
} @ inputs: let
forAllSystems = nixpkgs.lib.genAttrs ["x86_64-linux" "aarch64-linux"];
in {
nixosModules = {
Expand All @@ -21,6 +24,9 @@
in {
hjem-basic = import ./tests/basic.nix checkArgs;
hjem-special-args = import ./tests/special-args.nix checkArgs;

# Build smfh as a part of 'nix flake check'
smfh = inputs.smfh.packages.${system}.smfh;
});

formatter = forAllSystems (system: nixpkgs.legacyPackages.${system}.alejandra);
Expand Down
26 changes: 24 additions & 2 deletions modules/nixos/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
inherit (lib.lists) filter map flatten concatLists;
inherit (lib.attrsets) filterAttrs mapAttrs' attrValues mapAttrsToList;
inherit (lib.trivial) flip;
inherit (lib.types) bool attrsOf submoduleWith listOf raw attrs;
inherit (lib.types) bool attrsOf submoduleWith listOf raw attrs either package enum;

cfg = config.hjem;

Expand Down Expand Up @@ -66,6 +66,23 @@ in {
description = "Home configurations to be managed";
};

linker = mkOption {
type = either package (enum ["systemd-tmpfiles" "smfh"]);
default = "systemd-tmpfiles";
description = ''
The backend Hjem will use to link files in place.

* `systemd-tmpfiles` is th current implementation, lacks the ability to clean up
files that are no longer managed.
* `smfh` (Sleek Manifest File Handler) is the new implementation, set to be the
default once stable

If a value with the `package` type is passed, then the executable of the package
(acquired via `lib.getExe`) will be executed verbatim. Use the package option
only if you know what you are doing.
'';
};

extraModules = mkOption {
type = listOf raw;
default = [];
Expand Down Expand Up @@ -93,7 +110,12 @@ in {
inherit name;
value.packages = packages;
}) (filterAttrs (_: u: (u.enable && u.packages != [])) cfg.users);
}

# If using systemd-tmpfiles as a linker backend, then map files submodule into
# systemd.user.tmpfiles. Be careful to retain compatibility with the schema
# while altering the files submodule.
(mkIf (cfg.linker == "systemd-tmpfiles") {
systemd.user.tmpfiles.users = mapAttrs' (name: {files, ...}: {
inherit name;
value.rules = map (
Expand All @@ -110,7 +132,7 @@ in {
"${mode} '${file.target}' - - - - ${file.source}"
) (filter (f: f.enable && f.source != null) (attrValues files));
}) (filterAttrs (_: u: (u.enable && u.files != {})) cfg.users);
}
})

(mkIf (cfg.users != {}) {
warnings = flatten (flip mapAttrsToList cfg.users (user: config:
Expand Down