From 8b70b13ff349b106be9fd002e3a3c93a55d56e89 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Wed, 20 Mar 2024 14:23:41 +0000 Subject: [PATCH 1/8] works --- .gitignore | 6 +++- flake.lock | 64 +++++++++++++++++++++++++++++++++ flake.nix | 41 +++++++++++++++++++++ modules/bash-commons/install.sh | 2 +- 4 files changed, 111 insertions(+), 2 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix diff --git a/.gitignore b/.gitignore index e2e7cb0..80ea171 100644 --- a/.gitignore +++ b/.gitignore @@ -13,4 +13,8 @@ build/ out/ # Python -*.pyc \ No newline at end of file +*.pyc + +# Nix +result +result/** \ No newline at end of file diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..6ae9a72 --- /dev/null +++ b/flake.lock @@ -0,0 +1,64 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1709336216, + "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1710806803, + "narHash": "sha256-qrxvLS888pNJFwJdK+hf1wpRCSQcqA6W5+Ox202NDa0=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "b06025f1533a1e07b6db3e75151caa155d1c7eb3", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1709237383, + "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..e692fd8 --- /dev/null +++ b/flake.nix @@ -0,0 +1,41 @@ +{ + description = "bash-commons via nix flakes"; + inputs = { + flake-parts.url = "github:hercules-ci/flake-parts"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + }; + + outputs = inputs@{ flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; + perSystem = { config, self', inputs', pkgs, system, ... }: { + packages.default = pkgs.stdenvNoCC.mkDerivation rec { + pname = "bash-commons"; + version = "0.1.9"; + src = ./modules/bash-commons/src; + phases = [ "installPhase" "fixupPhase" ]; + installPhase = '' + mkdir -p $out/bin + cp $src/array.sh $out/bin/array.sh + cp $src/assert.sh $out/bin/assert.sh + cp $src/file.sh $out/bin/file.sh + cp $src/log.sh $out/bin/log.sh + cp $src/string.sh $out/bin/string.sh + cp $src/string.sh $out/bin/os.sh + + chmod +x $out/bin/array.sh + chmod +x $out/bin/assert.sh + chmod +x $out/bin/file.sh + chmod +x $out/bin/log.sh + chmod +x $out/bin/string.sh + chmod +x $out/bin/os.sh + ''; + + doCheck = false; + }; + devShells.default = pkgs.mkShell { + buildInputs = [ self'.packages.default ]; + }; + }; + }; +} diff --git a/modules/bash-commons/install.sh b/modules/bash-commons/install.sh index c67605f..f714a0a 100755 --- a/modules/bash-commons/install.sh +++ b/modules/bash-commons/install.sh @@ -21,7 +21,7 @@ function print_usage { echo echo "Usage: install.sh [options]" echo - echo "This script is used by the Gruntwork Installter to install the bash-commons library." + echo "This script is used by the Gruntwork Installer to install the bash-commons library." echo echo "Options:" echo From 59b40de971cc7a5a543bba24c600e63e817f8eda Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Fri, 10 May 2024 22:47:51 +0100 Subject: [PATCH 2/8] update nix --- flake.lock | 32 +++++++++++++------------------- flake.nix | 24 ++++++++++++++++-------- 2 files changed, 29 insertions(+), 27 deletions(-) diff --git a/flake.lock b/flake.lock index 6ae9a72..3b501db 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1709336216, - "narHash": "sha256-Dt/wOWeW6Sqm11Yh+2+t0dfEWxoMxGBvv3JpIocFl9E=", + "lastModified": 1714641030, + "narHash": "sha256-yzcRNDoyVP7+SCNX0wmuDju1NUCt8Dz9+lyUXEI0dbI=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "f7b3c975cf067e56e7cda6cb098ebe3fb4d74ca2", + "rev": "e5d10a24b66c3ea8f150e47dfdb0416ab7c3390e", "type": "github" }, "original": { @@ -20,36 +20,30 @@ }, "nixpkgs": { "locked": { - "lastModified": 1710806803, - "narHash": "sha256-qrxvLS888pNJFwJdK+hf1wpRCSQcqA6W5+Ox202NDa0=", + "lastModified": 1715218190, + "narHash": "sha256-R98WOBHkk8wIi103JUVQF3ei3oui4HvoZcz9tYOAwlk=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "b06025f1533a1e07b6db3e75151caa155d1c7eb3", + "rev": "9a9960b98418f8c385f52de3b09a63f9c561427a", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-unstable", + "ref": "nixos-23.11", "repo": "nixpkgs", "type": "github" } }, "nixpkgs-lib": { "locked": { - "dir": "lib", - "lastModified": 1709237383, - "narHash": "sha256-cy6ArO4k5qTx+l5o+0mL9f5fa86tYUX3ozE1S+Txlds=", - "owner": "NixOS", - "repo": "nixpkgs", - "rev": "1536926ef5621b09bba54035ae2bb6d806d72ac8", - "type": "github" + "lastModified": 1714640452, + "narHash": "sha256-QBx10+k6JWz6u7VsohfSw8g8hjdBZEf8CFzXH1/1Z94=", + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" }, "original": { - "dir": "lib", - "owner": "NixOS", - "ref": "nixos-unstable", - "repo": "nixpkgs", - "type": "github" + "type": "tarball", + "url": "https://github.com/NixOS/nixpkgs/archive/50eb7ecf4cd0a5756d7275c8ba36790e5bd53e33.tar.gz" } }, "root": { diff --git a/flake.nix b/flake.nix index e692fd8..84246ec 100644 --- a/flake.nix +++ b/flake.nix @@ -2,18 +2,26 @@ description = "bash-commons via nix flakes"; inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; + nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; }; - outputs = inputs@{ flake-parts, ... }: - flake-parts.lib.mkFlake { inherit inputs; } { - systems = [ "x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin" ]; - perSystem = { config, self', inputs', pkgs, system, ... }: { + outputs = inputs @ {flake-parts, ...}: + flake-parts.lib.mkFlake {inherit inputs;} { + systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; + perSystem = { + config, + self', + inputs', + pkgs, + system, + ... + }: { + formatter = pkgs.alejandra; packages.default = pkgs.stdenvNoCC.mkDerivation rec { pname = "bash-commons"; version = "0.1.9"; src = ./modules/bash-commons/src; - phases = [ "installPhase" "fixupPhase" ]; + phases = ["installPhase" "fixupPhase"]; installPhase = '' mkdir -p $out/bin cp $src/array.sh $out/bin/array.sh @@ -22,7 +30,7 @@ cp $src/log.sh $out/bin/log.sh cp $src/string.sh $out/bin/string.sh cp $src/string.sh $out/bin/os.sh - + chmod +x $out/bin/array.sh chmod +x $out/bin/assert.sh chmod +x $out/bin/file.sh @@ -34,7 +42,7 @@ doCheck = false; }; devShells.default = pkgs.mkShell { - buildInputs = [ self'.packages.default ]; + buildInputs = [self'.packages.default]; }; }; }; From 264a1e7c391bc182ddbf9b0c5f15a72a2b485f93 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Fri, 10 May 2024 22:51:54 +0100 Subject: [PATCH 3/8] can I? --- .circleci/config.yml | 29 ++++++++++++++++++----------- 1 file changed, 18 insertions(+), 11 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 429f654..8c1b1ac 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,19 +66,26 @@ jobs: steps: - checkout - run: docker-compose up --exit-code-from bats_ubuntu2004_imds_v2 bats_ubuntu2004_imds_v2 + nix: + docker: + - image: nixos/nix:2.22.1 + steps: + - checkout + - run: nix build workflows: version: 2 checks: jobs: - - shellcheck - - integration_test: - context: - - AWS__PHXDEVOPS__circle-ci-test - - GITHUB__PAT__gruntwork-ci - - bats_ubuntu1604_imds_v1 - - bats_ubuntu1604_imds_v2 - - bats_ubuntu1804_imds_v1 - - bats_ubuntu1804_imds_v2 - - bats_ubuntu2004_imds_v1 - - bats_ubuntu2004_imds_v2 + - nix + # - shellcheck + # - integration_test: + # context: + # - AWS__PHXDEVOPS__circle-ci-test + # - GITHUB__PAT__gruntwork-ci + # - bats_ubuntu1604_imds_v1 + # - bats_ubuntu1604_imds_v2 + # - bats_ubuntu1804_imds_v1 + # - bats_ubuntu1804_imds_v2 + # - bats_ubuntu2004_imds_v1 + # - bats_ubuntu2004_imds_v2 From 376247b36cc935ff28a6d5c55b9eaa8835ada7ac Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Fri, 10 May 2024 22:53:14 +0100 Subject: [PATCH 4/8] nope --- .circleci/config.yml | 29 +++++++++++------------------ 1 file changed, 11 insertions(+), 18 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 8c1b1ac..429f654 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -66,26 +66,19 @@ jobs: steps: - checkout - run: docker-compose up --exit-code-from bats_ubuntu2004_imds_v2 bats_ubuntu2004_imds_v2 - nix: - docker: - - image: nixos/nix:2.22.1 - steps: - - checkout - - run: nix build workflows: version: 2 checks: jobs: - - nix - # - shellcheck - # - integration_test: - # context: - # - AWS__PHXDEVOPS__circle-ci-test - # - GITHUB__PAT__gruntwork-ci - # - bats_ubuntu1604_imds_v1 - # - bats_ubuntu1604_imds_v2 - # - bats_ubuntu1804_imds_v1 - # - bats_ubuntu1804_imds_v2 - # - bats_ubuntu2004_imds_v1 - # - bats_ubuntu2004_imds_v2 + - shellcheck + - integration_test: + context: + - AWS__PHXDEVOPS__circle-ci-test + - GITHUB__PAT__gruntwork-ci + - bats_ubuntu1604_imds_v1 + - bats_ubuntu1604_imds_v2 + - bats_ubuntu1804_imds_v1 + - bats_ubuntu1804_imds_v2 + - bats_ubuntu2004_imds_v1 + - bats_ubuntu2004_imds_v2 From ee5db884293085d6241821c95021b58e483cc185 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 20 May 2024 12:52:31 +0100 Subject: [PATCH 5/8] versio fix --- flake.lock | 12 ++++++------ flake.nix | 10 +++++++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/flake.lock b/flake.lock index 3b501db..b534f8f 100644 --- a/flake.lock +++ b/flake.lock @@ -5,11 +5,11 @@ "nixpkgs-lib": "nixpkgs-lib" }, "locked": { - "lastModified": 1714641030, - "narHash": "sha256-yzcRNDoyVP7+SCNX0wmuDju1NUCt8Dz9+lyUXEI0dbI=", + "lastModified": 1715865404, + "narHash": "sha256-/GJvTdTpuDjNn84j82cU6bXztE0MSkdnTWClUCRub78=", "owner": "hercules-ci", "repo": "flake-parts", - "rev": "e5d10a24b66c3ea8f150e47dfdb0416ab7c3390e", + "rev": "8dc45382d5206bd292f9c2768b8058a8fd8311d9", "type": "github" }, "original": { @@ -20,11 +20,11 @@ }, "nixpkgs": { "locked": { - "lastModified": 1715218190, - "narHash": "sha256-R98WOBHkk8wIi103JUVQF3ei3oui4HvoZcz9tYOAwlk=", + "lastModified": 1716061101, + "narHash": "sha256-H0eCta7ahEgloGIwE/ihkyGstOGu+kQwAiHvwVoXaA0=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "9a9960b98418f8c385f52de3b09a63f9c561427a", + "rev": "e7cc61784ddf51c81487637b3031a6dd2d6673a2", "type": "github" }, "original": { diff --git a/flake.nix b/flake.nix index 84246ec..f569f83 100644 --- a/flake.nix +++ b/flake.nix @@ -5,7 +5,11 @@ nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; }; - outputs = inputs @ {flake-parts, ...}: + outputs = inputs @ { + flake-parts, + self, + ... + }: flake-parts.lib.mkFlake {inherit inputs;} { systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; perSystem = { @@ -19,7 +23,7 @@ formatter = pkgs.alejandra; packages.default = pkgs.stdenvNoCC.mkDerivation rec { pname = "bash-commons"; - version = "0.1.9"; + version = builtins.toString (self.shortRev or self.dirtyShortRev or self.lastModified or "unknown"); src = ./modules/bash-commons/src; phases = ["installPhase" "fixupPhase"]; installPhase = '' @@ -30,7 +34,7 @@ cp $src/log.sh $out/bin/log.sh cp $src/string.sh $out/bin/string.sh cp $src/string.sh $out/bin/os.sh - + chmod +x $out/bin/array.sh chmod +x $out/bin/assert.sh chmod +x $out/bin/file.sh From 92bd94ff4a0ee5a487a39cbcb17e88e8d2a2929b Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 20 May 2024 13:52:40 +0100 Subject: [PATCH 6/8] use official formatter and filter out mac --- flake.lock | 8 ++--- flake.nix | 93 +++++++++++++++++++++++++++++------------------------- 2 files changed, 54 insertions(+), 47 deletions(-) diff --git a/flake.lock b/flake.lock index b534f8f..a00eb85 100644 --- a/flake.lock +++ b/flake.lock @@ -20,16 +20,16 @@ }, "nixpkgs": { "locked": { - "lastModified": 1716061101, - "narHash": "sha256-H0eCta7ahEgloGIwE/ihkyGstOGu+kQwAiHvwVoXaA0=", + "lastModified": 1716128955, + "narHash": "sha256-3DNg/PV+X2V7yn8b/fUR2ppakw7D9N4sjVBGk6nDwII=", "owner": "NixOS", "repo": "nixpkgs", - "rev": "e7cc61784ddf51c81487637b3031a6dd2d6673a2", + "rev": "f9256de8281f2ccd04985ac5c30d8f69aefadbe8", "type": "github" }, "original": { "owner": "NixOS", - "ref": "nixos-23.11", + "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" } diff --git a/flake.nix b/flake.nix index f569f83..25a7659 100644 --- a/flake.nix +++ b/flake.nix @@ -2,52 +2,59 @@ description = "bash-commons via nix flakes"; inputs = { flake-parts.url = "github:hercules-ci/flake-parts"; - nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11"; + nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable"; }; - outputs = inputs @ { - flake-parts, - self, - ... - }: - flake-parts.lib.mkFlake {inherit inputs;} { - systems = ["x86_64-linux" "aarch64-linux" "aarch64-darwin" "x86_64-darwin"]; - perSystem = { - config, - self', - inputs', - pkgs, - system, - ... - }: { - formatter = pkgs.alejandra; - packages.default = pkgs.stdenvNoCC.mkDerivation rec { - pname = "bash-commons"; - version = builtins.toString (self.shortRev or self.dirtyShortRev or self.lastModified or "unknown"); - src = ./modules/bash-commons/src; - phases = ["installPhase" "fixupPhase"]; - installPhase = '' - mkdir -p $out/bin - cp $src/array.sh $out/bin/array.sh - cp $src/assert.sh $out/bin/assert.sh - cp $src/file.sh $out/bin/file.sh - cp $src/log.sh $out/bin/log.sh - cp $src/string.sh $out/bin/string.sh - cp $src/string.sh $out/bin/os.sh + outputs = + inputs@{ flake-parts, self, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = [ + "x86_64-linux" + "aarch64-linux" + "aarch64-darwin" + "x86_64-darwin" + ]; + perSystem = + { + config, + self', + inputs', + pkgs, + system, + ... + }: + { + formatter = pkgs.nixfmt-rfc-style; + packages = { + default = + # if not darwin system then regex an + let + filter = if pkgs.stdenv.isLinux then '''' else ''| grep --invert -E "os|ubuntu" ''; + in + # no need for c(pp) compiler + pkgs.stdenvNoCC.mkDerivation rec { + pname = "bash-commons"; + version = builtins.toString (self.shortRev or self.dirtyShortRev or self.lastModified or "unknown"); + src = ./modules/bash-commons/src; + phases = [ + "installPhase" + "fixupPhase" + ]; + installPhase = '' + mkdir -p $out/bin + find $src -type f ${filter} | xargs -I{} cp {} $out/bin/ + chmod +x $out/bin/*.sh + ''; + doCheck = false; + }; - chmod +x $out/bin/array.sh - chmod +x $out/bin/assert.sh - chmod +x $out/bin/file.sh - chmod +x $out/bin/log.sh - chmod +x $out/bin/string.sh - chmod +x $out/bin/os.sh - ''; - - doCheck = false; - }; - devShells.default = pkgs.mkShell { - buildInputs = [self'.packages.default]; + # run this to make universal check + check = pkgs.writeScriptBin "check" '' + nix flake check --print-build-logs --show-trace --no-build --debug --verbose --all-systems + nix build + ''; + }; + devShells.default = pkgs.mkShell { buildInputs = [ self'.packages.default ]; }; }; - }; }; } From 432be3b3acc56cdea58f1836d209139ce9fc9d70 Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Fri, 24 May 2024 10:52:03 +0100 Subject: [PATCH 7/8] Update flake.nix --- flake.nix | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/flake.nix b/flake.nix index 25a7659..e0c5c67 100644 --- a/flake.nix +++ b/flake.nix @@ -27,7 +27,7 @@ formatter = pkgs.nixfmt-rfc-style; packages = { default = - # if not darwin system then regex an + # filter out linux from mac let filter = if pkgs.stdenv.isLinux then '''' else ''| grep --invert -E "os|ubuntu" ''; in @@ -48,7 +48,7 @@ doCheck = false; }; - # run this to make universal check + # run this to make universal check of nix flake check = pkgs.writeScriptBin "check" '' nix flake check --print-build-logs --show-trace --no-build --debug --verbose --all-systems nix build From d838e81c7db00ed203207591bed764a7747c971f Mon Sep 17 00:00:00 2001 From: dzmitry-lahoda Date: Mon, 27 May 2024 16:20:22 +0100 Subject: [PATCH 8/8] nix into ci --- .circleci/config.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.circleci/config.yml b/.circleci/config.yml index 429f654..3b46bc5 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -1,4 +1,6 @@ version: 2 +orbs: + nix: eld/nix@ jobs: shellcheck: machine: true @@ -66,6 +68,12 @@ jobs: steps: - checkout - run: docker-compose up --exit-code-from bats_ubuntu2004_imds_v2 bats_ubuntu2004_imds_v2 + nixcheck: + machine: true + steps: + - checkout + - nix/install + - run: nix run .#check --option "flakes commands" --accept-flake-config workflows: version: 2 @@ -82,3 +90,4 @@ workflows: - bats_ubuntu1804_imds_v2 - bats_ubuntu2004_imds_v1 - bats_ubuntu2004_imds_v2 + - nixcheck