From a649086767928e5c3f3f10c552d6baf951c08e50 Mon Sep 17 00:00:00 2001 From: Gregor Kleen Date: Fri, 13 Apr 2018 12:25:38 +0200 Subject: Refine rebuild-system --- nix/rebuild-system.nix | 24 +++++++++++++++--------- rebuild-system | 13 +++++++------ 2 files changed, 22 insertions(+), 15 deletions(-) diff --git a/nix/rebuild-system.nix b/nix/rebuild-system.nix index 5c65e88..9e8f602 100644 --- a/nix/rebuild-system.nix +++ b/nix/rebuild-system.nix @@ -1,22 +1,28 @@ { stdenv , fetchgit , makeWrapper -, git +, zsh, git }: stdenv.mkDerivation rec { - inherit git; name = "rebuild-system-${version}"; - version = "0.1"; + version = "0.2"; src = ../rebuild-system; + buildInputs = [ makeWrapper ]; - phases = ["installPhase"]; + + phases = [ "buildPhase" "installPhase" ]; + + inherit zsh git; + + buildPhase = '' + substituteAll $src rebuild-system + ''; + installPhase = '' mkdir -p $out/bin - cp $src $out/bin/rebuild-system - chmod +x $out/bin/rebuild-system - wrapProgram $out/bin/rebuild-system \ - --prefix PATH : /var/setuid-wrappers \ - --prefix PATH : ${git}/bin + + install -m 755 -t $out/bin \ + rebuild-system ''; } diff --git a/rebuild-system b/rebuild-system index 8f116e3..cd99ae5 100644 --- a/rebuild-system +++ b/rebuild-system @@ -1,11 +1,12 @@ -#!/usr/bin/env bash +#!@zsh@/bin/zsh -if [[ "$USER" != "root" ]]; then +set -o errexit + +if [[ $(whoami) != "root" ]]; then exec sudo -- $0 $@ fi -path=/etc/nixos +configPath=$(nix-instantiate --eval --expr '') -git -C $path pull && \ - git -C $path submodule update && \ - nixos-rebuild $@ +@git@/bin/git -C ${configPath:h} pull +nixos-rebuild $@ -- cgit v1.2.3