From ae89eafb817f6c691cb0e97f9e67cd9204ada3a4 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Na=C3=AFm=20Favier?= Date: Tue, 15 Dec 2020 16:01:40 +0100 Subject: [PATCH] add flake support --- docs/setup-guide.rst | 28 +++++++++++++++++++++++++++ flake.lock | 42 ++++++++++++++++++++++++++++++++++++++++ flake.nix | 26 +++++++++++++++++++++++++ nixops/single-server.nix | 2 +- shell.nix | 12 +----------- 5 files changed, 98 insertions(+), 12 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/docs/setup-guide.rst b/docs/setup-guide.rst index ef2a76b..cc53283 100644 --- a/docs/setup-guide.rst +++ b/docs/setup-guide.rst @@ -97,6 +97,34 @@ After a ``nixos-rebuild switch --upgrade`` your server should be good to go. If you want to use ``nixops`` to deploy the server, look in the subfolder ``nixops`` for some inspiration. +If you're using `flakes `__, you can use +the following minimal ``flake.nix`` as an example: + +.. code:: nix + + { + description = "NixOS configuration"; + + inputs.simple-nixos-mailserver.url = "gitlab:simple-nixos-mailserver/nixos-mailserver"; + + outputs = { self, nixpkgs, simple-nixos-mailserver }: { + nixosConfigurations = { + hostname = nixpkgs.lib.nixosSystem { + system = "x86_64-linux"; + modules = [ + simple-nixos-mailserver.nixosModule + { + mailserver = { + enable = true; + # ... + }; + } + ]; + }; + }; + }; + } + B) Setup everything else ~~~~~~~~~~~~~~~~~~~~~~~~ diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..a9abdbc --- /dev/null +++ b/flake.lock @@ -0,0 +1,42 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1607522989, + "narHash": "sha256-o/jWhOSAlaK7y2M57OIriRt6whuVVocS/T0mG7fd1TI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e9158eca70ae59e73fae23be5d13d3fa0cfc78b4", + "type": "github" + }, + "original": { + "id": "nixpkgs", + "ref": "nixos-unstable", + "type": "indirect" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs", + "utils": "utils" + } + }, + "utils": { + "locked": { + "lastModified": 1605370193, + "narHash": "sha256-YyMTf3URDL/otKdKgtoMChu4vfVL3vCMkRqpGifhUn0=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "5021eac20303a61fafe17224c087f5519baed54d", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3d8cfbe --- /dev/null +++ b/flake.nix @@ -0,0 +1,26 @@ +{ + description = "A complete and Simple Nixos Mailserver"; + + inputs = { + utils.url = "github:numtide/flake-utils"; + nixpkgs.url = "flake:nixpkgs/nixos-unstable"; + }; + + outputs = { self, utils, nixpkgs }: { + nixosModules.mailserver = import ./.; + nixosModule = self.nixosModules.mailserver; + } // utils.lib.eachDefaultSystem (system: let + pkgs = nixpkgs.legacyPackages.${system}; + in { + devShell = pkgs.mkShell { + buildInputs = with pkgs; [ + (python3.withPackages (p: with p; [ + sphinx + sphinx_rtd_theme + ])) + jq + clamav + ]; + }; + }); +} diff --git a/nixops/single-server.nix b/nixops/single-server.nix index 115c593..c002da7 100644 --- a/nixops/single-server.nix +++ b/nixops/single-server.nix @@ -5,7 +5,7 @@ { config, pkgs, ... }: { imports = [ - ./../default.nix + ../default.nix ]; mailserver = { diff --git a/shell.nix b/shell.nix index 2c06231..d32886e 100644 --- a/shell.nix +++ b/shell.nix @@ -1,11 +1 @@ -let - nixpkgs = (import ./nix/sources.nix).nixpkgs-unstable; - pkgs = import nixpkgs {}; -in -pkgs.mkShell { - buildInputs = with pkgs; [ - (python3.withPackages(p: [p.sphinx p.sphinx_rtd_theme])) - niv - jq clamav - ]; -} +(import (builtins.fetchGit "https://github.com/edolstra/flake-compat") { src = ./.; }).shellNix