Bloc notes | NixOS writeScript exemple


Posted on July 1, 2017 by Alex comments [nixos, proxy]

Exemple d'un petit script qui permet d'ouvrir un tunnel ssh et de l'utiliser comme proxy socks dans google-chrome. Le code sur GitHub

Le default.nix

{ pkgs ? import <nixpkgs> {} }:

with pkgs;

let
  sshd = "schrome";
  exec = pkgs.writeScript "schrome" ''
#!/usr/bin/env bash
ps -eo pid,args | grep "ssh -D 3138" | awk '{ print $1 }' | sed '$ d' | xargs kill
ssh -D 3138 -f -C -q -N ${sshd}
google-chrome-stable --proxy-server="socks://127.0.0.1:3138" $@
'';
in

  stdenv.mkDerivation rec {
    name = "schrome";
    src = ./.;
    buildInstall = [ google-chrome ];
    installPhase = ''
mkdir -p $out/bin
ln -s ${exec} $out/bin/schrome
    '';
}

Config

In your ~/.ssh/config

Host schrome
  HostName my.remote.server

Build

nix-build

Test

./result/bin/schrome

Like it ? install !

nix-env -f . -i
schrome