Skip to content

Commit

Permalink
refactor(scripts): move to scripts.nix
Browse files Browse the repository at this point in the history
  • Loading branch information
r17x committed Jul 6, 2023
1 parent a3c97ff commit c9899c2
Show file tree
Hide file tree
Showing 2 changed files with 56 additions and 48 deletions.
61 changes: 13 additions & 48 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -8,62 +8,27 @@

outputs = { self, nixpkgs, utils }: {

overlay = final: prev:
let scripts = prev.callPackage ./scripts.nix { }; in
{
inherit (scripts) format update test-develop dvt;
};

templates = import ./templates.nix;

} // utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs { inherit system; };

inherit (pkgs) mkShell writeScriptBin;

run = pkg: "${pkgs.${pkg}}/bin/${pkg}";

dvt = writeScriptBin "dvt"
''
if [ -z $1 ]; then
echo "no template specified"
exit 1
fi
TEMPLATE=$1
${run "nix"} \
--experimental-features 'nix-command flakes' \
flake init \
--template \
"github:efishery/dvt#''${TEMPLATE}"
'';

format = writeScriptBin "format"
''
${run "nixpkgs-fmt"} **/*.nix
'';

update = writeScriptBin "update"
''
for dir in `ls -d */`; do
(
cd $dir
${run "nix"} flake update # Update flake.lock
${run "nix"} develop $dir # Make sure this work after update
)
done
'';

test-develop = writeScriptBin "test-develop"
''
for dir in `ls -d */`; do
(
${run "nix"} develop $dir # Make sure this work after update
sleep 0.2
)
done
'';
overlays = [ (self.overlay) ];
pkgs = import nixpkgs { inherit system overlays; };
in
{
devShells.default = mkShell { buildInputs = [ format update ]; };
devShells.default = pkgs.mkShell { buildInputs = with pkgs; [ format update ]; };

packages = {
default = dvt;
inherit dvt test-develop;
dvt-init = pkgs.dvt;
dvt-format = pkgs.format;
dvt-update = pkgs.update;
inherit (pkgs) test-develop;
};
});
}
43 changes: 43 additions & 0 deletions scripts.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
{ writeScriptBin, nix, nixpkgs-fmt }:
{
update = writeScriptBin "update"
''
for dir in `ls -d */`; do
(
cd $dir
${nix}/bin/nix flake update # Update flake.lock
${nix}/bin/nix develop $dir # Make sure this work after update
)
done
'';

test-develop = writeScriptBin "test-develop"
''
for dir in `ls -d */`; do
(
${nix}/bin/nix develop $dir # Make sure this work after update
sleep 0.2
)
done
'';

format = writeScriptBin "format"
''
${nixpkgs-fmt}/bin/nixpkgs-fmt **/*.nix
'';

dvt = writeScriptBin "dvt"
''
if [ -z $1 ]; then
echo "no template specified"
exit 1
fi
TEMPLATE=$1
${nix}/bin/nix \
--experimental-features 'nix-command flakes' \
flake init \
--template \
"github:efishery/dvt#''${TEMPLATE}"
'';
}

0 comments on commit c9899c2

Please sign in to comment.