info: generate dir file directly in profile

This avoids the need for the activation block. The `dir` file is
instead built directly in the installed profile.
This commit is contained in:
Robert Helgesson 2020-09-18 13:58:37 +02:00
parent 92c682cd10
commit b3498cccb3
No known key found for this signature in database
GPG key ID: 36BDAA14C2797E89

View file

@ -1,22 +1,21 @@
# info.nix -- install texinfo, set INFOPATH, create `dir` file # info.nix -- install texinfo and create `dir` file
# This is a helper for the GNU info documentation system. By default, # This is a helper for the GNU info documentation system. By default,
# the `info` command (and the Info subsystem within Emacs) gives easy # the `info` command (and the Info subsystem within Emacs) gives easy
# access to the info files stored system-wide, but not info files in # access to the info files stored system-wide, but not info files in
# your ~/.nix-profile. # your ~/.nix-profile.
# We set $INFOPATH to include `/run/current-system/sw/share/info` and # Specifically, although info can then find files when you explicitly
# `~/.nix-profile/share/info` but it's not enough. Although info can # ask for them, it doesn't show them to you in the table of contents
# then find files when you explicitly ask for them, it doesn't show # on startup. To do that requires a `dir` file. NixOS keeps the
# them to you in the table of contents on startup. To do that requires # system-wide `dir` file up to date, but ignores files installed in
# a `dir` file. NixOS keeps the system-wide `dir` file up to date, but # user profiles.
# ignores home-installed packages.
# So this module contains an activation script that generates the # This module contains extra profile commands that generate the `dir`
# `dir` for your home profile. Then when you start info (and both # for your home profile. Then when you start info (and both `dir`
# `dir` files are in your $INFOPATH), it will *merge* the contents of # files are in your $INFOPATH), it will *merge* the contents of the
# the two files, showing you a unified table of contents for all # two files, showing you a unified table of contents for all packages.
# packages. This is really nice. # This is really nice.
{ config, lib, pkgs, ... }: { config, lib, pkgs, ... }:
@ -26,50 +25,39 @@ let
cfg = config.programs.info; cfg = config.programs.info;
# Indexes info files found in this location
homeInfoPath = "${config.home.profileDirectory}/share/info";
# Installs this package -- the interactive just means that it # Installs this package -- the interactive just means that it
# includes the curses `info` program. We also use `install-info` # includes the curses `info` program. We also use `install-info`
# from this package in the activation script. # from this package in the activation script.
infoPkg = pkgs.texinfoInteractive; infoPkg = pkgs.texinfoInteractive;
in { in {
options = { imports = [
programs.info = { (mkRemovedOptionModule [ "programs" "info" "homeInfoDirLocation" ] ''
enable = mkEnableOption "GNU Info"; The `dir` file is now generated as part of the Home Manager profile and
will no longer be placed in your home directory.
'')
];
homeInfoDirLocation = mkOption { options.programs.info.enable = mkEnableOption "GNU Info";
default = "\${XDG_CACHE_HOME:-$HOME/.cache}/info";
description = ''
Directory in which to store the info <filename>dir</filename>
file within your home.
'';
};
};
};
config = mkIf cfg.enable { config = mkIf cfg.enable {
home.sessionVariables.INFOPATH = home.packages = [
"${cfg.homeInfoDirLocation}\${INFOPATH:+:}\${INFOPATH}"; infoPkg
home.activation.createHomeInfoDir = # Make sure the target directory is a real directory.
hm.dag.entryAfter [ "installPackages" ] '' (pkgs.runCommandLocal "dummy-info-dir1" { } "mkdir -p $out/share/info")
oPATH=$PATH (pkgs.runCommandLocal "dummy-info-dir2" { } "mkdir -p $out/share/info")
export PATH="${lib.makeBinPath [ pkgs.gzip ]}''${PATH:+:}$PATH" ];
$DRY_RUN_CMD mkdir -p "${cfg.homeInfoDirLocation}"
$DRY_RUN_CMD rm -f "${cfg.homeInfoDirLocation}/dir"
if [[ -d "${homeInfoPath}" ]]; then
find -L "${homeInfoPath}" \( -name '*.info' -o -name '*.info.gz' \) \
-exec $DRY_RUN_CMD ${infoPkg}/bin/install-info '{}' \
"${cfg.homeInfoDirLocation}/dir" \;
fi
export PATH="$oPATH"
unset oPATH
'';
home.packages = [ infoPkg ];
home.extraOutputsToInstall = [ "info" ]; home.extraOutputsToInstall = [ "info" ];
home.extraProfileCommands = let infoPath = "$out/share/info";
in ''
if [[ -w "${infoPath}" && ! -e "${infoPath}/dir" ]]; then
PATH="${lib.makeBinPath [ pkgs.gzip infoPkg ]}''${PATH:+:}$PATH" \
find -L "${infoPath}" \( -name '*.info' -o -name '*.info.gz' \) \
-exec install-info '{}' "${infoPath}/dir" ';'
fi
'';
}; };
} }