aboutsummaryrefslogtreecommitdiff
path: root/modules/home-environment.nix
diff options
context:
space:
mode:
authorRobert Helgesson <robert@rycee.net>2017-05-04 00:36:39 +0200
committerRobert Helgesson <robert@rycee.net>2017-05-04 00:39:36 +0200
commit8fab2a5d9bb685bbf190565ea242afe670367bf4 (patch)
tree24a2be4efb32fce594748b10c64201965c8ed4ad /modules/home-environment.nix
parent62a9a8fa3ced9debdaa8c760b3df6bd513c75fa7 (diff)
Add basic directed acyclic graph data structure
Also make use of this instead of Nixpkgs's strings-with-deps library in activation script generation.
Diffstat (limited to 'modules/home-environment.nix')
-rw-r--r--modules/home-environment.nix38
1 files changed, 21 insertions, 17 deletions
diff --git a/modules/home-environment.nix b/modules/home-environment.nix
index 8c3c462e987..1e7a447305f 100644
--- a/modules/home-environment.nix
+++ b/modules/home-environment.nix
@@ -1,6 +1,7 @@
{ config, lib, pkgs, ... }:
with lib;
+with import ./lib/dag.nix;
let
@@ -241,7 +242,11 @@ in
//
(maybeSet "LC_TIME" cfg.language.time);
- home.activation.linkGeneration =
+ # A dummy entry acting as a boundary between the activation
+ # script's "check" and the "write" phases.
+ home.activation.writeBoundary = dagEntryAnywhere "";
+
+ home.activation.linkGeneration = dagEntryAfter ["writeBoundary"] (
let
link = pkgs.writeText "link" ''
newGenFiles="$1"
@@ -303,27 +308,26 @@ in
else
echo "Same home files as previous generation ... doing nothing"
fi
- '';
+ ''
+ );
- home.activation.installPackages =
- ''
- $DRY_RUN_CMD nix-env -i ${cfg.path}
- '';
+ home.activation.installPackages = dagEntryAfter ["writeBoundary"] ''
+ $DRY_RUN_CMD nix-env -i ${cfg.path}
+ '';
home.activationPackage =
let
- addHeader = n: v:
- v // {
- text = ''
- echo Activating ${n}
- ${v.text}
- '';
- };
- toDepString = n: v: if isString v then noDepEntry v else v;
- activationWithDeps =
- mapAttrs addHeader (mapAttrs toDepString cfg.activation);
+ mkCmd = res: ''
+ echo Activating ${res.name}
+ ${res.data}
+ '';
+ sortedCommands = dagTopoSort cfg.activation;
activationCmds =
- textClosureMap id activationWithDeps (attrNames activationWithDeps);
+ if sortedCommands ? result then
+ concatStringsSep "\n" (map mkCmd sortedCommands.result)
+ else
+ abort ("Dependency cycle in activation script: "
+ + builtins.toJSON sortedCommands);
sf = pkgs.writeText "activation-script" ''
#!${pkgs.stdenv.shell}