-
-
Save tilpner/a2131b0244b21dc650e19cdb36d04577 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ config, lib, pkgs, ... }: | |
with lib; | |
let | |
dotfileUpdater = { name, root, files, method }: | |
pkgs.writeScript name ('' | |
#!/bin/sh | |
PATH=${pkgs.coreutils}/bin | |
set -e | |
update_dot() { | |
local src="$1" | |
local dst="$2" | |
mkdir -p "$(dirname "$dst")" | |
${method} "$src" "$dst" | |
} | |
'' + concatStringsSep "\n" ( | |
mapAttrsToList | |
(name: value: "update_dot \"${value}\" \"${root + ("/" + name)}\"") | |
files)); | |
cfg = config.environment.dotfiles; | |
in { | |
options.environment.dotfiles = mkOption { | |
description = "unsafe dotfile management"; | |
type = with types; attrsOf (submodule { | |
options = { | |
root = mkOption { | |
type = str; | |
default = ""; | |
}; | |
method = mkOption { | |
type = str; | |
default = "ln --symbolic --no-target-directory --force --verbose"; | |
}; | |
files = mkOption { | |
type = attrsOf path; | |
}; | |
}; | |
}); | |
}; | |
config = { | |
system.activationScripts = { | |
dotfiles = { | |
deps = [ "stdio" "users" ]; | |
text = '' | |
echo "setting up dotfiles..." | |
'' + concatStringsSep "\n" | |
(mapAttrsToList | |
(name: value: dotfileUpdater { | |
name = "dotfiles-${name}"; | |
inherit (value) root files method; | |
}) | |
cfg); | |
}; | |
}; | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment