From 0103a1961804640c570f951f97420201cd219071 Mon Sep 17 00:00:00 2001 From: Minijackson Date: Tue, 9 Nov 2021 13:50:42 +0100 Subject: flake: add overlay and checks --- flake.nix | 63 +++++++++++++++++++++++++++++++++++++++++++++------------------ 1 file changed, 45 insertions(+), 18 deletions(-) (limited to 'flake.nix') diff --git a/flake.nix b/flake.nix index ad3d540..4dce373 100644 --- a/flake.nix +++ b/flake.nix @@ -2,26 +2,53 @@ description = "A simple bash library for your scripting needs"; inputs.flake-utils.url = "github:numtide/flake-utils"; + inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-21.05"; - outputs = { self, flake-utils }: + outputs = { self, flake-utils, nixpkgs, }: with flake-utils.lib; - eachSystem allSystems (system: { - - # Convert a path to a derivation - # This is done so we don't depend on nixpkgs - packages.bash-lib = with builtins; derivation { - name = "bash-lib.sh"; - src = readFile ./bash-lib.sh; - inherit system; - - builder = "/bin/sh"; - args = [ - (toFile "builder.sh" '' - echo "$src" > $out - '') - ]; + (eachDefaultSystem (system: + let + pkgs = import nixpkgs { + inherit system; + overlays = [ self.overlay ]; + }; + in + { + + packages.bash-lib = pkgs.bash-lib; + + defaultPackage = self.packages.${system}.bash-lib; + + })) // { + checks.x86_64-linux = { + runAndCheckDemo = + let + pkgs = import nixpkgs { + system = "x86_64-linux"; + overlays = [ self.overlay ]; + }; + in + pkgs.runCommand "runAndCheckDemo" { src = ./.; nativeBuildInputs = [ pkgs.shellcheck ]; } '' + unpackFile "$src" + cd */ + shellcheck ./bash-lib.sh + shellcheck -x ./demo.sh + + chmod +w . demo.sh + sed '/^fatal/d' -i demo.sh + + patchShebangs ./demo.sh + ./demo.sh + + touch $out + ''; }; - defaultPackage = self.packages.${system}.bash-lib; - }); + overlay = final: prev: { + bash-lib = final.writeTextFile { + name = "bash-lib.sh"; + text = builtins.readFile ./bash-lib.sh; + }; + }; + }; } -- cgit v1.2.3