Skip to content

Commit

Permalink
modules/common: add hjem.linker option
Browse files Browse the repository at this point in the history
  • Loading branch information
eclairevoyant committed Jan 21, 2025
1 parent 864dcf3 commit ede630a
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 3 deletions.
2 changes: 1 addition & 1 deletion modules/common.nix
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
inherit (lib.modules) mkIf mkDefault mkDerivedConfig;
inherit (lib.options) mkOption mkEnableOption literalExpression;
inherit (lib.strings) hasPrefix;
inherit (lib.types) bool submodule str path attrsOf nullOr lines listOf package;
inherit (lib.types) attrsOf bool lines listOf nullOr package path str submodule;

clobberOpt = config.clobberFiles;

Expand Down
31 changes: 29 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) attrs attrsOf bool enum listOf raw submoduleWith;

cfg = config.hjem;
enabledUsers = filterAttrs (_: u: u.enable) cfg.users;
Expand Down Expand Up @@ -82,6 +82,27 @@ in {
to be passed down to to all imported modules.
'';
};

linker = mkOption {
default =
if pkgs.stdenv.hostPlatform.isLinux
then "tmpfiles"
else "manifest";
description = ''
Method to use to link files.
`"tmpfiles"` will use `systemd-tmpfiles`, which is only supported on Linux.
This is the default file linker on Linux, as it is the more mature linker, but it has the downside of leaving
behind symlinks that may not get invalidated until the next GC, if an entry is removed from {option}`hjem.<user>.files`.
`"manifest"` will use Hjem's custom file linker based on an internally-generated manifest.
The custom file linker will use this manifest to create or remove links as needed, by comparing the
manifest of the currently activated system with that of the new system.
This prevents dangling symlinks when an entry is removed from {option}`hjem.<user>.files`.
This linker is currently experimental; once it matures, it may become the default in the future.
'';
type = enum ["manifest" "tmpfiles"];
};
};

config = mkMerge [
Expand All @@ -90,7 +111,9 @@ in {
inherit name;
value.packages = packages;
}) (filterAttrs (_: u: u.packages != []) enabledUsers);
}

(mkIf (cfg.linker == "tmpfiles") {
systemd.user.tmpfiles.users = mapAttrs' (name: {files, ...}: {
inherit name;
value.rules = map (
Expand All @@ -107,7 +130,11 @@ in {
"${mode} '${file.target}' - - - - ${file.source}"
) (filter (f: f.enable && f.source != null) (attrValues files));
}) (filterAttrs (_: u: u.files != {}) enabledUsers);
}
})

(mkIf (cfg.linker == "manifest") {

})

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

0 comments on commit ede630a

Please sign in to comment.