Convert to flake

This commit is contained in:
Simon Bruder 2021-05-02 09:35:21 +02:00
parent ca0d9ed47b
commit 08715eacf1
Signed by: simon
GPG key ID: 8D3C82F9F309F8EC
5 changed files with 116 additions and 32 deletions

View file

@ -1,25 +0,0 @@
{ pkgs ? import <nixpkgs> { } }:
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;
}

43
flake.lock Normal file
View file

@ -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
}

60
flake.nix Normal file
View file

@ -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;
};
};
});
}

View file

@ -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";
};

View file

@ -1,11 +1,15 @@
{ nixpkgs, system, nixosModules }:
with import (nixpkgs + "/nixos/lib/testing-python.nix")
{
inherit system;
};
let
port = 8082;
in
import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, ... }:
{
makeTest {
nodes = {
server = {
imports = [ ./module.nix ];
imports = [ nixosModules.bang-evaluator ];
services.bang-evaluator = {
enable = true;
@ -14,7 +18,9 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, ... }:
networking.firewall.allowedTCPPorts = [ port ];
};
client = { };
client = { pkgs, ... }: {
environment.systemPackages = with pkgs; [ curl ];
};
};
testScript = ''
@ -29,7 +35,7 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, ... }:
return client.succeed(
" ".join(
[
"${pkgs.curl}/bin/curl",
"curl",
"-s",
"-o/dev/null",
"-w",
@ -52,4 +58,4 @@ import <nixpkgs/nixos/tests/make-test-python.nix> ({ pkgs, ... }:
== "https://startpage.com/sp/search?query=foo"
)
'';
})
}