diff --git a/examples/example.nix b/examples/example.nix index 4a78aa30..5f23699d 100644 --- a/examples/example.nix +++ b/examples/example.nix @@ -11,6 +11,10 @@ pkgs.fd ]; + shellAliases = { + nr = "nixpkgs-review pr"; + }; + etc = { foo = { text = '' diff --git a/nix/modules/environment.nix b/nix/modules/environment.nix index 3cccf661..168d4f1e 100644 --- a/nix/modules/environment.nix +++ b/nix/modules/environment.nix @@ -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 { @@ -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 = @@ -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 = diff --git a/test/nix/modules/default.nix b/test/nix/modules/default.nix index 0b3c6541..cfa9348c 100644 --- a/test/nix/modules/default.nix +++ b/test/nix/modules/default.nix @@ -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;