Skip to content

Commit

Permalink
environment.aliases: add module
Browse files Browse the repository at this point in the history
  • Loading branch information
mkg20001 committed Feb 3, 2025
1 parent f4bbf68 commit 86140c4
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 0 deletions.
44 changes: 44 additions & 0 deletions nixos/modules/misc/aliases.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
{ config, lib, pkgs, ... }:

with lib;

let
cfg = config.environment.aliases;

createScript = key: value:
let
normalizedKey = key; # TODO: normalize
script = ''#!${pkgs.bash}/bin/bash
set -euo pipefail
exec ${value}
'';
in
''
echo ${escapeShellArg script} > $out/bin/${escapeShellArg normalizedKey}
chmod +x $out/bin/${escapeShellArg normalizedKey}
'';
in
{
options.environment.aliases = mkOption {
type = types.attrsOf types.str;
description = "Global binary aliases to create";
default = {};
};

config = mkIf (cfg != {}) {
environment.systemPackages = [
(with pkgs; stdenv.mkDerivation {
name = "aliases";

dontUnpack = true;

installPhase = ''
mkdir -p $out/bin
${builtins.concatStringsSep "\n" (forEach (builtins.attrNames cfg) (key: createScript key cfg.${key}))}
'';
})
];
};
}
1 change: 1 addition & 0 deletions nixos/modules/module-list.nix
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
./i18n/input-method/uim.nix
./image/images.nix
./installer/tools/tools.nix
./misc/aliases.nix
./misc/assertions.nix
./misc/crashdump.nix
./misc/documentation.nix
Expand Down

0 comments on commit 86140c4

Please sign in to comment.