diff options
author | Robert Helgesson <robert@rycee.net> | 2017-01-16 20:26:42 +0100 |
---|---|---|
committer | Robert Helgesson <robert@rycee.net> | 2017-01-16 20:33:53 +0100 |
commit | f35b9a9970ef66eb8ede5a5595b01777e55fde4a (patch) | |
tree | ddf19087d75116d9590ae060b65c9fd942cd2543 | |
parent | 8ce389ce2acca7a630c3d25466fa20993843d28c (diff) |
Add initial section of activation script
The initial section creates some useful variables for use by later
activation sections.
-rwxr-xr-x | modules/activation-init.sh | 46 | ||||
-rw-r--r-- | modules/home-environment.nix | 48 | ||||
-rw-r--r-- | modules/systemd.nix | 2 |
3 files changed, 51 insertions, 45 deletions
diff --git a/modules/activation-init.sh b/modules/activation-init.sh new file mode 100755 index 00000000000..91ad791076d --- /dev/null +++ b/modules/activation-init.sh @@ -0,0 +1,46 @@ +function setupVars() { + local profilesPath="/nix/var/nix/profiles/per-user/$USER" + local gcPath="/nix/var/nix/gcroots/per-user/$USER" + local greatestGenNum + + greatestGenNum=$( \ + find "$profilesPath" -name 'home-manager-*-link' \ + | sed 's/^.*-\([0-9]*\)-link$/\1/' \ + | sort -rn \ + | head -1) + + if [[ -n "$greatestGenNum" ]] ; then + oldGenNum=$greatestGenNum + newGenNum=$((oldGenNum + 1)) + else + newGenNum=1 + fi + + if [[ -e "$gcPath/current-home" ]] ; then + oldGenPath="$(readlink -e "$gcPath/current-home")" + fi + + newGenPath="@GENERATION_DIR@"; + newGenProfilePath="$profilesPath/home-manager-$newGenNum-link" + newGenGcPath="$gcPath/current-home" +} + +setupVars + +echo "Starting home manager activation" + +if [[ $DRY_RUN ]] ; then + echo "This is a dry run" + export DRY_RUN_CMD=echo +else + echo "This is a live run" + unset DRY_RUN_CMD +fi + +echo "Activation variables:" +echo " oldGenNum=$oldGenNum" +echo " newGenNum=$newGenNum" +echo " oldGenPath=$oldGenPath" +echo " newGenPath=$newGenPath" +echo " newGenProfilePath=$newGenProfilePath" +echo " newGenGcPath=$newGenGcPath" diff --git a/modules/home-environment.nix b/modules/home-environment.nix index 0ea92147762..c4dda2ef8c8 100644 --- a/modules/home-environment.nix +++ b/modules/home-environment.nix @@ -202,7 +202,7 @@ in // (maybeSet "LC_TIME" cfg.language.time); - home.activation.linkages = + home.activation.linkGeneration = let link = pkgs.writeText "link" '' newGenFiles="$1" @@ -234,42 +234,6 @@ in ''; in '' - function setupVars() { - local profilesPath="/nix/var/nix/profiles/per-user/$(whoami)" - local gcPath="/nix/var/nix/gcroots/per-user/$(whoami)" - local greatestGenNum=( \ - $(find "$profilesPath" -name 'home-manager-*-link' \ - | sed 's/^.*-\([0-9]*\)-link$/\1/' \ - | sort -rn \ - | head -1) \ - ) - - if [[ -n "$greatestGenNum" ]] ; then - oldGenNum=$greatestGenNum - newGenNum=$(($oldGenNum + 1)) - else - newGenNum=1 - fi - - if [[ -e "$gcPath/current-home" ]] ; then - oldGenPath="$(readlink -e "$gcPath/current-home")" - fi - - newGenPath="@GENERATION_DIR@"; - newGenProfilePath="$profilesPath/home-manager-$newGenNum-link" - newGenGcPath="$gcPath/current-home" - } - - # Set some vars, these can be used later on as well. - setupVars - - echo oldGenNum=$oldGenNum - echo newGenNum=$newGenNum - echo oldGenPath=$oldGenPath - echo newGenPath=$newGenPath - echo newGenProfilePath=$newGenProfilePath - echo newGenGcPath=$newGenGcPath - function linkNewGen() { local newGenFiles newGenFiles="$(readlink -e "$newGenPath/home-files")" @@ -324,13 +288,9 @@ in sf = pkgs.writeText "activation-script" '' #!${pkgs.stdenv.shell} - if [[ $DRY_RUN ]] ; then - echo "Performing dry run" - export DRY_RUN_CMD=echo - else - echo "Performing live run" - unset DRY_RUN_CMD - fi + set -e + + ${builtins.readFile ./activation-init.sh} ${activationCmds} ''; diff --git a/modules/systemd.nix b/modules/systemd.nix index 784be8db69c..de3492308a9 100644 --- a/modules/systemd.nix +++ b/modules/systemd.nix @@ -69,7 +69,7 @@ in (buildServices "timer" config.systemd.user.timers) ); - home.activation.reloadSystemD = stringAfter ["linkages"] '' + home.activation.reloadSystemD = '' function systemdPostReload() { local servicesDiffFile="$(mktemp)" local oldUserServicePath="$oldGenPath/home-files/.config/systemd/user" |