From a5e9a0d724b44c5e75ef3f038e2c0a31d16cf4b2 Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Fri, 24 Nov 2023 08:54:48 -0500 Subject: [PATCH 1/5] Remove flake-utils from inputs --- .envrc | 4 +- .github/workflows/build.yml | 3 +- .gitignore | 11 +++ devenv.lock | 172 +++++++++++++++++++++++++++++++++ devenv.nix | 11 +++ devenv.yaml | 5 + flake.lock | 42 +------- flake.nix | 186 ++++++++++++++++-------------------- tests/.tool-versions | 2 - tests/flake.lock | 26 ----- tests/flake.nix | 7 -- 11 files changed, 293 insertions(+), 176 deletions(-) create mode 100644 devenv.lock create mode 100644 devenv.nix create mode 100644 devenv.yaml delete mode 100644 tests/.tool-versions delete mode 100644 tests/flake.lock delete mode 100644 tests/flake.nix diff --git a/.envrc b/.envrc index 3550a30..faa8210 100644 --- a/.envrc +++ b/.envrc @@ -1 +1,3 @@ -use flake +source_url "https://raw.githubusercontent.com/cachix/devenv/d1f7b48e35e6dee421cfd0f51481d17f77586997/direnvrc" "sha256-YBzqskFZxmNb3kYVoKD9ZixoPXJh1C9ZvTLGFRkauZ0=" + +use devenv diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b7b4e49..b244538 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -15,8 +15,7 @@ jobs: - name: Install Nix uses: cachix/install-nix-action@v23 - name: Run tests - run: nix eval --impure .#tests - working-directory: tests + run: devenv shell -- tests templates: runs-on: ubuntu-latest diff --git a/.gitignore b/.gitignore index 408752e..53d3f08 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,14 @@ .direnv node_modules templates/*/flake.lock + +# Devenv +.devenv* +devenv.local.nix + +# direnv +.direnv + +# pre-commit +.pre-commit-config.yaml + diff --git a/devenv.lock b/devenv.lock new file mode 100644 index 0000000..7a65d03 --- /dev/null +++ b/devenv.lock @@ -0,0 +1,172 @@ +{ + "nodes": { + "devenv": { + "locked": { + "dir": "src/modules", + "lastModified": 1700691772, + "narHash": "sha256-LidI1PVpxL5/WchIRfMszzsiA5t40QyJiU8V/vd4ZZE=", + "owner": "cachix", + "repo": "devenv", + "rev": "38302f4b9ff45915151848b719c5c4127946c1b8", + "type": "github" + }, + "original": { + "dir": "src/modules", + "owner": "cachix", + "repo": "devenv", + "type": "github" + } + }, + "flake-compat": { + "flake": false, + "locked": { + "lastModified": 1673956053, + "narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=", + "owner": "edolstra", + "repo": "flake-compat", + "rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9", + "type": "github" + }, + "original": { + "owner": "edolstra", + "repo": "flake-compat", + "type": "github" + } + }, + "flake-utils": { + "inputs": { + "systems": "systems" + }, + "locked": { + "lastModified": 1685518550, + "narHash": "sha256-o2d0KcvaXzTrPRIo0kOLV0/QXHhDQ5DTi+OxcjO8xqY=", + "owner": "numtide", + "repo": "flake-utils", + "rev": "a1720a10a6cfe8234c0e93907ffe81be440f4cef", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "flake-utils", + "type": "github" + } + }, + "gitignore": { + "inputs": { + "nixpkgs": [ + "pre-commit-hooks", + "nixpkgs" + ] + }, + "locked": { + "lastModified": 1660459072, + "narHash": "sha256-8DFJjXG8zqoONA1vXtgeKXy68KdJL5UaXR8NtVMUbx8=", + "owner": "hercules-ci", + "repo": "gitignore.nix", + "rev": "a20de23b925fd8264fd7fad6454652e142fd7f73", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "gitignore.nix", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1700786208, + "narHash": "sha256-vP0WI7qNkg3teQJN5xjFcxgnBNiKCbkgw3X9HcAxWJY=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "8b8c9407844599546393146bfac901290e0ab96b", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-stable": { + "locked": { + "lastModified": 1685801374, + "narHash": "sha256-otaSUoFEMM+LjBI1XL/xGB5ao6IwnZOXc47qhIgJe8U=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "c37ca420157f4abc31e26f436c1145f8951ff373", + "type": "github" + }, + "original": { + "owner": "NixOS", + "ref": "nixos-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixtest": { + "locked": { + "lastModified": 1689623844, + "narHash": "sha256-VvOQ7iuwsdZzUh213N5cHzaMKmqbX6qWwXoMGXRcE1o=", + "owner": "jetpack-io", + "repo": "nixtest", + "rev": "82e49b045e50a6c0597ab7d613d44c5a323241ab", + "type": "github" + }, + "original": { + "owner": "jetpack-io", + "repo": "nixtest", + "type": "github" + } + }, + "pre-commit-hooks": { + "inputs": { + "flake-compat": "flake-compat", + "flake-utils": "flake-utils", + "gitignore": "gitignore", + "nixpkgs": [ + "nixpkgs" + ], + "nixpkgs-stable": "nixpkgs-stable" + }, + "locked": { + "lastModified": 1700064067, + "narHash": "sha256-1ZWNDzhu8UlVCK7+DUN9dVQfiHX1bv6OQP9VxstY/gs=", + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "rev": "e558068cba67b23b4fbc5537173dbb43748a17e8", + "type": "github" + }, + "original": { + "owner": "cachix", + "repo": "pre-commit-hooks.nix", + "type": "github" + } + }, + "root": { + "inputs": { + "devenv": "devenv", + "nixpkgs": "nixpkgs", + "nixtest": "nixtest", + "pre-commit-hooks": "pre-commit-hooks" + } + }, + "systems": { + "locked": { + "lastModified": 1681028828, + "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", + "owner": "nix-systems", + "repo": "default", + "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", + "type": "github" + }, + "original": { + "owner": "nix-systems", + "repo": "default", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/devenv.nix b/devenv.nix new file mode 100644 index 0000000..caddd65 --- /dev/null +++ b/devenv.nix @@ -0,0 +1,11 @@ +{ pkgs, nixtest, ... }: + +{ + scripts.tests.exec = '' + nix eval --impure --apply 'run: run ./tests' ${nixtest}#run + ''; + + languages.javascript.enable = true; + + pre-commit.hooks.nixpkgs-fmt.enable = true; +} diff --git a/devenv.yaml b/devenv.yaml new file mode 100644 index 0000000..b793802 --- /dev/null +++ b/devenv.yaml @@ -0,0 +1,5 @@ +inputs: + nixpkgs: + url: github:NixOS/nixpkgs/nixpkgs-unstable + nixtest: + url: github:jetpack-io/nixtest diff --git a/flake.lock b/flake.lock index 754adbd..8bc3738 100644 --- a/flake.lock +++ b/flake.lock @@ -1,33 +1,17 @@ { "nodes": { - "flake-utils": { - "inputs": { - "systems": "systems" - }, - "locked": { - "lastModified": 1694529238, - "narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=", - "owner": "numtide", - "repo": "flake-utils", - "rev": "ff7b65b44d01cf9ba6a71320833626af21126384", - "type": "github" - }, - "original": { - "owner": "numtide", - "repo": "flake-utils", - "type": "github" - } - }, "nixpkgs": { "locked": { - "lastModified": 1700403855, - "narHash": "sha256-Q0Uzjik9kUTN9pd/kp52XJi5kletBhy29ctBlAG+III=", + "dir": "lib", + "lastModified": 1700678569, + "narHash": "sha256-2Ki+2UvOidxEb3xB4ADqlbPQ2BZOF4uZMR094O8or2I=", "owner": "nixos", "repo": "nixpkgs", - "rev": "0c5678df521e1407884205fe3ce3cf1d7df297db", + "rev": "8f1180704ac35baded1a74164365ac7cdfba6f38", "type": "github" }, "original": { + "dir": "lib", "owner": "nixos", "ref": "nixos-23.05", "repo": "nixpkgs", @@ -36,24 +20,8 @@ }, "root": { "inputs": { - "flake-utils": "flake-utils", "nixpkgs": "nixpkgs" } - }, - "systems": { - "locked": { - "lastModified": 1681028828, - "narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=", - "owner": "nix-systems", - "repo": "default", - "rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e", - "type": "github" - }, - "original": { - "owner": "nix-systems", - "repo": "default", - "type": "github" - } } }, "root": "root", diff --git a/flake.nix b/flake.nix index c1cabaa..3480daa 100644 --- a/flake.nix +++ b/flake.nix @@ -1,113 +1,97 @@ { - inputs = { - flake-utils.url = "github:numtide/flake-utils"; - nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05"; - }; + inputs.nixpkgs.url = "github:nixos/nixpkgs/nixos-23.05?dir=lib"; - outputs = { self, flake-utils, nixpkgs }: - flake-utils.lib.eachDefaultSystem - (system: + outputs = { self, nixpkgs }: + let + lib = nixpkgs.lib; + in + { + lib.packagesFromVersionsFile = + { versionsFile + , system ? builtins.currentSystem + , plugins ? { } + , skipMissingPlugins ? false + }: let - pkgs = nixpkgs.legacyPackages.${system}; - in - { - devShells.default = pkgs.mkShell { - buildInputs = [ pkgs.nodejs ]; - }; - }) - // - ( - let - lib = nixpkgs.lib; - in - { - lib.packagesFromVersionsFile = - { versionsFile - , system ? builtins.currentSystem - , plugins ? { } - , skipMissingPlugins ? false - }: - let - fileLines = file: lib.splitString "\n" (lib.fileContents file); - removeComments = builtins.filter (line: !lib.hasPrefix "#" line); - parseVersions = builtins.map - (line: - let - pluginAndVersion = lib.splitString " " line; - in - { - name = builtins.elemAt pluginAndVersion 0; - version = builtins.elemAt pluginAndVersion 1; - }); - filterPlugins = builtins.filter - ({ name, ... }: - let - hasPlugin = builtins.hasAttr name plugins; - in - lib.throwIf (!skipMissingPlugins && !hasPlugin) - '' - No plugin found for "${name}", try adding the missing plugin: + fileLines = file: lib.splitString "\n" (lib.fileContents file); + removeComments = builtins.filter (line: !lib.hasPrefix "#" line); + parseVersions = builtins.map + (line: + let + pluginAndVersion = lib.splitString " " line; + in + { + name = builtins.elemAt pluginAndVersion 0; + version = builtins.elemAt pluginAndVersion 1; + }); + filterPlugins = builtins.filter + ({ name, ... }: + let + hasPlugin = builtins.hasAttr name plugins; + in + lib.throwIf (!skipMissingPlugins && !hasPlugin) + '' + No plugin found for "${name}", try adding the missing plugin: - ``` - .lib.packagesFromVersionsFile { - plugins = { - ${name} = .lib.packageFromVersion; - ... - }; + ``` + .lib.packagesFromVersionsFile { + plugins = { + ${name} = .lib.packageFromVersion; ... }; - ``` + ... + }; + ``` - Or enable `skipMissingPlugins` to skip this error: + Or enable `skipMissingPlugins` to skip this error: - ``` - .lib.packagesFromVersionsFile { - plugins = { ... }; - skipMissingPlugins = true; - ... - }; - ``` - '' - lib.warnIf - (!hasPlugin) "Skipping \"${name}\" plugin" - hasPlugin); - findPackages = builtins.map - ({ name, version }: - let - plugin = plugins.${name}; - in - lib.throwIf (!plugin.hasVersion { inherit system version; }) - '' - Plugin "${name}" does not provide version "${version}", try - updating the plugin's input: + ``` + .lib.packagesFromVersionsFile { + plugins = { ... }; + skipMissingPlugins = true; + ... + }; + ``` + '' + lib.warnIf + (!hasPlugin) "Skipping \"${name}\" plugin" + hasPlugin); + findPackages = builtins.map + ({ name, version }: + let + plugin = plugins.${name}; + in + lib.throwIf (!plugin.hasVersion { inherit system version; }) + '' + Plugin "${name}" does not provide version "${version}", try + updating the plugin's input: - ``` - > nix flake lock --update-input - ``` - '' - { - inherit name; - value = plugin.packageFromVersion { inherit system version; }; - } - ); - in - builtins.listToAttrs - (findPackages - (filterPlugins - (parseVersions - (removeComments - (fileLines versionsFile))))); + ``` + > nix flake lock --update-input + ``` + '' + { + inherit name; + value = plugin.packageFromVersion { inherit system version; }; + } + ); + in + builtins.listToAttrs + (findPackages + (filterPlugins + (parseVersions + (removeComments + (fileLines versionsFile))))); - templates = { - default = { - description = "Install Nix packages from asdf versions file"; - path = ./templates/default; - }; - devenv = { - description = "Integration with devenv"; - path = ./templates/devenv; - }; + templates = { + default = { + description = "Install Nix packages from asdf versions file"; + path = ./templates/default; + }; + devenv = { + description = "Integration with devenv"; + path = ./templates/devenv; }; - } - ); + }; + }; } diff --git a/tests/.tool-versions b/tests/.tool-versions deleted file mode 100644 index 73fdbf7..0000000 --- a/tests/.tool-versions +++ /dev/null @@ -1,2 +0,0 @@ -python 3.12.0 -terraform 1.6.3 diff --git a/tests/flake.lock b/tests/flake.lock deleted file mode 100644 index 9971773..0000000 --- a/tests/flake.lock +++ /dev/null @@ -1,26 +0,0 @@ -{ - "nodes": { - "nixtest": { - "locked": { - "lastModified": 1689623844, - "narHash": "sha256-VvOQ7iuwsdZzUh213N5cHzaMKmqbX6qWwXoMGXRcE1o=", - "owner": "jetpack-io", - "repo": "nixtest", - "rev": "82e49b045e50a6c0597ab7d613d44c5a323241ab", - "type": "github" - }, - "original": { - "owner": "jetpack-io", - "repo": "nixtest", - "type": "github" - } - }, - "root": { - "inputs": { - "nixtest": "nixtest" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/tests/flake.nix b/tests/flake.nix deleted file mode 100644 index 59df9d0..0000000 --- a/tests/flake.nix +++ /dev/null @@ -1,7 +0,0 @@ -{ - inputs.nixtest.url = "github:jetpack-io/nixtest"; - - outputs = { self, nixtest }: { - tests = nixtest.run ./.; - }; -} From 6451f9b71d328933278bc45493987ae8c5a1fa81 Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:01:38 -0500 Subject: [PATCH 2/5] Install devenv from cachix --- .github/workflows/build.yml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index b244538..763931c 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,6 +14,8 @@ jobs: uses: actions/checkout@v4 - name: Install Nix uses: cachix/install-nix-action@v23 + - run: nix-env -iA cachix -f https://cachix.org/api/v1/install + - run: cachix use devenv - name: Run tests run: devenv shell -- tests From e03914bcb20c7661c3a06e700edab8879d4c7dd6 Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:03:18 -0500 Subject: [PATCH 3/5] Install devenv --- .github/workflows/build.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 763931c..6ce3d1d 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -16,6 +16,7 @@ jobs: uses: cachix/install-nix-action@v23 - run: nix-env -iA cachix -f https://cachix.org/api/v1/install - run: cachix use devenv + - run: nix-env -if https://install.devenv.sh/latest - name: Run tests run: devenv shell -- tests From 208da03413d853db8c67c7349480cebcec0409d3 Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:06:30 -0500 Subject: [PATCH 4/5] Add name to steps --- .github/workflows/build.yml | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 6ce3d1d..99f07ed 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -14,9 +14,12 @@ jobs: uses: actions/checkout@v4 - name: Install Nix uses: cachix/install-nix-action@v23 - - run: nix-env -iA cachix -f https://cachix.org/api/v1/install - - run: cachix use devenv - - run: nix-env -if https://install.devenv.sh/latest + - name: Install Cachix + run: nix-env -iA cachix -f https://cachix.org/api/v1/install + - name: Setup Cachix + run: cachix use devenv + - name: Install devenv + run: nix-env -if https://install.devenv.sh/latest - name: Run tests run: devenv shell -- tests From e89e9bc3abb035b69f2e5cbf3d25dc7ccc8b28e8 Mon Sep 17 00:00:00 2001 From: Sebastian Estrella <2049686+sestrella@users.noreply.github.com> Date: Fri, 24 Nov 2023 09:09:55 -0500 Subject: [PATCH 5/5] Change input URL --- devenv.lock | 4 ++-- devenv.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/devenv.lock b/devenv.lock index 7a65d03..1c445ee 100644 --- a/devenv.lock +++ b/devenv.lock @@ -76,13 +76,13 @@ "locked": { "lastModified": 1700786208, "narHash": "sha256-vP0WI7qNkg3teQJN5xjFcxgnBNiKCbkgw3X9HcAxWJY=", - "owner": "NixOS", + "owner": "nixos", "repo": "nixpkgs", "rev": "8b8c9407844599546393146bfac901290e0ab96b", "type": "github" }, "original": { - "owner": "NixOS", + "owner": "nixos", "ref": "nixpkgs-unstable", "repo": "nixpkgs", "type": "github" diff --git a/devenv.yaml b/devenv.yaml index b793802..a386d69 100644 --- a/devenv.yaml +++ b/devenv.yaml @@ -1,5 +1,5 @@ inputs: nixpkgs: - url: github:NixOS/nixpkgs/nixpkgs-unstable + url: github:nixos/nixpkgs/nixpkgs-unstable nixtest: url: github:jetpack-io/nixtest