-
-
Notifications
You must be signed in to change notification settings - Fork 364
/
flake.nix
152 lines (127 loc) · 4.21 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
{
description = "NixOps: a tool for deploying to [NixOS](https://nixos.org) machines in a network or the cloud";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable-small";
inputs.poetry2nix.url = "github:nix-community/poetry2nix";
inputs.poetry2nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.utils.url = "github:numtide/flake-utils";
outputs = { self, nixpkgs, poetry2nix, utils }: utils.lib.eachDefaultSystem (system: let
pkgs = import nixpkgs { inherit system; };
poetry2nix' = import poetry2nix { inherit pkgs; };
pythonEnv = poetry2nix'.mkPoetryEnv {
projectDir = ./.;
};
linters.doc = pkgs.writers.writeBashBin "lint-docs" ''
set -eux
# When running it in the Nix sandbox, there is no git repository
# but sources are filtered.
if [ -d .git ];
then
FILES=$(${pkgs.git}/bin/git ls-files)
else
FILES=$(find .)
fi
echo "$FILES" | xargs ${pkgs.codespell}/bin/codespell -L keypair,iam,hda
${pythonEnv}/bin/sphinx-build -M clean doc/ doc/_build
${pythonEnv}/bin/sphinx-build -n doc/ doc/_build
'';
in rec {
devShells.default = pkgs.mkShell {
buildInputs = [
pythonEnv
pkgs.openssh
pkgs.poetry
pkgs.rsync # Included by default on NixOS
pkgs.nixFlakes
pkgs.codespell
] ++ (builtins.attrValues linters);
shellHook = ''
git_root=$(${pkgs.git}/bin/git rev-parse --show-toplevel)
export PYTHONPATH=$git_root:$PYTHONPATH
export PATH=$git_root/scripts:$PATH
'';
};
devShell = devShells.default;
apps.default = {
type = "app";
program = "${self.defaultPackage."${system}"}/bin/nixops";
};
defaultApp = apps.default;
packages.default = poetry2nix'.mkPoetryApplication {
projectDir = ./.;
propagatedBuildInputs = [
pkgs.openssh
pkgs.rsync
];
# TODO: Re-add manual build
};
defaultPackage = packages.default;
nixosOptions = pkgs.nixosOptionsDoc {
inherit (pkgs.lib.fixMergeModules [ ./nix/options.nix ] {
inherit pkgs;
name = "<name>";
uuid = "<uuid>";
}) options;
};
rstNixosOptions = let
optionsNix = removeAttrs self.nixosOptions.${pkgs.system}.optionsNix [ "_module.args" ];
oneRstOption = name: value: ''
${name}
${pkgs.lib.concatStrings (builtins.genList (_: "-") (builtins.stringLength name))}
${value.description}
${pkgs.lib.optionalString (value ? readOnly) ''
Read Only
''}
:Type: ${value.type}
${pkgs.lib.optionalString (value ? default) ''
:Default: ${builtins.toJSON value.default}
''}
${pkgs.lib.optionalString (value ? example) ''
:Example: ${builtins.toJSON value.example}
''}
'';
text = ''
NixOps Options
==============
'' + pkgs.lib.concatStringsSep "\n" (pkgs.lib.mapAttrsToList oneRstOption optionsNix);
in pkgs.writeText "options.rst" text;
docs = pkgs.stdenv.mkDerivation {
name = "nixops-docs";
# we use cleanPythonSources because the default gitignore
# implementation doesn't support the restricted evaluation
src = poetry2nix'.cleanPythonSources {
src = ./.;
};
buildPhase = ''
cp ${self.rstNixosOptions.${pkgs.system}} doc/manual/options.rst
${pythonEnv}/bin/sphinx-build -M clean doc/ doc/_build
${pythonEnv}/bin/sphinx-build -n doc/ doc/_build
'';
installPhase = ''
mv doc/_build $out
'';
};
checks = {
doc = pkgs.stdenv.mkDerivation {
name = "check-lint-docs";
# we use cleanPythonSources because the default gitignore
# implementation doesn't support the restricted evaluation
src = poetry2nix'.cleanPythonSources {
src = ./.;
};
dontBuild = true;
installPhase = ''
${linters.doc}/bin/lint-docs | tee $out
'';
};
} // utils.lib.flattenTree (
import ./integration-tests {
inherit pkgs;
nixops = self.defaultPackage.${system};
}
);
}) // {
herculesCI = {
ciSystems = ["x86_64-linux"];
};
};
}