Rider home-manager module (#4)

This commit is contained in:
Patrick Stevens
2021-11-10 13:15:33 +00:00
committed by GitHub
parent e971992f28
commit 488e07af2e
4 changed files with 66 additions and 63 deletions

41
rider/default.nix Normal file
View File

@@ -0,0 +1,41 @@
{ pkgs, config, lib, ... }:
let src = ./GlobalSettingsStorage.DotSettings; in
let link = ./link.sh; in
let riderconfig =
pkgs.stdenv.mkDerivation {
name = "rider-config";
version = "2021.2";
src = src;
phases = [ "unpackPhase" ];
unpackPhase = ''
mkdir -p "$out"
cp ${src} "$out/GlobalSettingsStorage.DotSettings"
cp ${link} "$out/link.sh"
chmod u+x "$out/link.sh"
sed -i 's_NIX-DOTNET-SDK_${pkgs.dotnet-sdk}_' "$out/GlobalSettingsStorage.DotSettings"
sed -i "s!NIX-RIDER-CONFIG!$out!" "$out/link.sh"
'';
installPhase = ''
'';
};
in
{
options = {
rider.enable = lib.mkOption { default = false; };
rider.username = lib.mkOption { type = lib.types.str; example = "Patrick"; };
};
config = lib.mkIf config.rider.enable {
home.activation.jetbrains-rider-settings = lib.hm.dag.entryAfter [ "writeBoundary" ] ''
dest="/Users/${config.rider.username}/Library/Application Support/JetBrains"
find "$dest" -type d -maxdepth 1 -name 'Rider*' -exec sh -c '${riderconfig}/link.sh "$0"' {} \;
'';
};
}

21
rider/link.sh Normal file
View File

@@ -0,0 +1,21 @@
#!/bin/sh
outfile="$1/resharper-host/GlobalSettingsStorage.DotSettings"
if [ -e "$outfile" ]; then
existing=$(readlink "$outfile")
if [ $? -eq 1 ] ; then
echo "Backing up existing settings file $outfile"
mv "$outfile" "$outfile.bak"
ln -s "NIX-RIDER-CONFIG/GlobalSettingsStorage.DotSettings" "$outfile"
else
case "$existing" in
"/nix/store/"*)
ln -fs "NIX-RIDER-CONFIG/GlobalSettingsStorage.DotSettings" "$outfile" ;;
*)
echo "Refusing to overwrite existing symlink to $existing" && \
exit 1 ;;
esac
fi
else
ln -s "NIX-RIDER-CONFIG/GlobalSettingsStorage.DotSettings" "$outfile"
fi

View File

@@ -1,61 +0,0 @@
{ pkgs ? import <nixpkgs> {}, username }:
let src = ./GlobalSettingsStorage.DotSettings; in
let riderconfig =
pkgs.stdenv.mkDerivation {
name = "rider-config";
version = "2021.2";
src = src;
phases = [ "unpackPhase" ];
unpackPhase = ''
mkdir -p $out
cp ${src} $out/GlobalSettingsStorage.DotSettings
sed -i 's_NIX-DOTNET-SDK_${pkgs.dotnet-sdk}_' "$out/GlobalSettingsStorage.DotSettings"
'';
installPhase = ''
'';
};
in
pkgs.runCommandLocal "rider-config" {} ''
function go {
outfile="$1/resharper-host/GlobalSettingsStorage.DotSettings"
echo "$outfile"
if [ -e "$outfile" ]; then
existing=$(readlink "$outfile")
if [ $? -eq 1 ] ; then
echo "Backing up existing settings file $outfile"
mv "$outfile" "$outfile.bak"
ln -s "${riderconfig}/GlobalSettingsStorage.DotSettings" "$outfile"
else
if [[ "$existing" == /nix/store/* ]]; then
ln -fs "${riderconfig}/GlobalSettingsStorage.DotSettings" "$outfile"
else
echo "Refusing to overwrite existing symlink to $existing"
exit 1
fi
fi
else
ln -s "${riderconfig}/GlobalSettingsStorage.DotSettings" "$outfile"
fi
}
export -f go
whoami
dest="/Users/${username}/Library/Application Support/JetBrains"
echo "$dest"
find "$dest" -type d -maxdepth 1 -name 'Rider*' -exec sh -c 'go "$0"' {} \;
mkdir -p "$out" && touch "$out/done.txt"
''
#pkgs.writeTextFile {
# name = "rider-config";
# text = ./GlobalSettingsStorage.DotSettings;
# destination = "/Users/${username}/Library/ApplicationSupport/JetBrains/Rider2021.2/resharper-host/GlobalSettingsStorage.DotSettings";
#}