Skip to content

Commit

Permalink
Convert to a flake
Browse files Browse the repository at this point in the history
  • Loading branch information
edolstra committed Sep 26, 2019
1 parent 2b06ab1 commit 4c7acbb
Show file tree
Hide file tree
Showing 12 changed files with 208 additions and 339 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
Expand Up @@ -2,4 +2,4 @@ language: nix
before_script:
- sudo mkdir /etc/nix && echo 'sandbox = true' | sudo tee /etc/nix/nix.conf
script:
- nix-build --quiet release.nix -A build.x86_64-linux -I nixpkgs=channel:nixos-19.03
- nix flake check
46 changes: 23 additions & 23 deletions README.md
Expand Up @@ -16,37 +16,37 @@ machines in a network or cloud.
To start developing on nixops, you can run:

```bash
$ ./dev-shell --arg p "(p: [ p.plugin1 ])"
$ nix dev-shell
```

Where plugin1 can be any available nixops plugin, and where
none or more than one can be specified, including local plugins. An example is:


```bash
$ ./dev-shell --arg p "(p: [ p.aws p.packet (p.callPackage ../myplugin/release.nix {})])"
```

To update the available nixops plugins, edit the
all-plugins.txt file with any new plugin repos and
then execute the update-all script. This will refresh
the data.nix file.

## Building from source

The command to build NixOps depends on your platform and which plugins you choose:

- `nix-build release.nix -A build.x86_64-linux --arg p "(p: [ p.plugin1 ])"` on 64 bit linux.
- `nix-build release.nix -A build.i686-linux --arg p "(p: [ p.plugin1 ])"` on 32 bit linux.
- `nix-build release.nix -A build.x86_64-darwin --arg p "(p: [ p.plugin1 ])"` on OSX.
- `nix build .#hydraJobs.build.x86_64-linux` on 64 bit linux.
- `nix-build .#hydraJobs.build.i686-linux` on 32 bit linux.
- `nix-build .#hydraJobs.build.x86_64-darwin` on OSX.

Similarly, using NixOps from another project (for instance a nix-shell) can be done using:
NixOps can be imported into another flake as follows:

```nix
stdenv.mkDerivation {
name = "my-nixops-env";
buildInputs = [
(import /path/to/nixops/release.nix { p = (p: [ p.plugin1 ]); }).build.x86_64-linux
];
{
edition = 201909;
inputs.nixops.uri = github:NixOS/nixops;
outputs = { self, nixpkgs, nixops }: {
packages.my-package =
let
pkgs = import nixpkgs {
system = "x86_linux";
overlays = [ nixops.overlay ];
};
in
pkgs.stdenv.mkDerivation {
...
buildInputs = [ pkgs.nixops ];
};
};
}
```
16 changes: 0 additions & 16 deletions all-plugins.txt

This file was deleted.

17 changes: 0 additions & 17 deletions data.nix

This file was deleted.

3 changes: 0 additions & 3 deletions dev-shell

This file was deleted.

2 changes: 1 addition & 1 deletion doc/manual/default.nix
Expand Up @@ -2,7 +2,7 @@

let

pkgs = import nixpkgs {};
pkgs = import nixpkgs { system = "x86_64-linux"; };

systemModule = pkgs.lib.fixMergeModules [ ../../nix/options.nix ./dummy.nix ] {
inherit pkgs; utils = {};
Expand Down
6 changes: 3 additions & 3 deletions doc/manual/hacking.xml
Expand Up @@ -14,7 +14,7 @@ $ cd nixops

<para>To build it and its dependencies:
<screen>
$ nix-build release.nix -A build.x86_64-linux
$ nix build
</screen>
The resulting NixOps can be run as
<filename>./result/bin/nixops</filename>.</para>
Expand All @@ -23,7 +23,7 @@ The resulting NixOps can be run as
environment variables (such as <envar>PYTHONPATH</envar>) are set up
so that those dependencies can be found:
<screen>
$ nix-shell release.nix -A build.x86_64-linux --exclude tarball
$ nix dev-shell
$ echo $PYTHONPATH
/nix/store/yzj6p5f7iyh247pwxrg97y3klm6d0cni-python-2.7.3/lib/python2.7/site-packages:<replaceable>...</replaceable>
</screen>
Expand Down Expand Up @@ -56,7 +56,7 @@ filter on one or more tags.
There are also a few NixOS VM tests. These can be run as follows:

<screen>
$ nix-build release.nix -A tests.none_backend
$ nix build .#hydraJobs.tests.none_backend
</screen>

</para>
Expand Down
23 changes: 23 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

154 changes: 154 additions & 0 deletions flake.nix
@@ -0,0 +1,154 @@
{
description = "A tool for deploying NixOS machines in a network or cloud";

edition = 201909;

inputs.nixpkgs.uri = "nixpkgs/release-19.09";

inputs.nixops-aws = {
uri = github:NixOS/nixops-aws;
flake = false;
};

inputs.nixops-hetzner = {
uri = github:NixOS/nixops-hetzner;
flake = false;
};

outputs = { self, nixpkgs, nixops-aws, nixops-hetzner }:
let

officialRelease = false;

version = "1.7" + (if officialRelease then "" else "pre${builtins.substring 0 8 self.lastModified}.${self.shortRev}");

pkgs = import nixpkgs {
system = "x86_64-linux";
overlays = [ self.overlay ];
};

in {

overlay = final: prev: {

nixops = with final; python2Packages.buildPythonApplication rec {
name = "nixops-${version}";

src = "${self.hydraJobs.tarball}/tarballs/*.tar.bz2";

buildInputs = [ python2Packages.nose python2Packages.coverage ];

nativeBuildInputs = [ pkgs.mypy ];

propagatedBuildInputs = with python2Packages;
[ prettytable
# Go back to sqlite once Python 2.7.13 is released
pysqlite
typing
pluggy
(import (nixops-aws + "/release.nix") {
inherit nixpkgs;
src = nixops-aws;
}).build.x86_64-linux
(import (nixops-hetzner + "/release.nix") {
inherit nixpkgs;
src = nixops-hetzner;
}).build.x86_64-linux
];

# For "nix dev-shell".
shellHook = ''
export PYTHONPATH=$(pwd):$PYTHONPATH
export PATH=$(pwd)/scripts:${openssh}/bin:$PATH
'';

doCheck = true;

postCheck = ''
# We have to unset PYTHONPATH here since it will pick enum34 which collides
# with python3 own module. This can be removed when nixops is ported to python3.
PYTHONPATH= mypy --cache-dir=/dev/null nixops
# smoke test
HOME=$TMPDIR $out/bin/nixops --version
'';

# Needed by libcloud during tests.
SSL_CERT_FILE = "${pkgs.cacert}/etc/ssl/certs/ca-bundle.crt";

# Add openssh to nixops' PATH. On some platforms, e.g. CentOS and RHEL
# the version of openssh is causing errors with big networks (40+).
makeWrapperArgs = ["--prefix" "PATH" ":" "${openssh}/bin" "--set" "PYTHONPATH" ":"];

postInstall =
''
# Backward compatibility symlink.
ln -s nixops $out/bin/charon
make -C doc/manual install \
docdir=$out/share/doc/nixops mandir=$out/share/man
mkdir -p $out/share/nix/nixops
cp -av nix/* $out/share/nix/nixops
'';
};

};

hydraJobs = {

build.x86_64-linux = pkgs.nixops;

tarball = pkgs.releaseTools.sourceTarball {
name = "nixops-tarball";

src = self;

inherit version;

officialRelease = true; # hack

buildInputs = [ pkgs.git pkgs.libxslt pkgs.docbook5_xsl ];

postUnpack = ''
# Clean up when building from a working tree.
if [ -d $sourceRoot/.git ]; then
(cd $sourceRoot && (git ls-files -o | xargs -r rm -v))
fi
'';

distPhase =
''
# Generate the manual and the man page.
cp ${(import ./doc/manual { revision = self.rev; inherit nixpkgs; }).optionsDocBook} doc/manual/machine-options.xml
for i in scripts/nixops setup.py doc/manual/manual.xml; do
substituteInPlace $i --subst-var-by version ${version}
done
make -C doc/manual install docdir=$out/manual mandir=$TMPDIR/man
releaseName=nixops-$VERSION
mkdir ../$releaseName
cp -prd . ../$releaseName
rm -rf ../$releaseName/.git
mkdir $out/tarballs
tar cvfj $out/tarballs/$releaseName.tar.bz2 -C .. $releaseName
echo "doc manual $out/manual manual.html" >> $out/nix-support/hydra-build-products
'';
};

tests.none_backend = (import ./tests/none-backend.nix {
inherit nixpkgs;
nixops = pkgs.nixops;
system = "x86_64-linux";
}).test;
};

checks.build = self.hydraJobs.build.x86_64-linux;

packages.nixops = pkgs.nixops;
defaultPackage = pkgs.nixops;

};
}

0 comments on commit 4c7acbb

Please sign in to comment.