From e7f6744be5460cb4b34086ec8e8991bb311f7144 Mon Sep 17 00:00:00 2001 From: Stefan Junker Date: Sun, 4 Nov 2018 22:04:22 +0100 Subject: [PATCH] dotfiles/vcsh: populate nix store with dotfiles mirror --- Justfile | 3 +- nix/home-manager/profiles/dotfiles.nix | 24 ++---------- nix/home-manager/profiles/dotfiles/.gitignore | 1 + .../profiles/dotfiles/vcsh.tmpl.nix | 38 +++++++++++++++++++ nix/scripts/pre-eval-fixed.sh | 5 +++ 5 files changed, 49 insertions(+), 22 deletions(-) create mode 100644 nix/home-manager/profiles/dotfiles/.gitignore create mode 100644 nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix create mode 100755 nix/scripts/pre-eval-fixed.sh diff --git a/Justfile b/Justfile index 34fa1e5..eba55da 100755 --- a/Justfile +++ b/Justfile @@ -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}}) _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}} - # Rebulid this device's NixOS rebuild-this-device rebuildarg="dry-activate": #!/usr/bin/env bash diff --git a/nix/home-manager/profiles/dotfiles.nix b/nix/home-manager/profiles/dotfiles.nix index e0c18f6..2609ee2 100644 --- a/nix/home-manager/profiles/dotfiles.nix +++ b/nix/home-manager/profiles/dotfiles.nix @@ -4,28 +4,10 @@ }: let - repoHttps = "https://gitlab.com/steveeJ/dotfiles.git"; - repoSsh = "git@gitlab.com:/steveeJ/dotfiles.git"; + vcshActivationScript = pkgs.callPackage ./dotfiles/vcsh.nix {}; + in { home.activation.vcsh = config.lib.dag.entryAfter["linkGeneration"] '' - $DRY_RUN_CMD ${pkgs.writeScript "activation-script" '' - 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 - ''}; + $DRY_RUN_CMD ${vcshActivationScript} ''; } diff --git a/nix/home-manager/profiles/dotfiles/.gitignore b/nix/home-manager/profiles/dotfiles/.gitignore new file mode 100644 index 0000000..f3f979e --- /dev/null +++ b/nix/home-manager/profiles/dotfiles/.gitignore @@ -0,0 +1 @@ +vcsh.nix diff --git a/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix b/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix new file mode 100644 index 0000000..fe99c8d --- /dev/null +++ b/nix/home-manager/profiles/dotfiles/vcsh.tmpl.nix @@ -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 + '' diff --git a/nix/scripts/pre-eval-fixed.sh b/nix/scripts/pre-eval-fixed.sh new file mode 100755 index 0000000..0b22a4f --- /dev/null +++ b/nix/scripts/pre-eval-fixed.sh @@ -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 {}' --arg config 'null' 2>&1 | grep -oE '[0-9a-z]{52}' | head -n1) +sed -E "s/0{52}/${hash}/" ${INFILE} > ${OUTFILE}