Skip to content

Commit

Permalink
Add dag library to config.lib
Browse files Browse the repository at this point in the history
Also replace all imports of `dag.nix` by the entry in `config.lib`.
  • Loading branch information
rycee committed Dec 5, 2017
1 parent f8aaba6 commit 391f1df
Show file tree
Hide file tree
Showing 11 changed files with 43 additions and 24 deletions.
6 changes: 3 additions & 3 deletions modules/files.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ pkgs, config, lib, ... }:

with config.lib;
with lib;
with import ./lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -64,7 +64,7 @@ in

# This verifies that the links we are about to create will not
# overwrite an existing file.
home.activation.checkLinkTargets = dagEntryBefore ["writeBoundary"] (
home.activation.checkLinkTargets = dag.entryBefore ["writeBoundary"] (
let
check = pkgs.writeText "check" ''
. ${./lib-bash/color-echo.sh}
Expand Down Expand Up @@ -120,7 +120,7 @@ in
# and a failure during the intermediate state FA ∩ FB will not
# result in lost links because this set of links are in both the
# source and target generation.
home.activation.linkGeneration = dagEntryAfter ["writeBoundary"] (
home.activation.linkGeneration = dag.entryAfter ["writeBoundary"] (
let
link = pkgs.writeText "link" ''
newGenFiles="$1"
Expand Down
8 changes: 4 additions & 4 deletions modules/home-environment.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ./lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -232,9 +232,9 @@ in

# A dummy entry acting as a boundary between the activation
# script's "check" and the "write" phases.
home.activation.writeBoundary = dagEntryAnywhere "";
home.activation.writeBoundary = dag.entryAnywhere "";

home.activation.installPackages = dagEntryAfter ["writeBoundary"] ''
home.activation.installPackages = dag.entryAfter ["writeBoundary"] ''
$DRY_RUN_CMD nix-env -i ${cfg.path}
'';

Expand All @@ -244,7 +244,7 @@ in
noteEcho Activating ${res.name}
${res.data}
'';
sortedCommands = dagTopoSort cfg.activation;
sortedCommands = dag.topoSort cfg.activation;
activationCmds =
if sortedCommands ? result then
concatStringsSep "\n" (map mkCmd sortedCommands.result)
Expand Down
18 changes: 18 additions & 0 deletions modules/lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{ lib }:

{
dag =
let
d = import ./dag.nix { inherit lib; };
in
{
empty = d.emptyDag;
isDag = d.isDag;
topoSort = d.dagTopoSort;
map = d.dagMap;
entryAnywhere = d.dagEntryAnywhere;
entryBetween = d.dagEntryBetween;
entryAfter = d.dagEntryAfter;
entryBefore = d.dagEntryBefore;
};
}
1 change: 1 addition & 0 deletions modules/modules.nix
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ let
config._module.args.baseModules = modules;
config._module.args.pkgs = lib.mkDefault pkgs;
config._module.check = check;
config.lib = import ./lib { inherit lib; };
config.nixpkgs.system = mkDefault pkgs.system;
};

Expand Down
4 changes: 2 additions & 2 deletions modules/programs/gnome-terminal.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ../lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -181,7 +181,7 @@ in
home.packages = [ pkgs.gnome3.gnome_terminal ];

# The dconf service needs to be installed and prepared.
home.activation.gnomeTerminal = dagEntryAfter ["installPackages"] (
home.activation.gnomeTerminal = dag.entryAfter ["installPackages"] (
let
iniText = toDconfIni (buildIniSet cfg);
iniFile = pkgs.writeText "gnome-terminal.ini" iniText;
Expand Down
4 changes: 2 additions & 2 deletions modules/programs/home-manager.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ../lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -42,7 +42,7 @@ in
# Uninstall manually installed home-manager, if such exists.
# Without this a file collision error will be printed.
home.activation.uninstallHomeManager =
dagEntryBetween [ "installPackages" ] [ "writeBoundary" ] ''
dag.entryBetween [ "installPackages" ] [ "writeBoundary" ] ''
if nix-env -q | grep -q "^home-manager$" ; then
$DRY_RUN_CMD nix-env -e home-manager
Expand Down
4 changes: 2 additions & 2 deletions modules/programs/info.nix
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@

{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ../lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -63,7 +63,7 @@ in
home.sessionVariables.INFOPATH =
"${cfg.homeInfoDirLocation}\${INFOPATH:+:}\${INFOPATH}";

home.activation.createHomeInfoDir = dagEntryAfter ["installPackages"] ''
home.activation.createHomeInfoDir = dag.entryAfter ["installPackages"] ''
oPATH=$PATH
export PATH="${lib.makeBinPath [ pkgs.gzip ]}''${PATH:+:}$PATH"
$DRY_RUN_CMD mkdir -p "${cfg.homeInfoDirLocation}"
Expand Down
6 changes: 3 additions & 3 deletions modules/services/polybar.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ../lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -131,15 +131,15 @@ in
};
};

home.activation.checkPolybar = dagEntryBefore [ "linkGeneration" ] ''
home.activation.checkPolybar = dag.entryBefore [ "linkGeneration" ] ''
if ! cmp --quiet \
"${configFile}" \
"$HOME/.config/polybar/config"; then
polybarChanged=1
fi
'';

home.activation.applyPolybar = dagEntryAfter [ "reloadSystemD" ] ''
home.activation.applyPolybar = dag.entryAfter [ "reloadSystemD" ] ''
if [[ -v polybarChanged && -v DISPLAY ]]; then
echo "Restarting polybar"
${config.systemd.user.systemctlPath} --user restart polybar.service
Expand Down
6 changes: 3 additions & 3 deletions modules/services/window-managers/i3.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ../../lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -621,15 +621,15 @@ in
xsession.windowManager.command = "${cfg.package}/bin/i3";
xdg.configFile."i3/config".source = configFile;

home.activation.checkI3 = dagEntryBefore [ "linkGeneration" ] ''
home.activation.checkI3 = dag.entryBefore [ "linkGeneration" ] ''
if ! cmp --quiet \
"${configFile}" \
"${config.xdg.configHome}/i3/config"; then
i3Changed=1
fi
'';

home.activation.reloadI3 = dagEntryAfter [ "linkGeneration" ] ''
home.activation.reloadI3 = dag.entryAfter [ "linkGeneration" ] ''
if [[ -v i3Changed && -v DISPLAY ]]; then
echo "Reloading i3"
${cfg.package}/bin/i3-msg reload 1>/dev/null
Expand Down
6 changes: 3 additions & 3 deletions modules/services/window-managers/xmonad.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ../../lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -90,13 +90,13 @@ in
(mkIf (cfg.config != null) {
home.file.".xmonad/xmonad.hs".source = cfg.config;

home.activation.checkXmonad = dagEntryBefore [ "linkGeneration" ] ''
home.activation.checkXmonad = dag.entryBefore [ "linkGeneration" ] ''
if ! cmp --quiet "${cfg.config}" "$HOME/.xmonad/xmonad.hs"; then
xmonadChanged=1
fi
'';

home.activation.applyXmonad = dagEntryAfter [ "linkGeneration" ] ''
home.activation.applyXmonad = dag.entryAfter [ "linkGeneration" ] ''
if [[ -v xmonadChanged ]]; then
echo "Recompiling xmonad"
${config.xsession.windowManager.command} --recompile
Expand Down
4 changes: 2 additions & 2 deletions modules/systemd.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{ config, lib, pkgs, ... }:

with config.lib;
with lib;
with import ./lib/dag.nix { inherit lib; };

let

Expand Down Expand Up @@ -118,7 +118,7 @@ in
(buildServices "timer" cfg.timers)
);

home.activation.reloadSystemD = dagEntryAfter ["linkGeneration"] ''
home.activation.reloadSystemD = dag.entryAfter ["linkGeneration"] ''
function isStartable() {
local service="$1"
[[ $(systemctl --user show -p RefuseManualStart "$service") == *=no ]]
Expand Down

0 comments on commit 391f1df

Please sign in to comment.