Skip to content

Instantly share code, notes, and snippets.

@tilpner
Created July 14, 2017 08:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tilpner/a2131b0244b21dc650e19cdb36d04577 to your computer and use it in GitHub Desktop.
Save tilpner/a2131b0244b21dc650e19cdb36d04577 to your computer and use it in GitHub Desktop.
{ 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