2021-06-20 10:08:00 +03:00
|
|
|
{ inputs, system ? builtins.currentSystem }:
|
|
|
|
let
|
2021-06-20 05:42:51 +03:00
|
|
|
|
2021-07-16 23:40:39 +03:00
|
|
|
pkgs = import inputs.nixpkgs {
|
|
|
|
inherit system; config = { };
|
|
|
|
overlays = [
|
2021-07-16 23:54:02 +03:00
|
|
|
(import ./overlays/nix-patched.nix)
|
2021-07-16 23:40:39 +03:00
|
|
|
];
|
|
|
|
};
|
2021-06-20 05:42:51 +03:00
|
|
|
devshell = import inputs.devshell { inherit pkgs system; };
|
|
|
|
|
|
|
|
withCategory = category: attrset: attrset // { inherit category; };
|
|
|
|
util = withCategory "utils";
|
|
|
|
|
|
|
|
test = name: withCategory "tests" {
|
|
|
|
name = "check-${name}";
|
|
|
|
help = "Checks ${name} example";
|
|
|
|
command = ''
|
|
|
|
set -e
|
2021-06-24 22:24:10 +03:00
|
|
|
|
|
|
|
diggaurl=
|
|
|
|
lockfile_updated=1
|
|
|
|
lockfile_present=1
|
2021-07-15 04:07:19 +03:00
|
|
|
tempdigga="\"github:divnix/digga/$(git rev-parse HEAD)\""
|
2021-06-24 22:24:10 +03:00
|
|
|
|
|
|
|
cleanup() {
|
|
|
|
if is $lockfile_present; then
|
|
|
|
git checkout -- flake.lock
|
|
|
|
elif is $lockfile_updated; then
|
|
|
|
git rm -f flake.lock
|
|
|
|
fi
|
|
|
|
# ensure: restore input
|
2021-07-15 04:07:19 +03:00
|
|
|
[ -z $diggaurl ] || sed -i "s|$tempdigga|$diggaurl|g" flake.nix
|
2021-06-24 22:24:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
digga_fixture() {
|
|
|
|
# ensure: replace input
|
|
|
|
diggaurl=$({ grep -o '"github:divnix/digga.*"' flake.nix || true; })
|
2021-07-15 04:07:19 +03:00
|
|
|
sed -i "s|\"github:divnix/digga/.*\"|$tempdigga|g" flake.nix
|
2021-06-24 22:24:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
trap_err() {
|
|
|
|
local ret=$?
|
|
|
|
cleanup
|
|
|
|
echo -e \
|
2021-07-16 23:40:39 +03:00
|
|
|
"\033[1m\033[31m""exit $ret: \033[0m\033[1m""command [$BASH_COMMAND] failed""\033[0m"
|
2021-06-24 22:24:10 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
is () { [ "$1" -eq "0" ]; }
|
|
|
|
|
|
|
|
trap 'trap_err' ERR
|
|
|
|
|
|
|
|
# --------------------------------------------------------------------------------
|
|
|
|
|
2021-06-20 05:42:51 +03:00
|
|
|
cd $DEVSHELL_ROOT/examples/${name}
|
2021-06-24 22:24:10 +03:00
|
|
|
|
|
|
|
digga_fixture
|
|
|
|
|
|
|
|
test -f flake.lock && lockfile_present=$? || true
|
2021-06-30 23:22:21 +03:00
|
|
|
${pkgs.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?;
|
|
|
|
${pkgs.nixUnstable}/bin/nix flake show "$@"
|
|
|
|
${pkgs.nixUnstable}/bin/nix flake check "$@"
|
2021-06-24 22:24:10 +03:00
|
|
|
|
|
|
|
cleanup
|
2021-06-20 05:42:51 +03:00
|
|
|
'';
|
|
|
|
};
|
|
|
|
|
|
|
|
in
|
|
|
|
devshell.mkShell {
|
|
|
|
name = "digga";
|
|
|
|
packages = with pkgs; [
|
|
|
|
fd
|
|
|
|
nixpkgs-fmt
|
2021-06-30 23:22:21 +03:00
|
|
|
nixUnstable
|
2021-06-20 05:42:51 +03:00
|
|
|
];
|
|
|
|
|
2021-07-16 22:54:47 +03:00
|
|
|
env = [
|
|
|
|
{
|
|
|
|
name = "NIX_CONFIG";
|
|
|
|
value =
|
2021-07-16 23:40:39 +03:00
|
|
|
''extra-experimental-features = nix-command flakes ca-references
|
2021-07-16 22:54:47 +03:00
|
|
|
extra-substituters = https://nrdxp.cachix.org https://nix-community.cachix.org
|
|
|
|
extra-trusted-public-keys = nrdxp.cachix.org-1:Fc5PSqY2Jm1TrWfm88l6cvGWwz3s93c6IOifQWnhNW4= nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs='';
|
|
|
|
}
|
|
|
|
];
|
|
|
|
|
2021-06-30 23:20:05 +03:00
|
|
|
# tempfix: remove when merged https://github.com/numtide/devshell/pull/123
|
|
|
|
devshell.startup.load_profiles = pkgs.lib.mkForce (pkgs.lib.noDepEntry ''
|
|
|
|
# PATH is devshell's exorbitant privilige:
|
|
|
|
# fence against its pollution
|
|
|
|
_PATH=''${PATH}
|
|
|
|
# Load installed profiles
|
|
|
|
for file in "$DEVSHELL_DIR/etc/profile.d/"*.sh; do
|
|
|
|
# If that folder doesn't exist, bash loves to return the whole glob
|
|
|
|
[[ -f "$file" ]] && source "$file"
|
|
|
|
done
|
|
|
|
# Exert exorbitant privilige and leave no trace
|
|
|
|
export PATH=''${_PATH}
|
|
|
|
unset _PATH
|
|
|
|
'');
|
|
|
|
|
2021-06-20 05:42:51 +03:00
|
|
|
commands = [
|
|
|
|
{
|
|
|
|
command = "git rm --ignore-unmatch -f $DEVSHELL_ROOT/{tests,examples}/*/flake.lock";
|
|
|
|
help = "Remove all lock files";
|
|
|
|
name = "rm-locks";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "fmt";
|
|
|
|
help = "Check Nix formatting";
|
|
|
|
command = "nixpkgs-fmt \${@} $DEVSHELL_ROOT";
|
|
|
|
}
|
|
|
|
{
|
|
|
|
name = "evalnix";
|
|
|
|
help = "Check Nix parsing";
|
|
|
|
command = "fd --extension nix --exec nix-instantiate --parse --quiet {} >/dev/null";
|
|
|
|
}
|
|
|
|
|
2021-06-24 22:24:10 +03:00
|
|
|
(test "downstream")
|
2021-06-20 05:42:51 +03:00
|
|
|
(test "groupByConfig")
|
2021-07-16 03:55:15 +03:00
|
|
|
(test "hmOnly")
|
|
|
|
(test "all" // { command = "check-downstream && check-groupByConfig && check-hmOnly"; })
|
2021-06-20 05:42:51 +03:00
|
|
|
|
|
|
|
];
|
|
|
|
}
|