diff --git a/home.nix b/home.nix index ff4cdd9..362bcfb 100644 --- a/home.nix +++ b/home.nix @@ -2,9 +2,11 @@ let username = "Patrick"; in -let rider = import ./rider/rider.nix { inherit pkgs; username = username; }; in - { + imports = [ ./rider ]; + + rider = { enable = true; username = username; }; + # Let Home Manager install and manage itself. programs.home-manager.enable = true; diff --git a/rider/default.nix b/rider/default.nix new file mode 100644 index 0000000..c25f6ab --- /dev/null +++ b/rider/default.nix @@ -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"' {} \; + ''; + }; + +} diff --git a/rider/link.sh b/rider/link.sh new file mode 100644 index 0000000..24b1705 --- /dev/null +++ b/rider/link.sh @@ -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 diff --git a/rider/rider.nix b/rider/rider.nix deleted file mode 100644 index fad28e4..0000000 --- a/rider/rider.nix +++ /dev/null @@ -1,61 +0,0 @@ -{ pkgs ? import {}, 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"; -#}