-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
101 lines (95 loc) · 3.02 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable";
};
outputs = {
self,
nixpkgs,
}: let
inherit (nixpkgs) lib;
eachDefaultSystem = lib.genAttrs [
"x86_64-linux"
"x86_64-darwin"
"aarch64-linux"
"aarch64-darwin"
];
in {
packages = eachDefaultSystem (system: let
pkgs = import nixpkgs {inherit system;};
in {
default = pkgs.stdenvNoCC.mkDerivation {
pname = "deploy-sh";
version = "0.2.0";
nativeBuildInputs = [pkgs.makeWrapper];
unpackPhase = "true";
installPhase = ''
install -DT ${./deploy.sh} $out/bin/deploy
'';
postFixup = ''
wrapProgram $out/bin/deploy --set PATH ${with pkgs; lib.makeBinPath [coreutils bash gnugrep jq nix git openssh nix-diff nvd]}
'';
};
});
nixosModules.default = {
config,
lib,
pkgs,
...
}:
with lib; {
options.deploy-sh = {
targetHost = mkOption {
type = types.str;
example = "[email protected]";
description = ''
The host to deploy the system on. Both the local host and the build host has to be able to connect to this host via SSH.
'';
};
buildHost = mkOption {
type = types.nullOr types.str;
default = config.deploy-sh.targetHost;
example = "[email protected]";
description = ''
The host to build the system on. The local host has to be able to connect to this host via SSH.
'';
};
buildCache = mkOption {
type = types.nullOr types.str;
default = null;
example = "/var/cache/deploy-sh/HOSTNAME";
description = ''
A path on the build host where to store a symlink to the new system to avoid garbage collection.
'';
};
enableDiff = mkOption {
type = types.bool;
default = true;
};
pushDerivations = mkOption {
type = types.bool;
};
_config = mkOption {
visible = false;
readOnly = true;
};
};
config = let
cfg = config.deploy-sh;
in {
deploy-sh.pushDerivations = lib.mkDefault cfg.enableDiff;
deploy-sh._config = let
vars = {
inherit (cfg) buildHost targetHost buildCache pushDerivations;
systemDrv = config.system.build.toplevel.drvPath;
system = config.system.build.toplevel.outPath;
nomDrv = pkgs.nix-output-monitor.drvPath;
nom = pkgs.nix-output-monitor.outPath;
};
text = builtins.concatStringsSep "" (lib.mapAttrsToList (k: v: "local ${k}=${lib.escapeShellArg v}\n") vars);
in
pkgs.writeText "deploy-sh-config" (builtins.unsafeDiscardStringContext text);
nix.settings.keep-derivations = lib.mkIf cfg.enableDiff true;
};
};
};
}