From 7d23fc01f00a9cb4dfba5a5cfe2ab77bf078b84f Mon Sep 17 00:00:00 2001 From: mawalu Date: Thu, 6 Oct 2022 23:10:47 +0200 Subject: [PATCH] Flakeify --- .gitignore | 1 + flake.lock | 26 ++++++++++++++++++++++ flake.nix | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++ norbert.nimble | 13 +++++++++++ 4 files changed, 100 insertions(+) create mode 100644 flake.lock create mode 100644 flake.nix create mode 100644 norbert.nimble diff --git a/.gitignore b/.gitignore index 6b956b3..0b0fab4 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ norbert .idea +result diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..595a33e --- /dev/null +++ b/flake.lock @@ -0,0 +1,26 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1665087388, + "narHash": "sha256-FZFPuW9NWHJteATOf79rZfwfRn5fE0wi9kRzvGfDHPA=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "95fda953f6db2e9496d2682c4fc7b82f959878f7", + "type": "github" + }, + "original": { + "owner": "NixOS", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..4d4c22f --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + description = "A DNS server for the ACME DNS-01 challenge written in dependency-free nim"; + + inputs.nixpkgs.url = github:NixOS/nixpkgs; + + outputs = { self, nixpkgs }: + let + # System types to support. + supportedSystems = [ "x86_64-linux" "aarch64-darwin" ]; + + # Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'. + forAllSystems = nixpkgs.lib.genAttrs supportedSystems; + + # Nixpkgs instantiated for supported system types. + nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; }); + in + { + packages = forAllSystems(system: + let + pkgs = nixpkgsFor.${system}; + in + { + default = pkgs.nimPackages.buildNimPackage { + name = "norbert"; + src = self; + }; + } + ); + + nixosModules.default = { config, lib, pkgs, ... }: + with lib; + let cfg = config.mawalu.services.norbert; + in + { + options.mawalu.services.norbert = { + enable = mkEnableOption "Enable the norbert DNS server"; + + config = { + baseDomain = mkOption { + type = types.str; + description = "Base domain"; + }; + }; + }; + + config = mkIf cfg.enable { + systemd.services.norbert = { + wantedBy = [ "multi-user.target" ]; + + serviceConfig = let pkg = self.packages.${pkgs.system}.default; + in { + Restart = "on-failure"; + ExecStart = "${pkg}/bin/norbert ${toINI cfg.config}"; + DynamicUser = "yes"; + }; + }; + }; + }; + }; +} diff --git a/norbert.nimble b/norbert.nimble new file mode 100644 index 0000000..a407772 --- /dev/null +++ b/norbert.nimble @@ -0,0 +1,13 @@ +# Package + +version = "1.0.0" +author = "mawalu" +description = "A DNS server for the ACME DNS-01 challenge" +license = "MIT" +srcDir = "." +bin = @["norbert"] + + +# Dependencies + +requires "nim >= 1.6.0"