Skip to content

Instantly share code, notes, and snippets.

@hdonnay
Created April 28, 2017 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save hdonnay/3802cf201d2c550027bc9606e57d5c0b to your computer and use it in GitHub Desktop.
Save hdonnay/3802cf201d2c550027bc9606e57d5c0b to your computer and use it in GitHub Desktop.
weird nix setup
{ nixpkgs }:
let
pkgs = nixpkgs { };
etcHook = {
name,
text,
exec ? false,
need ? []
}: let
destination = "/etc/profile.d/${name}.sh";
in pkgs.runCommandNoCC "${name}-custom"
{ inherit text exec;
propagatedUserEnvPkgs = need;
passAsFile = [ "text" ];
# Pointless to do this on a remote machine.
preferLocalBuild = true;
allowSubstitutes = false;
}
''
n=$out${destination}
mkdir -p "$(dirname "$n")"
if [ -e "$textPath" ]; then
mv "$textPath" "$n"
else
echo -n "$text" > "$n"
fi
(test -n "$exec" && chmod +x "$n") || true
if [ -n "$propagatedUserEnvPkgs" ]; then
mkdir -p "''${out:?out not set}/nix-support"
echo "$propagatedUserEnvPkgs" > "''${out:?out not set}/nix-support/propagated-user-env-packages"
fi
'';
custom-weechat = pkgs.weechat.override {
rubySupport = false;
tclSupport = false;
guileSupport = false;
};
bugwarrior-devel = pkgs.python27Packages.bugwarrior.overrideAttrs (old: rec {
propagatedBuildInputs = old.propagatedBuildInputs ++
[ pkgs.python27Packages.future ];
src = pkgs.fetchFromGitHub {
owner = "ralphbean";
repo = "bugwarrior";
rev = "83bf9539eabeddd5ebbb48bbe27a2a7e8fc3564f";
sha256 = "188x0mqw9rhpkid7c2x43v9avn1rn9sg0w5miq3w6j9gpgzjmpzj";
};
});
filter = path: type:
let f = baseNameOf path; in
f != "nix" &&
!pkgs.lib.hasPrefix ".git" f &&
true;
in
pkgs // rec {
plan9port = pkgs.plan9port.overrideAttrs (old: rec {
passAsFile = [ "text" ];
destination = "/etc/profile.d/${old.name}.sh";
preFixup = ''
n=$out${destination}
mkdir -p "$(dirname "$n")"
if [ -e "$textPath" ]; then
mv "$textPath" "$n"
else
echo -n "$text" > "$n"
fi
(test -n "$exec" && chmod +x "$n") || true
'';
text = ''
PLAN9=$HOME/.nix-profile/plan9
PATH=''${PATH:+$PATH:}$PLAN9/bin
export PLAN9 PATH
'';
});
Gitfiles = import ./nix/Gitfiles {
inherit plan9port;
stdenv = pkgs.stdenv;
fetchFromGitHub = pkgs.fetchFromGitHub;
};
aspell = etcHook {
name = "aspell";
need = [ pkgs.aspell pkgs.aspellDicts.en ];
text = ''
ASPELL_CONF="dict-dir $HOME/.nix-profile/lib/aspell;lang en_US;"
export ASPELL_CONF
'';
};
go = etcHook {
name = "go";
need = [ pkgs.go ];
text = ''
: ''${GOPATH:=$HOME}
: ''${GOBIN:=$HOME/bin}
export GOPATH GOBIN
'';
};
weechat = etcHook {
name = "weechat";
need = [ pkgs.weechat pkgs.lua52Packages.cjson aspell ];
text = ''
weechat() {
next=$(/usr/bin/which --skip-alias --skip-functions weechat)
echo "$next" | grep -q .nix-profile && \
export LUA_CPATH=$HOME/.nix-profile/lib/lua/5.2/?.so''${LUA_CPATH:+;$LUA_CPATH}
WEECHAT_PASSPHRASE=$(secret-tool lookup application weechat) exec $next "$@"
}
'';
};
common-configs = pkgs.stdenvNoCC.mkDerivation {
name = "common-configs";
propagatedBuildInputs = [ pkgs.stow ];
propagatedUserEnvPkgs = [ pkgs.stow ];
src = builtins.filterSource
(path: type: filter path type && !(type == "directory" && baseNameOf path == "scripts"))
./.;
buildPhase = ''
wd=$(pwd)
mkdir $wd/live
find . -maxdepth 1 -mindepth 1 -type d | \
grep -v 'work\|scripts\|nix' | \
while read d; do
stow --dir=$wd --target=$wd/live --stow $(basename $d)
done
echo $out > $wd/live/.config/store-address
'';
installPhase = ''
mkdir -p $out/etc/profile.d $out/cfg
cp -Lr . $out/cfg
mv $out/cfg/live $out/live
cat <<'EOF' >$out/etc/profile.d/stow-configs.sh
[ -e "$HOME/.config/store-address" ] && stow --dir=$(cat $HOME/.config/store-address) --target=$HOME --delete live
stow --dir=$(dirname $(realpath $HOME/.nix-profile/live)) --target=$HOME --stow live
# need to make sure systemd is using the latest unit files
systemctl --user daemon-reload
for unit in $HOME/.config/systemd/user/*.timer; do
systemctl --quiet --user enable $(basename $unit)
done
for unit in $HOME/.config/systemd/user/*.service; do
systemctl --quiet --user enable $(basename $unit)
done
EOF
'';
};
common-scripts = pkgs.stdenvNoCC.mkDerivation rec {
rLinks = [ "home" ];
name = "common-scripts";
# need both to get the paths fixed up
propagatedBuildInputs = [ plan9port pkgs.bash pkgs.perl pkgs.zsh ];
src = builtins.filterSource filter ./scripts;
installPhase = ''
install -d $out/bin
install -t $out/bin {sh,rc,perl,zsh}/*
export PATH=''${PATH:+$PATH:}${plan9port}/plan9/bin
'' + (pkgs.lib.concatMapStrings (x: "ln -s -v $out/bin/rr $out/bin/${x};\n") rLinks);
};
Env = [
common-configs
common-scripts
plan9port
Gitfiles
go
pkgs.vim
pkgs.git
pkgs.nix
pkgs.mosh
pkgs.tmux
pkgs.parallel
pkgs.jq
];
Mail = [
pkgs.mutt
pkgs.isync
pkgs.msmtp
pkgs.w3m
pkgs.mu
pkgs.poppler_utils
pkgs.lbdb
];
Task = [
pkgs.taskwarrior
bugwarrior-devel # needed for github enterprise support :/
];
}
args@{nixpkgs, ...}:
with (import ./common.nix { inherit nixpkgs; });
Env ++
Mail ++
Task ++
[
nghttp2
emacs25-nox
youtube-dl
newsbeuter
go2nix
nix-repl
u9fs
weechat
ncmpc
ag
mr
valgrind
nmap
rxvt_unicode-with-plugins
source-code-pro
unifont
go-font
ttf_bitstream_vera
mplus-outline-fonts
]
#!/bin/sh
nix-channel --update
test -f "$HOME/lib/$(hostname).nix" &&
nix-env -riE "(import $HOME/lib/$(hostname).nix)"
if test -f "$HOME/.nix-profile/etc/profile.d/stow-configs.sh"; then
echo swapping configs...
. "$HOME/.nix-profile/etc/profile.d/stow-configs.sh"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment