From 5ec5d1a6fc94215c3de1f4f3d26f0b66de3fb6cb Mon Sep 17 00:00:00 2001 From: Lord-Valen Date: Fri, 4 Nov 2022 14:52:28 -0400 Subject: [PATCH 1/4] :recycle: `env` Ignore example lock files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 726d2d6..d268a08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ result .direnv +examples/**/flake.lock From f8ec6efba4fa6348379896ac3a3e0080926b8631 Mon Sep 17 00:00:00 2001 From: Lord-Valen Date: Fri, 4 Nov 2022 14:55:48 -0400 Subject: [PATCH 2/4] :bulb: `refactor` Improved flake-compat Get the rev from the flake.lock file. Shouldn't be an issue for first time users as the guide instructs users to generate a lock file. `builtins.file` was used in accordance with nix.dev reccommendations. https://nix.dev/anti-patterns/language#reproducibility-referencing-top-level-directory-with --- examples/devos/flake.nix | 5 +++++ examples/devos/lib/compat/default.nix | 8 ++++---- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/examples/devos/flake.nix b/examples/devos/flake.nix index 4c5e8fb..632917d 100644 --- a/examples/devos/flake.nix +++ b/examples/devos/flake.nix @@ -7,6 +7,11 @@ inputs = { + flake-compat = { + url = "github:edolstra/flake-compat"; + flake = false; + }; + # Track channels with commits tested and built by hydra nixos.url = "github:nixos/nixpkgs/nixos-22.05"; latest.url = "github:nixos/nixpkgs/nixos-unstable"; diff --git a/examples/devos/lib/compat/default.nix b/examples/devos/lib/compat/default.nix index 9d0c283..ae3b442 100644 --- a/examples/devos/lib/compat/default.nix +++ b/examples/devos/lib/compat/default.nix @@ -1,14 +1,14 @@ let - rev = "e7e5d481a0e15dcd459396e55327749989e04ce0"; + lock = builtins.fromJSON (builtins.readFile builtins.path { path = ../../flake.lock; name = "lockPath"; }); flake = (import ( fetchTarball { - url = "https://github.com/edolstra/flake-compat/archive/${rev}.tar.gz"; - sha256 = "0zd3x46fswh5n6faq4x2kkpy6p3c6j593xbdlbsl40ppkclwc80x"; + url = "https://github.com/edolstra/flake-compat/archive/${lock.nodes.flake-compat.locked.rev}.tar.gz"; + sha256 = lock.nodes.flake-compat.locked.narHash; } ) { - src = ../../.; + src = builtins.path { path = ../../.; name = "projectRoot"; }; }); in flake From aa7dc0e6c35b0616911568863eef14b10565e56c Mon Sep 17 00:00:00 2001 From: Lord-Valen Date: Fri, 4 Nov 2022 15:02:10 -0400 Subject: [PATCH 3/4] :bulb: `refactor` Check exit code directly Eliminated the redundant check for the exit code of `editorconfig-checker`. This way is more explicit and idiomatic. https://github.com/koalaman/shellcheck/wiki/SC2181 --- examples/devos/shell/hooks/pre-commit.sh | 25 +++++++++++------------- 1 file changed, 11 insertions(+), 14 deletions(-) diff --git a/examples/devos/shell/hooks/pre-commit.sh b/examples/devos/shell/hooks/pre-commit.sh index a7fa908..795a5b6 100755 --- a/examples/devos/shell/hooks/pre-commit.sh +++ b/examples/devos/shell/hooks/pre-commit.sh @@ -1,7 +1,6 @@ #!/usr/bin/env bash -if git rev-parse --verify HEAD >/dev/null 2>&1 -then +if git rev-parse --verify HEAD >/dev/null 2>&1; then against=HEAD else # Initial commit: diff against an empty tree object @@ -14,19 +13,17 @@ nix_files=($($diff -- '*.nix')) all_files=($($diff)) # Format staged nix files. -if (( ${#nix_files[@]} != 0 )); then - nixpkgs-fmt "${nix_files[@]}" \ - && git add "${nix_files[@]}" +if ((${#nix_files[@]} != 0)); then + nixpkgs-fmt "${nix_files[@]}" && + git add "${nix_files[@]}" fi # check editorconfig -if (( ${#all_files[@]} != 0 )); then - editorconfig-checker -- "${all_files[@]}" -fi - -if [[ $? != '0' ]]; then - printf "%b\n" \ - "\nCode is not aligned with .editorconfig" \ - "Review the output and commit your fixes" >&2 - exit 1 +if ((${#all_files[@]} != 0)); then + if ! editorconfig-checker -- "${all_files[@]}"; then + printf "%b\n" \ + "\nCode is not aligned with .editorconfig" \ + "Review the output and commit your fixes" >&2 + exit 1 + fi fi From 226942bb79db1a6bf0493f0e5f7eff700df9f807 Mon Sep 17 00:00:00 2001 From: Lord-Valen Date: Fri, 4 Nov 2022 15:15:04 -0400 Subject: [PATCH 4/4] :brain: `redesign` Rm tempfix --- examples/devos/shell/devos.nix | 15 --------------- 1 file changed, 15 deletions(-) diff --git a/examples/devos/shell/devos.nix b/examples/devos/shell/devos.nix index efa0187..357ad47 100644 --- a/examples/devos/shell/devos.nix +++ b/examples/devos/shell/devos.nix @@ -25,21 +25,6 @@ in imports = [ "${extraModulesPath}/git/hooks.nix" ]; git = { inherit hooks; }; - # 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 = [ (devos nixUnstable) (devos agenix)