]> Git — Sourcephile - sourcephile-nix.git/blob - nixos/modules/install.nix
nix: add module security.pass
[sourcephile-nix.git] / nixos / modules / install.nix
1 { pkgs, lib, config, ... }:
2 let
3 inherit (builtins) listToAttrs;
4 inherit (lib) types;
5 inherit (config) networking;
6 cfg = config.install;
7 in
8 {
9 options.install = {
10 enable = lib.mkEnableOption "Install";
11 shellHook = lib.mkOption {
12 type = types.lines;
13 default = "";
14 };
15 shellScript = lib.mkOption {
16 type = types.lines;
17 default = "";
18 apply = pkgs.writeShellScriptBin "bash";
19 };
20 target = lib.mkOption {
21 type = types.str;
22 default = "root@${networking.hostName}.${networking.domain}";
23 };
24 generations = lib.mkOption {
25 type = types.str;
26 default = "+10";
27 };
28 profile = lib.mkOption {
29 type = types.str;
30 default = "/nix/var/nix/profiles/system";
31 };
32 };
33 config = lib.mkIf cfg.enable {
34 install.shellScript =
35 let nixos = config.system.build.toplevel; in ''
36 PATH="$PATH:${with pkgs; lib.makeBinPath [nix openssh]}"
37 set -x
38 nix ''${TRACE:+-L} copy \
39 --to ssh://${cfg.target} --substitute-on-destination \
40 ${nixos}
41 ssh ${cfg.target} nix-env --profile "${cfg.profile}" --set "${nixos}" \
42 '&&' nix-env --profile "${cfg.profile}" --delete-generations "${cfg.generations}" \
43 '&&' "${cfg.profile}"/bin/switch-to-configuration "''${switch:-switch}"
44 '';
45 };
46 }