1 { config, lib, pkgs, ... }:
3 let cfg = config.nix-plugins;
6 options.nix-plugins = {
7 enable = lib.mkEnableOption "nix-plugins";
8 extra-builtins = mkOption {
11 pass = path: exec [ "${config.nix-plugins.nix-pass}/bin/nix-pass" path ];
12 pass-to-file = path: file: exec [ "${config.nix-plugins.nix-pass-to-file}/bin/nix-pass-to-file" path file ];
13 git = dir: args: exec ([ "${config.nix-plugins.nix-git}/bin/nix-git" (builtins.toPath dir) ] ++ args);
14 git-time = dir: path: exec [ "${config.nix-plugins.nix-git}/bin/nix-git" (builtins.toPath dir) "log" "-1" "--format=%ct" "--" path ];
17 Content put in extra-builtins.nix for nix-plugins.
19 apply = lines: pkgs.writeText "extra-builtins.nix" (''
27 nix-with-extra-builtins = mkOption {
29 apply = pkgs.writeShellScriptBin "nix-with-extra-builtins";
32 --option plugin-files ${pkgs.nix-plugins}/lib/nix/plugins/libnix-extra-builtins.so \
33 --option extra-builtins-file ${cfg.extra-builtins} \
37 Wrapper around nix to load extra-builtins.nix with nix-plugins.
43 apply = pkgs.writeShellScriptBin "nix-pass";
47 trap "shred -u $f" EXIT
48 ${pkgs.pass}/bin/pass show "$1" >$f
49 nix-instantiate --eval -E "builtins.readFile $f"
56 ${pkgs.pass}/bin/pass show "$1" |
57 ${pkgs.gnused}/bin/sed \
58 -e 's:\n:\\n:g;s:\r:\\r:g;s:\t:\\t:g;s:":\\":g;1s:^:":;$s:$:":;'
61 Wrapper around pass to call it with exec in extra-builtins.nix.
62 Unfortunately it can only load secrets which can be represented as a Nix string,
63 hence without null-byte and such special characters.
67 nix-pass-to-file = mkOption {
69 apply = pkgs.writeShellScriptBin "nix-pass-to-file";
73 ${pkgs.pass}/bin/pass show "$1" |
74 install -D -m 400 /dev/stdin "$2"
75 printf '%s\n' "$PWD/$2"
78 Wrapper around pass to call it with exec in extra-builtins.nix and put the output in a file.
79 Needed for boot.initrd.network.ssh.host*Key.
85 apply = pkgs.writeShellScriptBin "nix-git";
88 ${pkgs.git}/bin/git "$@"
91 Wrapper around git to call it with exec in extra-builtins.nix.