Skip to content

Commit

Permalink
build(flake): add template
Browse files Browse the repository at this point in the history
  • Loading branch information
loicreynier committed Mar 8, 2024
1 parent 5c5fae8 commit bd0a09b
Show file tree
Hide file tree
Showing 8 changed files with 84 additions and 3 deletions.
5 changes: 5 additions & 0 deletions .templates/flake/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if has nix; then
use flake .
fi

# vim: ft=sh
3 changes: 3 additions & 0 deletions .templates/flake/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Nix generated
/.pre-commit-config.yaml
result
3 changes: 3 additions & 0 deletions .templates/flake/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# `sandbox`

A description fitting in one single line.
27 changes: 27 additions & 0 deletions .templates/flake/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
{
description = "Sandbox template";

outputs = {
self,
nixpkgs,
}: let
supportedSystems = [
"x86_64-linux"
];
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
nixpkgsFor = forAllSystems (system: import nixpkgs {inherit system;});
in {
devShells = forAllSystems (system: let
pkgs = nixpkgsFor.${system};
in {
default = pkgs.mkShell {
name = "sandbox-nix-shell";
buildInputs = with pkgs; [
just
];
};
});
};

inputs.nixpkgs.url = "github:NixOS/nixpkgs";
}
5 changes: 5 additions & 0 deletions .templates/shell/.envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
if has nix; then
use nix
fi

# vim: ft=sh
14 changes: 14 additions & 0 deletions .templates/shell/shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
pkgs ? (
let
inherit (builtins) fetchTree fromJSON readFile;
inherit ((fromJSON (readFile ../flake.lock)).nodes) nixpkgs;
in
import (fetchTree nixpkgs.locked) {}
),
}:
pkgs.mkShell {
packages = with pkgs; [
hello
];
}
12 changes: 12 additions & 0 deletions Justfile
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,15 @@
build-readme:
@python make_readme.py
@sh .github/make-readme.sh

# Create sandbox
create-sandbox sandbox:
@mkdir -v "{{justfile_directory()}}/{{sandbox}}"
@cd "{{justfile_directory()}}/{{sandbox}}" \
&& nix flake init -t "{{justfile_directory()}}#templates.shell"

# Create sandbox with Flake
create-sandbox-flake sandbox:
@mkdir -v "{{justfile_directory()}}/{{sandbox}}"
@cd "{{justfile_directory()}}/{{sandbox}}" \
&& nix flake init -t "{{justfile_directory()}}#templates.flake"
18 changes: 15 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,26 @@
}: let
supportedSystems = ["x86_64-linux"];
in
flake-utils.lib.eachSystem supportedSystems (system: let
{
templates = {
flake = {
path = ./.templates/flake;
description = "Sandbox with flake";
};
shell = {
path = ./.templates/shell;
description = "Sandbox with only a Nix shell";
};
};
}
// flake-utils.lib.eachSystem supportedSystems (system: let
pkgs = import nixpkgs {inherit system;};
in rec {
in {
checks = {
pre-commit-check = pre-commit-hooks.lib.${system}.run {
src = ./.;

hooks = with pkgs; {
hooks = {
make_readme = {
enable = true;
name = "make-readme";
Expand Down

0 comments on commit bd0a09b

Please sign in to comment.