diff --git a/base.nix b/base.nix index c4d7711..5fe4faf 100644 --- a/base.nix +++ b/base.nix @@ -16,6 +16,7 @@ #boot.kernelPackages = pkgs.linuxPackages_latest; services.openssh.enable = true; + programs.mosh.enable = true; } diff --git a/flake.nix b/flake.nix index 49297ba..390770a 100644 --- a/flake.nix +++ b/flake.nix @@ -19,6 +19,7 @@ outputs = { self, home-manager, nixpkgs, neovim-nightly-overlay, nur, ... }@inputs: let utils = import ./utils.nix { inherit nixpkgs home-manager inputs; }; + pkgs = import nixpkgs {}; in with utils; { @@ -30,6 +31,8 @@ (builtins.attrNames (builtins.readDir ./modules))); nixosConfigurations = builtins.mapAttrs (name: value: (mkMachine name value self.nixosModules)) (importConfig ./machines); + + #legacyPackages."x86_64-linux"."mosh" = import ./packages/mosh/default.nix; }; diff --git a/machines/newton.nix b/machines/newton.nix index a02b01f..2441449 100644 --- a/machines/newton.nix +++ b/machines/newton.nix @@ -65,7 +65,6 @@ in - programs.mosh.enable = true; programs.fish.enable = true; users.defaultUserShell = pkgs.fish; diff --git a/packages/mosh/default.nix b/packages/mosh/default.nix new file mode 100644 index 0000000..5febad7 --- /dev/null +++ b/packages/mosh/default.nix @@ -0,0 +1,76 @@ +#{ lib, stdenv, fetchFromGithub, fetchpatch, zlib, protobuf, ncurses, pkg-config +#, makeWrapper, perlPackages, openssl, autoreconfHook, openssh, bash-completion +#, withUtempter ? stdenv.isLinux, libutempter }: + +stdenv.mkDerivation rec { + pname = "mosh"; + version = "1.3.2"; + + src = fetchFromGitHub { + owner = "mobile-shell"; + repo = pname; + rev = "378dfa6aa5778cf168646ada7f52b6f4a8ec8e41"; + sha256 = "05hjhlp6lk8yjcy59zywpf0r6s0h0b9zxq0lw66dh9x8vxrhaq6s"; + }; + + nativeBuildInputs = [ autoreconfHook pkg-config makeWrapper ]; + buildInputs = [ protobuf ncurses zlib openssl bash-completion ] + ++ (with perlPackages; [ perl IOTty ]) + ++ lib.optional withUtempter libutempter; + + enableParallelBuilding = true; + + patches = [ + ./ssh_path.patch + ./mosh-client_path.patch + ./utempter_path.patch + # Fix w/c++17, ::bind vs std::bind + (fetchpatch { + url = "https://github.com/mobile-shell/mosh/commit/e5f8a826ef9ff5da4cfce3bb8151f9526ec19db0.patch"; + sha256 = "15518rb0r5w1zn4s6981bf1sz6ins6gpn2saizfzhmr13hw4gmhm"; + }) + # Fix build with bash-completion 2.10 + ./bash_completion_datadir.patch + ]; + + postPatch = '' + # Fix build with Xcode 12.5 toolchain/case-insensitive filesystems + # Backport of https://github.com/mobile-shell/mosh/commit/12199114fe4234f791ef4c306163901643b40538; + # remove on next upstream release. + patch -p0 < ${fetchpatch { + url = "https://raw.githubusercontent.com/macports/macports-ports/70ca3f65e622c17582fd938602d800157ed951c3/net/mosh/files/patch-version-subdir.diff"; + sha256 = "1yyh6d07y9zbdx4fb0r56zkq9nd9knwzj22v4dfi55k4k42qxapd"; + }} + + substituteInPlace scripts/mosh.pl \ + --subst-var-by ssh "${openssh}/bin/ssh" \ + --subst-var-by mosh-client "$out/bin/mosh-client" + ''; + + configureFlags = [ "--enable-completion" ] + ++ lib.optional withUtempter "--with-utempter"; + + postInstall = '' + wrapProgram $out/bin/mosh --prefix PERL5LIB : $PERL5LIB + ''; + + CXXFLAGS = lib.optionalString stdenv.cc.isClang "-std=c++11"; + + meta = with lib; { + homepage = "https://mosh.org/"; + description = "Mobile shell (ssh replacement)"; + longDescription = '' + Remote terminal application that allows roaming, supports intermittent + connectivity, and provides intelligent local echo and line editing of + user keystrokes. + + Mosh is a replacement for SSH. It's more robust and responsive, + especially over Wi-Fi, cellular, and long-distance links. + ''; + license = licenses.gpl3Plus; + maintainers = with maintainers; [ viric SuperSandro2000 ]; + platforms = platforms.unix; + }; +} + + diff --git a/utils.nix b/utils.nix index 84d7457..095a1d4 100644 --- a/utils.nix +++ b/utils.nix @@ -19,6 +19,22 @@ in home-manager.useUserPackages = true; nixpkgs.overlays = [ inputs.neovim-nightly-overlay.overlay + (final: prev: + { + mosh = prev.mosh.overrideAttrs (old: { + patches = []; + postPatch = ''''; + buildInputs = with prev; [ protobuf ncurses zlib openssl ] + ++ (with perlPackages; [ perl IOTty ]) + ++ lib.optional true libutempter; + src = prev.fetchFromGitHub { + owner = "mobile-shell"; + repo = "mosh"; + rev = "378dfa6aa5778cf168646ada7f52b6f4a8ec8e41"; + sha256 = "LJssBMrICVgaZtTvZTO6bYMFO4fQ330lIUkWzDSyf7o="; + }; + }); + }) ]; } ];