Skip to content

Commit

Permalink
Make scripts less janky
Browse files Browse the repository at this point in the history
  • Loading branch information
lucperkins committed Apr 15, 2024
1 parent 8f13f3a commit d0e18d0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 22 deletions.
1 change: 1 addition & 0 deletions empty/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use flake
53 changes: 31 additions & 22 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,58 +6,67 @@
outputs = { self, nixpkgs }:
let
overlays = [
(final: prev:
let
exec = pkg: "${prev.${pkg}}/bin/${pkg}";
in
{
format = prev.writeScriptBin "format" ''
${exec "nixpkgs-fmt"} **/*.nix
'';

check = prev.writeScriptBin "check" ''
for dir in `ls -d */`; do # Iterate through all the templates
(final: prev: {
format = final.writeShellApplication {
name = "format";
runtimeInputs = with final; [ nixpkgs-fmt ];
text = "nixpkgs-fmt '**/*.nix'";
};

check = final.writeShellApplication {
name = "check";
text = ''
SYSTEM=$(nix eval --impure --raw --expr 'builtins.currentSystem')
for dir in */; do # Iterate through all the templates
(
cd $dir
cd "''${dir}"
echo "checking ''${dir}"
nix flake check --all-systems --no-build
echo "building ''${dir}"
nix build ".#devShells.''${SYSTEM}.default"
)
done
'';
};

dvt = prev.writeScriptBin "dvt" ''
dvt = final.writeShellApplication {
name = "dvt";
text = ''
if [ -z $1 ]; then
echo "no template specified"
exit 1
fi
TEMPLATE=$1
${exec "nix"} \
nix \
--experimental-features 'nix-command flakes' \
flake init \
--template \
"github:the-nix-way/dev-templates#''${TEMPLATE}"
'';
};

update = prev.writeScriptBin "update" ''
for dir in `ls -d */`; do # Iterate through all the templates
update = final.writeShellApplication {
name = "update";
text = ''
for dir in */; do # Iterate through all the templates
(
cd $dir
cd "''${dir}"
echo "updating ''${dir}"
# Update flake.lock
nix flake update
echo "checking ''${dir}"
# Make sure things work after the update
nix flake check --all-systems --no-build
)
done
'';
})
};
})
];
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
forEachSupportedSystem = f: nixpkgs.lib.genAttrs supportedSystems (system: f {
Expand Down

0 comments on commit d0e18d0

Please sign in to comment.