From 2fc05665715747185fe834365d02a495d93ecd80 Mon Sep 17 00:00:00 2001 From: Nicolas Mattia Date: Fri, 1 Feb 2019 15:51:40 +0100 Subject: [PATCH] Test that README is up-to-date --- .circleci/config.yml | 4 ++-- default.nix | 4 ++-- nix/default.nix | 2 +- nix/overlay.nix | 4 +++- nix/sources.nix | 5 ++++- script/test | 11 +++++++++++ 6 files changed, 23 insertions(+), 7 deletions(-) create mode 100755 script/test diff --git a/.circleci/config.yml b/.circleci/config.yml index 0bbf991..4583ed2 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -12,6 +12,7 @@ jobs: sudo chown circleci /nix bash <(curl https://nixos.org/nix/install) echo '. /home/circleci/.nix-profile/etc/profile.d/nix.sh' >> $BASH_ENV + sudo mkdir -p /etc/nix && echo "sandbox = true" | sudo tee -a /etc/nix/nix.conf - checkout - restore_cache: # Match on the latest cache for this branch @@ -35,8 +36,7 @@ jobs: - run: name: Nix build - command: | - nix-build --no-out-link --option sandbox true + command: ./script/test - run: name: Create cache diff --git a/default.nix b/default.nix index 26028ad..765e32e 100644 --- a/default.nix +++ b/default.nix @@ -1,2 +1,2 @@ -with { pkgs = import ./nix; }; -{ inherit (pkgs) niv readme ; } +with { pkgs = import ./nix {}; }; +{ inherit (pkgs) niv readme readme-test ; } diff --git a/nix/default.nix b/nix/default.nix index f5efbae..b6c5d55 100644 --- a/nix/default.nix +++ b/nix/default.nix @@ -1,3 +1,3 @@ -with { sources = import ./sources.nix; }; +{ sources ? import ./sources.nix }: import sources.nixpkgs { overlays = import ./overlay.nix { inherit sources; } ; config = {}; } diff --git a/nix/overlay.nix b/nix/overlay.nix index 09f8dbc..aba0b87 100644 --- a/nix/overlay.nix +++ b/nix/overlay.nix @@ -16,7 +16,7 @@ # README generation (self: super: - { readme = self.writeText "README.md" + rec { readme = self.writeText "README.md" (with { template = builtins.readFile ../README.tpl.md; niv_help = builtins.readFile @@ -46,6 +46,8 @@ [ niv_help niv_add_help niv_update_help niv_drop_help ] template ); + readme-test = self.runCommand "README-test" {} + "diff ${../README.md} ${readme} && echo dummy > $out"; } ) ] diff --git a/nix/sources.nix b/nix/sources.nix index 8135bd5..2ae3408 100644 --- a/nix/sources.nix +++ b/nix/sources.nix @@ -10,10 +10,13 @@ with builtins.fetchTarball { inherit url; } else builtins.fetchTarball { inherit url sha256; }; + mapAttrs = builtins.mapAttrs or + (f: set: with builtins; + listToAttrs (map (attr: { name = attr; value = f attr set.${attr}; }) (attrNames set))); }; # NOTE: spec must _not_ have an "outPath" attribute -builtins.mapAttrs (_: spec: +mapAttrs (_: spec: if builtins.hasAttr "outPath" spec then abort "The values in versions.json should not have an 'outPath' attribute" diff --git a/script/test b/script/test new file mode 100755 index 0000000..4c73862 --- /dev/null +++ b/script/test @@ -0,0 +1,11 @@ +#!/usr/bin/env nix-shell +#!nix-shell -i bash +#!nix-shell -I nixpkgs=./nix +#!nix-shell -p nix +#!nix-shell --pure + +echo "Building" + +nix build --no-link + +echo "all good"