tvl-depot/tools/eaglemode/default.nix
Vincent Ambo 8c8861cb3c feat(tools/eaglemode): add function for creating etc dir
Adds an eaglemode.etcDir function which creates a directory structure suitable
for use with EM_USER_CONFIG_DIR.

The catch is that Eagle Mode requires this to be always writable, so it isn't
possible to just point the environment variable at the Nix store and launch it
from there.

The idea of this function is to make it possible to reuse it in a wrapper
script, a home manager module, a NixOS module or whatever that would make it
possible to provide the result to Eagle Mode in a mutable location.

Change-Id: I95c8b16c6c6fe8510ce9759c9d9b9e36e836e290
Reviewed-on: https://cl.tvl.fyi/c/depot/+/12368
Tested-by: BuildkiteCI
Reviewed-by: tazjin <tazjin@tvl.su>
Reviewed-by: azahi <azat@bahawi.net>
2024-08-30 13:30:07 +00:00

74 lines
2.5 KiB
Nix

# Helper functions for extending Eagle Mode with useful stuff.
#
# Eagle Mode's customisation usually expects people to copy the entire
# configuration into their user folder, which we can automate fairly easily
# using Nix, letting users choose whether to keep upstream config or not.
{ depot, lib, pkgs, ... }:
let
mkDesc = d: lib.concatMapStringsSep "\n"
(x: "# Descr =${x}")
(builtins.filter (s: s != "") (lib.splitString "\n" d));
in
rec {
# mkCommand creates an Eagle Mode command for the file browser.
#
# Commands are basically little Perl scripts with a command standard library
# available. They receive the user's selected target from Eagle Mode.
mkCommand =
{
# Name of the command.
name
, # User-facing description, displayed in Eagle Mode UI. Can be multi-line.
description
, # Verbatim Perl code of the command. Command library is already available.
code
, # Caption for the UI button (defaults to name).
caption ? name
, icon ? "terminal.tga"
, # TODO: what's a good default?
hotkey ? ""
, order ? 1.0
}: pkgs.writeTextDir "emFileMan/Commands/${name}.pl" (''
#!${pkgs.perl}/bin/perl
#[[BEGIN PROPERTIES]]
# Type = Command
# Interpreter = perl
# DefaultFor = directory
# Caption = ${caption}
# Order = ${toString order}
# Icon = ${icon}
''
+ (lib.optionalString (description != "") "${mkDesc description}\n")
+ (lib.optionalString (hotkey != "") "# Hotkey = ${hotkey}\n")
+ ''
#[[END PROPERTIES]]
use strict;
use warnings;
BEGIN { require "$ENV{'EM_DIR'}/res/emFileMan/scripts/cmd-util.pl"; }
${if builtins.isString code
then code
else (if builtins.isPath code
then builtins.readFile code
else throw "code must be a string (literal code) or path to file")}
'');
# etcDir creates a directory layout suitable for use in the EM_USER_CONFIG_DIR
# environment variable.
#
# Note that Eagle Mode requires the value of that variable to be mutable at
# runtime (it is the same place where it persists all of its user-controlled
# state), so the results of this function can not be used directly.
etcDir =
{ eaglemode ? pkgs.eaglemode
, extraPaths ? [ ]
}: pkgs.runCommand "eaglemode-config" { } ''
mkdir $out
${
lib.concatMapStringsSep "\n" (s: "cp -rT ${s} $out/\nchmod -R u+rw $out/\n") ([ "${eaglemode}/etc"] ++ extraPaths)
}
'';
}