mirror of
https://github.com/nix-community/home-manager.git
synced 2025-12-11 11:31:06 +01:00
Add basic directed acyclic graph data structure
Also make use of this instead of Nixpkgs's strings-with-deps library in activation script generation.
This commit is contained in:
parent
62a9a8fa3c
commit
8fab2a5d9b
4 changed files with 153 additions and 22 deletions
|
|
@ -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}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue