From 08715eacf11e0c086fe8a09d3ccf6e9c91a60de4 Mon Sep 17 00:00:00 2001 From: Simon Bruder Date: Sun, 2 May 2021 09:35:21 +0200 Subject: [PATCH] Convert to flake --- default.nix | 25 ---------------------- flake.lock | 43 ++++++++++++++++++++++++++++++++++++++ flake.nix | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++ module.nix | 2 +- test.nix | 18 ++++++++++------ 5 files changed, 116 insertions(+), 32 deletions(-) delete mode 100644 default.nix create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/default.nix b/default.nix deleted file mode 100644 index d6f3f70..0000000 --- a/default.nix +++ /dev/null @@ -1,25 +0,0 @@ -{ pkgs ? import { } }: -let - gitignoreSrc = pkgs.fetchFromGitHub { - owner = "hercules-ci"; - repo = "gitignore"; - rev = "c4662e662462e7bf3c2a968483478a665d00e717"; - sha256 = "1npnx0h6bd0d7ql93ka7azhj40zgjp815fw2r6smg8ch9p7mzdlx"; - }; - inherit (import gitignoreSrc { inherit (pkgs) lib; }) gitignoreSource; -in -pkgs.buildGoModule { - name = "bang-evaluator"; - - src = gitignoreSource ./.; - - subPackages = [ "." ]; - - vendorSha256 = "11r1l5lcdfm3wymrkbddl5khpjmr30jln31l40mfyyy9msnqayf3"; - - preBuild = ''go generate ./...''; - - doCheck = false; # no tests (yet?) - - meta.license = pkgs.lib.licenses.mit; -} diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..98163ca --- /dev/null +++ b/flake.lock @@ -0,0 +1,43 @@ +{ + "nodes": { + "flake-utils": { + "locked": { + "lastModified": 1619345332, + "narHash": "sha256-qHnQkEp1uklKTpx3MvKtY6xzgcqXDsz5nLilbbuL+3A=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "2ebf2558e5bf978c7fb8ea927dfaed8fefab2e28", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1619907998, + "narHash": "sha256-laZ15ZpbbqQof9XptcfgI8rvygiD69UeIzf4tGV7vJk=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "2cca79be09cbf2c3c4a6ca5d095b1c60135cafc9", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..37ce83a --- /dev/null +++ b/flake.nix @@ -0,0 +1,60 @@ +{ + description = "A web service to evaluate DuckDuckGo-style bangs in search queries"; + + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-utils.url = "github:numtide/flake-utils"; + }; + + outputs = { self, flake-utils, nixpkgs }: { + overlay = final: prev: { + bang-evaluator = prev.buildGoModule { + name = "bang-evaluator"; + + src = self; + + subPackages = [ "." ]; + + vendorSha256 = "11r1l5lcdfm3wymrkbddl5khpjmr30jln31l40mfyyy9msnqayf3"; + + preBuild = ''go generate ./...''; + + doCheck = false; # no tests (yet?) + + meta = with prev.lib; { + license = licenses.mit; + maintainer = with mainatiners; [ sbruder ]; + }; + }; + }; + + nixosModules.bang-evaluator = { + imports = [ ./module.nix ]; + + nixpkgs.overlays = [ + self.overlay + ]; + }; + } // flake-utils.lib.eachSystem [ "aarch64-linux" "x86_64-linux" ] (system: + let + pkgs = import nixpkgs { inherit system; overlays = [ self.overlay ]; }; + in + rec { + packages = { + inherit (pkgs) bang-evaluator; + }; + + defaultPackage = packages.bang-evaluator; + defaultApp = { + type = "app"; + program = "${packages.bang-evaluator}/bin/evaluator"; + }; + + checks = { + integration-test = import ./test.nix { + inherit nixpkgs system; + inherit (self) nixosModules; + }; + }; + }); +} diff --git a/module.nix b/module.nix index 02c29ce..ab5545c 100644 --- a/module.nix +++ b/module.nix @@ -7,7 +7,7 @@ in enable = lib.mkEnableOption "bang-evaluator"; package = lib.mkOption { type = lib.types.package; - default = import ./default.nix { inherit pkgs; }; + default = pkgs.bang-evaluator; example = "pkgs.bang-exporter-fork"; description = "The package to use for bang-exporter"; }; diff --git a/test.nix b/test.nix index 35a9ab7..f117a9d 100644 --- a/test.nix +++ b/test.nix @@ -1,11 +1,15 @@ +{ nixpkgs, system, nixosModules }: +with import (nixpkgs + "/nixos/lib/testing-python.nix") +{ + inherit system; +}; let port = 8082; in -import ({ pkgs, ... }: -{ +makeTest { nodes = { server = { - imports = [ ./module.nix ]; + imports = [ nixosModules.bang-evaluator ]; services.bang-evaluator = { enable = true; @@ -14,7 +18,9 @@ import ({ pkgs, ... }: networking.firewall.allowedTCPPorts = [ port ]; }; - client = { }; + client = { pkgs, ... }: { + environment.systemPackages = with pkgs; [ curl ]; + }; }; testScript = '' @@ -29,7 +35,7 @@ import ({ pkgs, ... }: return client.succeed( " ".join( [ - "${pkgs.curl}/bin/curl", + "curl", "-s", "-o/dev/null", "-w", @@ -52,4 +58,4 @@ import ({ pkgs, ... }: == "https://startpage.com/sp/search?query=foo" ) ''; -}) +}