diff --git a/cli/default.nix b/cli/default.nix index 66b56558..e43a4b28 100644 --- a/cli/default.nix +++ b/cli/default.nix @@ -1,7 +1,7 @@ { config, lib, pkgs, ... }: { - imports = [ ./neovim ./kakoune ]; + imports = [ ./lorri.nix ./neovim ./kakoune ]; home.packages = with pkgs; [ bfs cachix @@ -32,7 +32,6 @@ enable = true; enableBashIntegration = true; enableZshIntegration = true; - stdlib = lib.readFile ./use_nix.sh; }; programs.fzf = { changeDirWidgetCommand = "bfs -type d"; diff --git a/cli/lorri.nix b/cli/lorri.nix new file mode 100644 index 00000000..68d12570 --- /dev/null +++ b/cli/lorri.nix @@ -0,0 +1,38 @@ +{ pkgs, ... }: +let lorri = pkgs.channels.lorri; +in { + home.packages = [ lorri ]; + programs.direnv = { + stdlib = '' + use_nix() { + eval "$(lorri direnv)" + } + ''; + }; + systemd.user.sockets.lorri = { + Unit = { Description = "lorri build daemon"; }; + Socket = { ListenStream = "%t/lorri/daemon.socket"; }; + Install = { WantedBy = [ "sockets.target" ]; }; + }; + systemd.user.services.lorri = + let path = with pkgs; lib.makeBinPath [ nix gnutar git mercurial ]; + in { + Unit = { + Description = "lorri build daemon"; + Documentation = "https://github.com/target/lorri"; + ConditionUser = "!@system"; + Requires = "lorri.socket"; + After = "lorri.socket"; + RefuseManualStart = true; + }; + + Service = { + ExecStart = "${lorri}/bin/lorri daemon"; + PrivateTmp = true; + ProtectSystem = "strict"; + WorkingDirectory = "%h"; + Restart = "on-failure"; + Environment = "PATH=${path} RUST_BACKTRACE=1"; + }; + }; +} diff --git a/cli/use_nix.sh b/cli/use_nix.sh deleted file mode 100644 index 2dcfec8a..00000000 --- a/cli/use_nix.sh +++ /dev/null @@ -1,63 +0,0 @@ -use_nix() { - local path="$(nix-instantiate --find-file nixpkgs)" - - if [ -f "${path}/.version-suffix" ]; then - local version="$(< $path/.version-suffix)" - elif [ -f "${path}/.git" ]; then - local version="$(< $(< ${path}/.git/HEAD))" - fi - - local cache=".direnv/cache-${version:-unknown}" - - local update_drv=0 - if [[ ! -e "$cache" ]] || \ - [[ "$HOME/.direnvrc" -nt "$cache" ]] || \ - [[ .envrc -nt "$cache" ]] || \ - [[ default.nix -nt "$cache" ]] || \ - [[ shell.nix -nt "$cache" ]]; - then - [ -d .direnv ] || mkdir .direnv - nix-shell --show-trace --pure "$@" --run "\"$direnv\" dump bash" > "$cache" - update_drv=1 - else - log_status using cached derivation - fi - local term_backup=$TERM path_backup=$PATH - if [ -n ${TMPDIR+x} ]; then - local tmp_backup=$TMPDIR - fi - - eval "$(< $cache)" - export PATH=$PATH:$path_backup TERM=$term_backup TMPDIR=$tmp_backup - if [ -n ${tmp_backup+x} ]; then - export TMPDIR=${tmp_backup} - else - unset TMPDIR - fi - - # `nix-shell --pure` sets invalid ssl certificate paths - if [ "${SSL_CERT_FILE:-}" = /no-cert-file.crt ]; then - unset SSL_CERT_FILE - fi - if [ "${NIX_SSL_CERT_FILE:-}" = /no-cert-file.crt ]; then - unset NIX_SSL_CERT_FILE - fi - - # This part is based on https://discourse.nixos.org/t/what-is-the-best-dev-workflow-around-nix-shell/418/4 - if [ "$out" ] && (( $update_drv )); then - local drv_link=".direnv/drv" - local drv="$(nix show-derivation $out | grep -E -o -m1 '/nix/store/.*.drv')" - local stripped_pwd=${PWD/\//} - local escaped_pwd=${stripped_pwd//-/--} - local escaped_pwd=${escaped_pwd//\//-} - ln -fs "$drv" "$drv_link" - ln -fs "$PWD/$drv_link" "/nix/var/nix/gcroots/per-user/$LOGNAME/$escaped_pwd" - log_status renewed cache and derivation link - fi - - if [[ $# = 0 ]]; then - watch_file default.nix - watch_file shell.nix - fi -} - diff --git a/nix-channels b/nix-channels index 28f9cbed..c122a71e 100644 --- a/nix-channels +++ b/nix-channels @@ -1,3 +1,4 @@ https://github.com/Infinisil/all-hies/archive/master.tar.gz all-hies https://github.com/rycee/home-manager/archive/release-19.09.tar.gz home-manager +https://github.com/target/lorri/archive/rolling-release.tar.gz lorri https://nixos.org/channels/nixos-unstable nixos-unstable diff --git a/overlays/channels.nix b/overlays/channels.nix index 643f2191..2026994d 100644 --- a/overlays/channels.nix +++ b/overlays/channels.nix @@ -1,6 +1,7 @@ self: super: { channels = { all-hies = import { }; + lorri = import { }; nixos-unstable = import { }; }; }