To have all internet-bound traffic go out through a Wireguard tunnel—and if Wireguard goes down, to not not have any internet-bound traffic leak through other interfaces—the easiest option is to use a container with a private network stack.
Configuring Wireguard using systemd-networkd on NixOS
Wireguard can be configured manually using systemd-networkd. This setup connects the Wireguard tunnel and sets up the necessary IP routes and firewall rules to send and accept all traffic over the Wireguard interface.
NixOS is my preferred system, so I’ve specified the configuration using NixOS here. Translation to a non-NixOS system should be straightforward.
xmonad Per-Layout Keybindings
In xmonad it can be useful to have different keybindings for different layouts, or respond to other events differently depending on the active layout. This can be accomplished by looking up the active layout in the hook. For this we define a utility function:
import XMonad
import qualified XMonad.StackSet as S
-- Get the name of the active layout.
getActiveLayoutDescription :: X String
getActiveLayoutDescription = do
workspaces <- gets windowset
return $ description . S.layout . S.workspace . S.current $ workspaces
Granting Capabilities Using capsh
On Linux it sometimes is useful to grant privileged capabilities to binaries without running them as root. Usually this is achieved by setting capabilities on the file through setcap. However, this has some complications with environment variables and capabilities inheritance of child processes. We can use capsh instead of setcap to achieve what we want using ambient capabilities.
Using setcap, we might add a capability to a file as follows:
$ sudo setcap cap_net_raw+epi /path/to/wine
Using Nix to create R virtual environments
Previously we saw how to use Nix to create virtual environments for Python. We can do the same for R. This means we can have different simultaneous R installations for different projects and keep the installed packages for each project separated. An important benefit of this is the ability to have different (incompatible) versions of the same packages for different projects.
The straightforward approach is to let Nix handle all R package management. However, sometimes it is useful to manage packages through the various R tools such as the built-in install.packages or install utilities provided by the devtools package.
Using Nix to create Python virtual environments
Nix is a great tool to set up development environments. It allows us to have simultaneous installations of various versions of tools—such as Python—required for our projects. This means Nix makes it easy to have Python 2.7 installed for one project, and Python 3.6 for another. Projects using the same Python version can have different Python packages.
Of course, Python’s VirtualEnv also enables us to do this. Nix, however, is more powerful. It can handle all our system’s packages; not just Python’s. This means it enables us to hold different versions of any dependency. For example, if one project requires a specific version of OpenCL and another project requires an incompatible version, VirtualEnv won’t help us. Nix will.
Rust Debug with Breakpoint Support in Visual Studio Code on Windows
Closed-Form Rocket Fuel Requirements
&SPL β Creating a simple imperative programming language
Creating Multiple Custom User Types Through Inheritance in Django
When developing applications in Django, the need might arise to customize the user model. Specifically, you might want to create different types of users. In my case, Iβm interested in creating a person user and a kit user. A person user can own multiple kit users, and both need to be able to authenticate to access an API. Luckily, Djangoβs authentication system is very flexible, and there are multiple ways to achieve this goal.