Skip to content

Instantly share code, notes, and snippets.

@grahamc

grahamc/foo.nix Secret

Last active October 8, 2017 11:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save grahamc/873369fa52ce60f9c849eb343863d63e to your computer and use it in GitHub Desktop.
Save grahamc/873369fa52ce60f9c849eb343863d63e to your computer and use it in GitHub Desktop.
users.extraUsers.grahamc = rec {
# ...
symlinks = {
".mbsyncrc" = pkgs.email.mbsyncrc;
".msmtprc" = pkgs.email.msmtprc;
".notmuch-config" = pkgs.email.notmuch-config;
".gitconfig" = pkgs.gitconfig;
".gnupg/gpg.conf" = pkgs.gnupgconfig.gpgconf;
".gnupg/scdaemon.conf" = pkgs.gnupgconfig.scdaemonconf;
".mail/grahamc/.notmuch/hooks/pre-new" = pkgs.email.pre-new;
".mail/grahamc/.notmuch/hooks/post-new" = pkgs.email.post-new;
} // (if (builtins.pathExists "${home}/projects/nixpkgs") then {
"projects/nixpkgs/.git/hooks/pre-push" = pkgs.nixpkgs-pre-push;
} else {});
};
{ config, lib, pkgs, ... }:
with lib;
let
usersWithKeys = attrValues (flip filterAttrs config.users.users (n: u:
u.symlinks != {}
));
activationScriptForUser = user: flip mapAttrsToList user.symlinks (reltarget: src:
"update_symlink \"${src}\" \"${user.home}/${reltarget}\""
);
activationScript = ''
${builtins.readFile ./update-symlinks.sh}
${concatStringsSep "\n" (flatten (map activationScriptForUser usersWithKeys))}
'';
in {
###### interface
options = {
users.users = mkOption {
options = [{
symlinks = mkOption {
default = {};
description = ''
An attrset of relative paths and targets to symlink in to
the user's HOME.
'';
};
}];
};
};
###### implementation
config = ({
system.activationScripts.usersymlinks = activationScript;
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment