Skip to content

Commit

Permalink
Streamline scripts again
Browse files Browse the repository at this point in the history
  • Loading branch information
lucperkins committed Apr 15, 2024
1 parent 7c3ef7b commit d6bccb7
Showing 1 changed file with 61 additions and 66 deletions.
127 changes: 61 additions & 66 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,78 +6,73 @@
outputs = { self, nixpkgs }:
let
overlays = [
(final: prev: {
format = final.writeShellApplication {
name = "format";
runtimeInputs = with final; [ nixpkgs-fmt ];
text = "nixpkgs-fmt '**/*.nix'";
};

# only run this locally, as Actions will run out of disk space
build = final.writeShellApplication {
name = "build";
text = ''
SYSTEM=$(nix eval --impure --raw --expr 'builtins.currentSystem')
for dir in */; do # Iterate through all the templates
(final: prev:
let
getSystem = "SYSTEM=$(nix eval --impure --raw --expr 'builtins.currentSystem')";
forEachDir = exec: ''
for dir in */; do
(
cd "''${dir}"
nix build ".#devShells.''${SYSTEM}.default"
)
done
'';
};

check = final.writeShellApplication {
name = "check";
text = ''
for dir in */; do # Iterate through all the templates
(
cd "''${dir}"
echo "checking ''${dir}"
nix flake check --all-systems --no-build
)
done
'';
};

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

update = final.writeShellApplication {
name = "update";
text = ''
for dir in */; do # Iterate through all the templates
(
cd "''${dir}"
echo "updating ''${dir}"
nix flake update
echo "checking ''${dir}"
nix flake check --all-systems --no-build
${exec}
)
done
'';
};
})
in
{
format = final.writeShellApplication {
name = "format";
runtimeInputs = with final; [ nixpkgs-fmt ];
text = "nixpkgs-fmt '**/*.nix'";
};

# only run this locally, as Actions will run out of disk space
build = final.writeShellApplication {
name = "build";
text = ''
${getSystem}
${forEachDir ''
echo "building ''${dir}"
nix build ".#devShells.''${SYSTEM}.default"
''}
'';
};

check = final.writeShellApplication {
name = "check";
text = forEachDir ''
echo "checking ''${dir}"
nix flake check --all-systems --no-build
'';
};

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

update = final.writeShellApplication {
name = "update";
text = forEachDir ''
echo "updating ''${dir}"
nix flake update
'';
};
})
];
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 d6bccb7

Please sign in to comment.