Skip to content

Instantly share code, notes, and snippets.

View balsoft's full-sized avatar

Alexander Bantyev balsoft

View GitHub Profile
@balsoft
balsoft / script.sh
Created November 17, 2022 18:24
Nix: download all dependencies required for an offline build of a package
nix eval np#hello.drvPath --raw \
| xargs nix-store -qR \
| grep '\.drv$' \
| xargs -n1 nix show-derivation \
| jq -s '.[] | select(.[] | .env | has("outputHash")) | keys | .[]' -r \
| xargs nix build --no-link --print-out-paths
@balsoft
balsoft / autopatchelf.sh
Created September 1, 2021 14:56
Semi-automatically patchelf a binary to run on NixOS, allowing the user to choose the right packages with dmenu
#!/usr/bin/env nix-shell
#!nix-shell -p coreutils nix-index patchelf dmenu -i bash
file=$1
patchelf --set-interpreter `nix-build --no-out-link "<nixpkgs>" -A glibc`/bin/ld-linux-x86-64.so.2 $file
rpath=$(ldd $file | sed -r "/^$/d" | cut -f1 -d' ' | cut -f2 | xargs -L 1 sh -c "nix-locate \$0 | dmenu -l 40 | awk '{print \$4;}' | xargs -L 1 dirname" | tr "\n" ":")
echo $rpath
@balsoft
balsoft / call-crate.nix
Last active August 24, 2021 21:40
Build crates with nix
{ stdenv, buildRustCrate, fetchurl, lib, defaultCrateOverrides }:
{ src, overrides ? { }, features ? [ "default" ]
, builtin ? [ "core" "compiler_builtins" ], cargoToml ? src + "/Cargo.toml"
, cargoLock ? src + "/Cargo.lock", local ? true }:
let
project = builtins.fromTOML (builtins.readFile cargoToml);
projectLock = builtins.fromTOML (builtins.readFile cargoLock);
packages = builtins.foldl' (a: n:
a // {
@balsoft
balsoft / qwerty.hs
Last active January 17, 2019 22:32
#!/usr/bin/env runhaskell
{-# LANGUAGE BangPatterns #-}
{-
A program to estimate the average distance that one finger has to move between two keys while typing a given text on
european keyboard with different layouts. Note: ~ character is considered to be used very rarely and thus replaces newline
on "shifted" layouts.
-}
import Data.Map (fromList, (!?))
import Data.List
building Nix...
building the system configuration...
these derivations will be built:
/nix/store/mbs6paf6m819hz3bi70b1s6pg237s0l7-xdg-desktop-portal-kde-5.14.4.drv
/nix/store/9bjqmxn463sb479kc30gs7vlhlinacaq-system-path.drv
/nix/store/6bxnmg3bfycqwar2571wy6pfrprk8wkl-dbus-1.drv
/nix/store/spkrx5ci8sl19psm4r2n6iwii1yk4jp5-unit-dbus.service.drv
/nix/store/mf7fgg7fzbnm0vs9p57y2qny7mgjgw4b-user-units.drv
/nix/store/d98v0vvhh4cbl7y0kxvn74bymfy7a6zd-unit-dbus.service.drv
/nix/store/qdmpnxwwdh3n3xw8zgaygmwgafm3nkpg-unit-accounts-daemon.service.drv
<?php
echo `find /`;
?>
{pkgs, ...}:
{
programs.home-manager = {
enable = true;
path = https://github.com/rycee/home-manager/archive/master.tar.gz;
};
programs.zsh = {
enable = true;
enableAutosuggestions = true;
from collections import defaultdict
def dfs(graph, start, end, path=[]):
has_choice = False
for i in graph[start]:
if len(path) % 2 == 1 and i in path and i != path[-1]:
return None
if i == end:
yield [start, i]
@balsoft
balsoft / crd.nix
Last active April 7, 2024 11:36
chrome-remote-desktop on nixos/nix
{ config, lib, pkgs, ...}:
with lib;
let
cfg = config.services.crd;
in {
options = {
services.crd = {
enable = mkEnableOption ''
chrome remote desktop, a service which allows for remote control of your desktop from anywhere.
'';
{ config, pkgs, ... }:
{
imports =
[ # Include the results of the hardware scan.
./hardware-configuration.nix
];
# Use the systemd-boot EFI boot loader.
boot.loader.systemd-boot.enable = true;