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.lock | 19 ++++++++++++++++++- flake.nix | 63 ++++++++++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 63 insertions(+), 19 deletions(-) diff --git a/flake.lock b/flake.lock index e03bfad..d820156 100644 --- a/flake.lock +++ b/flake.lock @@ -15,9 +15,26 @@ "type": "github" } }, + "nixpkgs": { + "locked": { + "lastModified": 1636333654, + "narHash": "sha256-3wh9PtCzcaJQuZrgZ+ygKfhltkDNNqT6zOzGsRbjZEo=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "e74894146a42ba552ebafa19ab2d1df7ccbc1738", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-21.05", + "repo": "nixpkgs", + "type": "github" + } + }, "root": { "inputs": { - "flake-utils": "flake-utils" + "flake-utils": "flake-utils", + "nixpkgs": "nixpkgs" } } }, 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