dotfiles/vcsh: populate nix store with dotfiles mirror

This commit is contained in:
steveej 2018-11-04 22:04:22 +01:00
parent a71fe67e78
commit e7f6744be5
5 changed files with 49 additions and 22 deletions

View file

@ -7,9 +7,10 @@ _device action dir +moreargs="":
sudo $(set -x; nix-build --no-link --show-trace $(dirname {{dir}})/default.nix -A {{action}} --argstr dir {{dir}} {{moreargs}}) sudo $(set -x; nix-build --no-link --show-trace $(dirname {{dir}})/default.nix -A {{action}} --argstr dir {{dir}} {{moreargs}})
_rebuild-device dir rebuildarg="dry-activate" +moreargs="": _rebuild-device dir rebuildarg="dry-activate" +moreargs="":
#!/usr/bin/env bash
nix/scripts/pre-eval-fixed.sh nix/home-manager/profiles/dotfiles/vcsh{.tmpl,}.nix
just -v _device rebuild {{dir}} --argstr rebuildarg {{rebuildarg}} {{moreargs}} just -v _device rebuild {{dir}} --argstr rebuildarg {{rebuildarg}} {{moreargs}}
# Rebulid this device's NixOS # Rebulid this device's NixOS
rebuild-this-device rebuildarg="dry-activate": rebuild-this-device rebuildarg="dry-activate":
#!/usr/bin/env bash #!/usr/bin/env bash

View file

@ -4,28 +4,10 @@
}: }:
let let
repoHttps = "https://gitlab.com/steveeJ/dotfiles.git"; vcshActivationScript = pkgs.callPackage ./dotfiles/vcsh.nix {};
repoSsh = "git@gitlab.com:/steveeJ/dotfiles.git";
in { in {
home.activation.vcsh = config.lib.dag.entryAfter["linkGeneration"] '' home.activation.vcsh = config.lib.dag.entryAfter["linkGeneration"] ''
$DRY_RUN_CMD ${pkgs.writeScript "activation-script" '' $DRY_RUN_CMD ${vcshActivationScript}
set -e
export HOST=$(hostname -s)
function set_remotes {
${pkgs.vcsh}/bin/vcsh dotfiles remote set-url origin ${repoHttps}
${pkgs.vcsh}/bin/vcsh dotfiles remote set-url --push origin ${repoSsh}
}
if ! test -d $HOME/.config/vcsh/repo.d/dotfiles.git; then
echo Cloning dotfiles for $HOST...
${pkgs.vcsh}/bin/vcsh clone -b $HOST ${repoHttps}
set_remotes
else
echo Updating dotfiles for $HOST...
set_remotes
${pkgs.vcsh}/bin/vcsh pull $HOST
fi
''};
''; '';
} }

View file

@ -0,0 +1 @@
vcsh.nix

View file

@ -0,0 +1,38 @@
{ pkgs
, repoHttps ? "https://gitlab.com/steveeJ/dotfiles.git"
, repoSsh ? "git@gitlab.com:/steveeJ/dotfiles.git"
, ...
}:
let
repoHttps = "https://gitlab.com/steveeJ/dotfiles.git";
repoSsh = "git@gitlab.com:/steveeJ/dotfiles.git";
repoBareLocal = pkgs.runCommand "fetchbare" {
outputHashMode = "recursive";
outputHashAlgo = "sha256";
outputHash = "0000000000000000000000000000000000000000000000000000";
} ''
export GIT_SSL_CAINFO=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
export SSL_CERT_FILE=${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt
${pkgs.git}/bin/git clone --mirror ${repoHttps} $out
'';
in pkgs.writeScript "activation-script" ''
export HOST=$(hostname -s)
function set_remotes {
${pkgs.vcsh}/bin/vcsh dotfiles remote set-url origin $1
${pkgs.vcsh}/bin/vcsh dotfiles remote set-url --push origin $2
}
if ! test -d $HOME/.config/vcsh/repo.d/dotfiles.git; then
echo Cloning dotfiles for $HOST...
${pkgs.vcsh}/bin/vcsh clone -b $HOST ${repoBareLocal}
set_remotes ${repoHttps} ${repoSsh}
else
set_remotes ${repoBareLocal} ${repoSsh}
echo Updating dotfiles for $HOST...
${pkgs.vcsh}/bin/vcsh pull $HOST || true
set_remotes ${repoHttps} ${repoSsh}
fi
''

5
nix/scripts/pre-eval-fixed.sh Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env bash
INFILE="${1:?Please set arg1 to INFILE}"
OUTFILE="${2:?Please set arg2 to OUTFILE}"
hash=$(nix-build ${INFILE} --arg pkgs 'import <nixpkgs> {}' --arg config 'null' 2>&1 | grep -oE '[0-9a-z]{52}' | head -n1)
sed -E "s/0{52}/${hash}/" ${INFILE} > ${OUTFILE}