~ruther/nix-tmpactivator

36039e24788d5577829ef2aa357cad7b423f7487 — Rutherther 11 months ago f4f924a
feat: add removal records for home files
2 files changed, 16 insertions(+), 27 deletions(-)

M modules/home.nix
M modules/tmpfiles.nix
M modules/home.nix => modules/home.nix +9 -2
@@ 44,14 44,21 @@ in {
    tmpfiles.defaultUser = config.home.user;
    tmpfiles.defaultGroup = config.home.group;

    tmpfiles.files = lib.attrValues (lib.mapAttrs (name: conf: {
    tmpfiles.files = (lib.attrValues (lib.mapAttrs (name: conf: {
      type = "L+";
      mode = "-";
      user = "-";
      group = "-";
      text = "${config.home.homeFilesPackage}/${name}";
      target = "${config.home.homeDirectory}/${name}";
    }) homeFiles);
    }) homeFiles)) ++ (lib.attrValues (lib.mapAttrs (name: conf: {
      type = "r";
      mode = "-";
      user = "-";
      group = "-";
      text = "-";
      target = "${config.home.homeDirectory}/${name}";
    }) homeFiles));

    home.homeFilesPackage = pkgs.runCommandLocal "home-files" {
      nativeBuildInputs = [ pkgs.xorg.lndir ];

M modules/tmpfiles.nix => modules/tmpfiles.nix +7 -25
@@ 26,14 26,6 @@ in {
        type = lib.types.listOf lib.types.str;
      };

      configurationFile = lib.mkOption {
        type = lib.types.str;
      };

      removalConfigurationFile = lib.mkOption {
        type = lib.types.str;
      };

      configurationPackage = lib.mkOption {
        type = lib.types.package;
        description = ''


@@ 68,31 60,21 @@ in {
      contents = if file.source != null then file.source else file.text;
    }))) tmpFiles;

    tmpfiles.configurationFile = pkgs.lib.concatStringsSep "\n" config.tmpfiles.configurationFileLines;

    tmpfiles.removalConfigurationFile = lib.concatStrings (builtins.map (file: tmpLib.mkRmTmpFile ({
      type = if file.type == "d" then "R" else "r";
      target = file.target;
    }) + "\n") tmpFiles);

    tmpfiles.configurationPackage = pkgs.runCommand "tmpfiles-configuration" {
      configuration = config.tmpfiles.configurationFile;
      removal = config.tmpfiles.removalConfigurationFile;
    } ''
      mkdir -p $out/share/tmpfiles $out/lib/tmpfiles.d
      echo -n "$configuration" > "$out/lib/tmpfiles.d/tmpfiles.conf"
      echo -n "$removal" > "$out/share/tmpfiles/rm-tmpfiles.conf"
    '';
    tmpfiles.configurationPackage = pkgs.writeTextFile {
      name = "100-tmpactivator.conf";
      destination = "/lib/tmpfiles.d/100-tmpactivator.conf";
      text = lib.concatStringsSep "\n" config.tmpfiles.configurationFileLines;
    };

    tmpfiles.activationPackage = pkgs.symlinkJoin {
      name = "tmpfiles-activation";

      paths = [
        (pkgs.writeShellScriptBin "activate" ''
          systemd-tmpfiles --create "${config.tmpfiles.configurationPackage}/lib/tmpfiles.d/tmpfiles.conf"
          systemd-tmpfiles --create "${config.tmpfiles.configurationPackage}/lib/tmpfiles.d/100-tmpactivator.conf"
        '')
        (pkgs.writeShellScriptBin "deactivate" ''
          systemd-tmpfiles --remove "${config.tmpfiles.configurationPackage}/share/tmpfiles/rm-tmpfiles.conf"
          systemd-tmpfiles --remove "${config.tmpfiles.configurationPackage}/lib/tmpfiles.d/100-tmpactivator.conf"
        '')
        config.tmpfiles.configurationPackage
      ];

Do not follow this link