Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions examples/example.nix
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
pkgs.fd
];

shellAliases = {
nr = "nixpkgs-review pr";
};

etc = {
foo = {
text = ''
Expand Down
28 changes: 28 additions & 0 deletions nix/modules/environment.nix
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,15 @@
...
}:

let
cfg = config.environment;

aliases = builtins.concatStringsSep "\n" (
lib.mapAttrsToList (k: v: "alias -- ${k}=${lib.escapeShellArg v}") (
lib.filterAttrs (k: v: v != null) cfg.shellAliases
)
);
in
{
options.environment = {
systemPackages = lib.mkOption {
Expand All @@ -16,6 +25,21 @@
type = lib.types.listOf lib.types.str;
default = [ ];
};

shellAliases = lib.mkOption {
type = with lib.types; attrsOf (nullOr (either str path));
default = { };
example = {
nr = "nixpkgs-review pr";
".." = "cd ..";
};
description = ''
An attribute set that maps aliases (the top level attribute names in
this option) to command strings or directly to build outputs. The
aliases are added to all users' shells.
Aliases mapped to `null` are ignored.
'';
};
};

config =
Expand All @@ -33,6 +57,10 @@
export PATH=${pathDir}/bin/:''${PATH}
'';

"profile.d/shell-aliases.sh".source = pkgs.writeText "shell-aliases.sh" ''
${aliases}
'';

# TODO: figure out how to properly add fish support. We could start by
# looking at what NixOS and HM do to set up the fish env.
#"fish/conf.d/system-manager-path.fish".source =
Expand Down
2 changes: 2 additions & 0 deletions test/nix/modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -321,6 +321,8 @@ forEachUbuntuImage "example" {
vm.succeed("bash --login -c 'realpath $(which rg) | grep -F ${hostPkgs.ripgrep}/bin/rg'")
vm.succeed("bash --login -c 'realpath $(which fd) | grep -F ${hostPkgs.fd}/bin/fd'")

vm.succeed("bash --login -c 'type nr'")

${system-manager.lib.activateProfileSnippet {
node = "vm";
profile = newConfig;
Expand Down