1
1
mirror of https://github.com/divnix/digga.git synced 2024-09-11 06:55:55 +03:00

fix onboarding process for pulling template

This commit is contained in:
Parthiv Seetharaman 2022-04-03 10:12:00 -07:00 committed by David Arnold
parent afa1c70e0c
commit 1072583dbe
6 changed files with 166 additions and 161 deletions

View File

@ -20,7 +20,7 @@ of changes and progress.
# Usage
The best way to make use of library is with the [Official template][template].
Check out the [guide](https://digga.divnix.com/start) to get up and running.
Check out the [guide](./doc/start/index.md) to get up and running.
Also have a look at devos's [_flake.nix_](./examples/devos/flake.nix).
If anything is not immediately discoverable via our [`mkFlake`][mk-flake], please file a bug report.

View File

@ -11,5 +11,8 @@ let
) defaultNix;
in
# Pass this flake as inputs.digga
defaultNix // { inputs = defaultNix.inputs // { digga = defaultNix; }; }
defaultNix // {
inputs = defaultNix.inputs // { digga = defaultNix; };
shell = import ./shell.nix;
}

149
devShell.nix Normal file
View File

@ -0,0 +1,149 @@
{ system ? builtins.currentSystem
, inputs ? (import ./.).inputs
}:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
devshell = import inputs.devshell { inherit pkgs system; };
withCategory = category: attrset: attrset // { inherit category; };
utils = withCategory "utils";
docs = withCategory "docs";
makeDocs = {
name = "make-docs";
help = "Execute the docs creating jobs and place the results in ./doc";
command = ''
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceTopLevel" \
&& cp result "$PRJ_ROOT/doc/api-reference.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceChannels" \
&& cp result "$PRJ_ROOT/doc/api-reference-channels.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-channels.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceHome" \
&& cp result "$PRJ_ROOT/doc/api-reference-home.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-home.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceDevshell" \
&& cp result "$PRJ_ROOT/doc/api-reference-devshell.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-devshell.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceNixos" \
&& cp result "$PRJ_ROOT/doc/api-reference-nixos.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-nixos.md"
'';
};
test = type: name: withCategory "tests" {
name = "check-${name}";
help = "Checks ${name} ${type}";
command = ''
set -e
# set -x
diggaurl=
lockfile_updated=1
lockfile_present=1
tempdigga="\"path:$PRJ_ROOT\""
cleanup() {
if is $lockfile_present; then
git checkout -- flake.lock
elif is $lockfile_updated; then
git rm -f flake.lock
fi
# ensure: restore input
[ -z $diggaurl ] || ${pkgs.gnused}/bin/sed -i "s|$tempdigga|$diggaurl|g" flake.nix
}
digga_fixture() {
# ensure: replace input
diggaurl=$({ grep -o '"github:divnix/digga.*"' flake.nix || true; })
[ -z $diggaurl ] || ${pkgs.gnused}/bin/sed -i "s|$diggaurl|$tempdigga|g" flake.nix
}
trap_err() {
local ret=$?
cleanup
echo -e \
"\033[1m\033[31m""exit $ret: \033[0m\033[1m""command [$BASH_COMMAND] failed""\033[0m"
}
is () { [ "$1" -eq "0" ]; }
trap 'trap_err' ERR
# --------------------------------------------------------------------------------
cd $PRJ_ROOT/${type}/${name}
digga_fixture
test -f flake.lock && lockfile_present=$? || true
${pkgs.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?;
${pkgs.nixUnstable}/bin/nix flake show "$@"
${pkgs.nixUnstable}/bin/nix flake check "$@"
cleanup
'';
};
in
devshell.mkShell {
name = "digga";
packages = with pkgs; [
fd
nixpkgs-fmt
nixUnstable
];
env = [
{
name = "NIX_CONFIG";
value =
''extra-experimental-features = nix-command flakes
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='';
}
];
# 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
'');
commands = [
(utils {
command = "git rm --ignore-unmatch -f $PRJ_ROOT/{tests,examples}/*/flake.lock";
help = "Remove all lock files";
name = "rm-locks";
})
(utils {
name = "fmt";
help = "Check Nix formatting";
command = "nixpkgs-fmt \${@} $PRJ_ROOT";
})
(utils {
name = "evalnix";
help = "Check Nix parsing";
command = "fd --extension nix --exec nix-instantiate --parse --quiet {} >/dev/null";
})
(test "examples" "devos")
(test "examples" "groupByConfig")
(test "examples" "hmOnly")
(test "examples" "all" // { command = "check-devos && check-groupByConfig && check-hmOnly"; })
(docs { package = pkgs.mdbook; })
(docs makeDocs)
];
}

View File

@ -2,17 +2,18 @@
The only dependency is nix, so make sure you have it [installed][install-nix].
## Get the Template
Here is a snippet that will get you the template without the git history:
If you currently don't have flakes setup, you can utilize the digga shell to pull the template:
```sh
nix-shell -p cachix --run "cachix use nrdxp"
nix-shell https://github.com/divnix/devos/archive/main.tar.gz -A shell \
--run "bud get main"
cd devos
nix-shell
nix-shell "https://github.com/divnix/digga/archive/main.tar.gz" \
--run "nix flake init -t github:divnix/digga"
```
If you already have flakes support, you can directly pull the template:
```sh
nix flake init -t github:divnix/digga
```
Then make sure to create the git repository:
```sh
git init
git add .
git commit -m init

View File

@ -126,7 +126,7 @@
# system-space and pass sytem and input to each file
jobs = polyfillOutput ./jobs;
checks = polyfillOutput ./checks;
devShell = polyfillOutput ./shell.nix;
devShell = polyfillOutput ./devShell.nix;
};
}

150
shell.nix
View File

@ -1,149 +1 @@
{ system ? builtins.currentSystem
, inputs ? (import ./.).inputs
}:
let
pkgs = inputs.nixpkgs.legacyPackages.${system};
devshell = import inputs.devshell { inherit pkgs system; };
withCategory = category: attrset: attrset // { inherit category; };
utils = withCategory "utils";
docs = withCategory "docs";
makeDocs = {
name = "make-docs";
help = "Execute the docs creating jobs and place the results in ./doc";
command = ''
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceTopLevel" \
&& cp result "$PRJ_ROOT/doc/api-reference.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceChannels" \
&& cp result "$PRJ_ROOT/doc/api-reference-channels.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-channels.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceHome" \
&& cp result "$PRJ_ROOT/doc/api-reference-home.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-home.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceDevshell" \
&& cp result "$PRJ_ROOT/doc/api-reference-devshell.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-devshell.md"
nix build "$PRJ_ROOT#jobs.${pkgs.system}.mkApiReferenceNixos" \
&& cp result "$PRJ_ROOT/doc/api-reference-nixos.md" \
&& chmod 755 "$PRJ_ROOT//doc/api-reference-nixos.md"
'';
};
test = type: name: withCategory "tests" {
name = "check-${name}";
help = "Checks ${name} ${type}";
command = ''
set -e
# set -x
diggaurl=
lockfile_updated=1
lockfile_present=1
tempdigga="\"path:$PRJ_ROOT\""
cleanup() {
if is $lockfile_present; then
git checkout -- flake.lock
elif is $lockfile_updated; then
git rm -f flake.lock
fi
# ensure: restore input
[ -z $diggaurl ] || ${pkgs.gnused}/bin/sed -i "s|$tempdigga|$diggaurl|g" flake.nix
}
digga_fixture() {
# ensure: replace input
diggaurl=$({ grep -o '"github:divnix/digga.*"' flake.nix || true; })
[ -z $diggaurl ] || ${pkgs.gnused}/bin/sed -i "s|$diggaurl|$tempdigga|g" flake.nix
}
trap_err() {
local ret=$?
cleanup
echo -e \
"\033[1m\033[31m""exit $ret: \033[0m\033[1m""command [$BASH_COMMAND] failed""\033[0m"
}
is () { [ "$1" -eq "0" ]; }
trap 'trap_err' ERR
# --------------------------------------------------------------------------------
cd $PRJ_ROOT/${type}/${name}
digga_fixture
test -f flake.lock && lockfile_present=$? || true
${pkgs.nixUnstable}/bin/nix flake lock --update-input digga "$@"; lockfile_updated=$?;
${pkgs.nixUnstable}/bin/nix flake show "$@"
${pkgs.nixUnstable}/bin/nix flake check "$@"
cleanup
'';
};
in
devshell.mkShell {
name = "digga";
packages = with pkgs; [
fd
nixpkgs-fmt
nixUnstable
];
env = [
{
name = "NIX_CONFIG";
value =
''extra-experimental-features = nix-command flakes
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='';
}
];
# 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
'');
commands = [
(utils {
command = "git rm --ignore-unmatch -f $PRJ_ROOT/{tests,examples}/*/flake.lock";
help = "Remove all lock files";
name = "rm-locks";
})
(utils {
name = "fmt";
help = "Check Nix formatting";
command = "nixpkgs-fmt \${@} $PRJ_ROOT";
})
(utils {
name = "evalnix";
help = "Check Nix parsing";
command = "fd --extension nix --exec nix-instantiate --parse --quiet {} >/dev/null";
})
(test "examples" "devos")
(test "examples" "groupByConfig")
(test "examples" "hmOnly")
(test "examples" "all" // { command = "check-devos && check-groupByConfig && check-hmOnly"; })
(docs { package = pkgs.mdbook; })
(docs makeDocs)
];
}
import ./devShell.nix { }