From 897a093a033ab5db192f351b091e417b92af4c57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Wed, 5 Jul 2023 11:52:13 +0200 Subject: [PATCH 01/10] Radically cleanup the templates MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Remove all the templates, except for one. This makes the repository quite simpler, and emphasises the fact that we want something that just works™ We'll certainly want to add some funkier tests, but in a more principled way, and that doesn't leak into the end-user interface. Also removes the example for the same reason --- .github/workflows/examples.yml | 58 ------------ .github/workflows/templates.yml | 36 +------- examples/c-hello-world/flake.nix | 14 --- examples/c-hello-world/hello.c | 6 -- examples/c-hello-world/nickel.lock.ncl | 8 -- examples/c-hello-world/package.ncl | 29 ------ flake.nix | 90 ++----------------- templates/default/dev-shell.ncl | 8 ++ .../{devshells/clojure => default}/flake.nix | 2 - .../{devshells/c => default}/nickel.lock.ncl | 0 templates/devshells/c/dev-shell.ncl | 8 -- templates/devshells/c/flake.nix | 14 --- templates/devshells/clojure/dev-shell.ncl | 8 -- templates/devshells/clojure/nickel.lock.ncl | 8 -- templates/devshells/erlang/dev-shell.ncl | 8 -- templates/devshells/erlang/flake.nix | 14 --- templates/devshells/erlang/nickel.lock.ncl | 8 -- templates/devshells/go/dev-shell.ncl | 8 -- templates/devshells/go/flake.nix | 14 --- templates/devshells/go/nickel.lock.ncl | 8 -- templates/devshells/haskell/dev-shell.ncl | 9 -- templates/devshells/haskell/flake.nix | 14 --- templates/devshells/haskell/nickel.lock.ncl | 8 -- templates/devshells/javascript/dev-shell.ncl | 8 -- templates/devshells/javascript/flake.nix | 14 --- .../devshells/javascript/nickel.lock.ncl | 8 -- templates/devshells/php/dev-shell.ncl | 8 -- templates/devshells/php/flake.nix | 14 --- templates/devshells/php/nickel.lock.ncl | 8 -- templates/devshells/python310/dev-shell.ncl | 8 -- templates/devshells/python310/flake.nix | 14 --- templates/devshells/python310/nickel.lock.ncl | 8 -- templates/devshells/racket/dev-shell.ncl | 8 -- templates/devshells/racket/flake.nix | 14 --- templates/devshells/racket/nickel.lock.ncl | 8 -- templates/devshells/rust/create-env.sh | 25 ------ templates/devshells/rust/dev-shell.ncl | 8 -- templates/devshells/rust/flake.nix | 14 --- templates/devshells/rust/nickel.lock.ncl | 8 -- templates/devshells/scala/dev-shell.ncl | 8 -- templates/devshells/scala/flake.nix | 14 --- templates/devshells/scala/nickel.lock.ncl | 8 -- templates/devshells/zig/dev-shell.ncl | 8 -- templates/devshells/zig/flake.nix | 14 --- templates/devshells/zig/nickel.lock.ncl | 8 -- test-template.sh | 38 ++++++++ 46 files changed, 58 insertions(+), 595 deletions(-) delete mode 100644 .github/workflows/examples.yml delete mode 100644 examples/c-hello-world/flake.nix delete mode 100644 examples/c-hello-world/hello.c delete mode 100644 examples/c-hello-world/nickel.lock.ncl delete mode 100644 examples/c-hello-world/package.ncl create mode 100644 templates/default/dev-shell.ncl rename templates/{devshells/clojure => default}/flake.nix (89%) rename templates/{devshells/c => default}/nickel.lock.ncl (100%) delete mode 100644 templates/devshells/c/dev-shell.ncl delete mode 100644 templates/devshells/c/flake.nix delete mode 100644 templates/devshells/clojure/dev-shell.ncl delete mode 100644 templates/devshells/clojure/nickel.lock.ncl delete mode 100644 templates/devshells/erlang/dev-shell.ncl delete mode 100644 templates/devshells/erlang/flake.nix delete mode 100644 templates/devshells/erlang/nickel.lock.ncl delete mode 100644 templates/devshells/go/dev-shell.ncl delete mode 100644 templates/devshells/go/flake.nix delete mode 100644 templates/devshells/go/nickel.lock.ncl delete mode 100644 templates/devshells/haskell/dev-shell.ncl delete mode 100644 templates/devshells/haskell/flake.nix delete mode 100644 templates/devshells/haskell/nickel.lock.ncl delete mode 100644 templates/devshells/javascript/dev-shell.ncl delete mode 100644 templates/devshells/javascript/flake.nix delete mode 100644 templates/devshells/javascript/nickel.lock.ncl delete mode 100644 templates/devshells/php/dev-shell.ncl delete mode 100644 templates/devshells/php/flake.nix delete mode 100644 templates/devshells/php/nickel.lock.ncl delete mode 100644 templates/devshells/python310/dev-shell.ncl delete mode 100644 templates/devshells/python310/flake.nix delete mode 100644 templates/devshells/python310/nickel.lock.ncl delete mode 100644 templates/devshells/racket/dev-shell.ncl delete mode 100644 templates/devshells/racket/flake.nix delete mode 100644 templates/devshells/racket/nickel.lock.ncl delete mode 100755 templates/devshells/rust/create-env.sh delete mode 100644 templates/devshells/rust/dev-shell.ncl delete mode 100644 templates/devshells/rust/flake.nix delete mode 100644 templates/devshells/rust/nickel.lock.ncl delete mode 100644 templates/devshells/scala/dev-shell.ncl delete mode 100644 templates/devshells/scala/flake.nix delete mode 100644 templates/devshells/scala/nickel.lock.ncl delete mode 100644 templates/devshells/zig/dev-shell.ncl delete mode 100644 templates/devshells/zig/flake.nix delete mode 100644 templates/devshells/zig/nickel.lock.ncl create mode 100755 test-template.sh diff --git a/.github/workflows/examples.yml b/.github/workflows/examples.yml deleted file mode 100644 index 0ec14174..00000000 --- a/.github/workflows/examples.yml +++ /dev/null @@ -1,58 +0,0 @@ -name: Examples - -on: - push: - branches: - - main - pull_request: - -jobs: - - get-example-names: - name: Setup nix and nickel-nix - runs-on: ubuntu-latest - - outputs: - examples: ${{ steps.examples.outputs.examples }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup - uses: ./.github/actions/common-setup - with: - SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CACHIX_TOKEN: ${{ secrets.CACHIX_TOKEN }} - - - name: List all examples - id: examples - run: | - examples=$(python3 -c "import json, os, sys; json.dump(os.listdir('examples'), sys.stdout)") - echo "examples=$examples" >> $GITHUB_OUTPUT - - test-examples: - name: Test example ${{ matrix.example }} - needs: get-example-names - runs-on: ubuntu-latest - - strategy: - fail-fast: false - matrix: - example: ${{ fromJSON(needs.get-example-names.outputs.examples) }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup - uses: ./.github/actions/common-setup - with: - SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CACHIX_TOKEN: ${{ secrets.CACHIX_TOKEN }} - - - name: Build - run: | - nix run .#tests.examples.${{ matrix.example }} diff --git a/.github/workflows/templates.yml b/.github/workflows/templates.yml index 90e6bc13..50f8ab6c 100644 --- a/.github/workflows/templates.yml +++ b/.github/workflows/templates.yml @@ -8,40 +8,10 @@ on: jobs: - get-template-names: - name: Setup nix and nickel-nix - runs-on: ubuntu-latest - - outputs: - templates: ${{ steps.templates.outputs.templates }} - - steps: - - uses: actions/checkout@v3 - with: - fetch-depth: 0 - - - name: Setup - uses: ./.github/actions/common-setup - with: - SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} - CACHIX_TOKEN: ${{ secrets.CACHIX_TOKEN }} - - - name: List all templates - id: templates - run: | - templates=$(nix eval .#templates --apply builtins.attrNames --json) - echo "templates=$templates" >> $GITHUB_OUTPUT - enter-devshells: - name: Test devshell ${{ matrix.template }} - needs: get-template-names + name: Test devshells runs-on: ubuntu-latest - strategy: - fail-fast: false - matrix: - template: ${{ fromJSON(needs.get-template-names.outputs.templates) }} - steps: - uses: actions/checkout@v3 with: @@ -53,6 +23,6 @@ jobs: SECRET_GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} CACHIX_TOKEN: ${{ secrets.CACHIX_TOKEN }} - - name: Test devshell ${{ matrix.template }} + - name: Test devshells run: | - nix run .#tests.templates.${{ matrix.template }} + nix develop --accept-flake-config --command bash test-template.sh diff --git a/examples/c-hello-world/flake.nix b/examples/c-hello-world/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/examples/c-hello-world/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/examples/c-hello-world/hello.c b/examples/c-hello-world/hello.c deleted file mode 100644 index 73e1b0a9..00000000 --- a/examples/c-hello-world/hello.c +++ /dev/null @@ -1,6 +0,0 @@ -#include - -int main() { - printf("Hello, world!"); - return 0; -} diff --git a/examples/c-hello-world/nickel.lock.ncl b/examples/c-hello-world/nickel.lock.ncl deleted file mode 100644 index 3a95f954..00000000 --- a/examples/c-hello-world/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "/nix/store/qb3qvz3xxvnwy5ma1b60ba2gw8pw9vas-5626jyxg49xsax707lciippzazpldgjn-source/builders.ncl", - contracts = import "/nix/store/qb3qvz3xxvnwy5ma1b60ba2gw8pw9vas-5626jyxg49xsax707lciippzazpldgjn-source/contracts.ncl", - - nix = import "/nix/store/qb3qvz3xxvnwy5ma1b60ba2gw8pw9vas-5626jyxg49xsax707lciippzazpldgjn-source/nix.ncl", - }, -} diff --git a/examples/c-hello-world/package.ncl b/examples/c-hello-world/package.ncl deleted file mode 100644 index 21783ad7..00000000 --- a/examples/c-hello-world/package.ncl +++ /dev/null @@ -1,29 +0,0 @@ -let nickel-nix = (import "./nickel.lock.ncl").nickel-nix in - -nickel-nix.builders.NixpkgsPkg & { - inputs_spec = { - bash.input = "nixpkgs", - coreutils.input = "nixpkgs", - gcc.input = "nixpkgs", - }, - - inputs, - - output = - { - name = "hello", - version = "0.1", - structured_env = { - buildInputs.gcc = inputs.gcc, - buildInputs.coreutils = inputs.coreutils, - buildInputs.bash = inputs.bash, - }, - env = { - buildCommand = nix-s%" - gcc %{nickel-nix.lib.import_file "hello.c"} -o hello - mkdir -p $out/bin - cp hello $out/bin/hello - "%, - }, - } -} diff --git a/flake.nix b/flake.nix index 246cf728..83309625 100644 --- a/flake.nix +++ b/flake.nix @@ -26,33 +26,17 @@ topiary, } @ inputs: { - templates = let - inherit (nixpkgs) lib; - brokenShells = ["javascript" "php" "python310"]; - filteredShells = ( - lib.filterAttrs - (name: value: !(builtins.elem name brokenShells)) - (builtins.readDir ./templates/devshells) - ); - in - lib.mapAttrs' - ( - name: value: - lib.nameValuePair - (name + "-devshell") - { - path = ./templates/devshells/${name}; - description = "A ${name} devshell using nickel."; - welcomeText = '' - You have created a ${name} devshell that is built using nickel! + templates.default = { + path = ./templates/default; + description = "A devshell using nickel."; + welcomeText = '' + You have created a devshell that is built using nickel! - First run `nix run .#regenerate-lockfile` to fill `nickel.lock.ncl` with proper references. + First run `nix run .#regenerate-lockfile` to fill `nickel.lock.ncl` with proper references. - Then run `nix develop` to enter the dev shell. - ''; - } - ) - filteredShells; + Then run `nix develop` to enter the dev shell. + ''; + }; # Generate typical flake outputs from .ncl files in path for provided systems (default from flake-utils): # @@ -158,62 +142,6 @@ program = pkgs.lib.getExe (self.lib.${system}.buildLockFile contents); }; - apps.tests = let - mkTest = { - name, - script, - }: let - test = pkgs.writeShellApplication { - inherit name; - text = '' - set -xeuo pipefail - WORKDIR=$(mktemp -d) - function clean() { - rm -rf "''${WORKDIR}" - } - trap clean EXIT - cd "''${WORKDIR}" - - ${script} - ''; - }; - in { - type = "app"; - program = "${pkgs.lib.getExe test}"; - }; - in { - templates = pkgs.lib.flip pkgs.lib.mapAttrs self.templates ( - name: _: - mkTest { - name = "test devshell ${name}"; - script = '' - nix flake new --template path:${self.outPath}#${name} example --accept-flake-config - - pushd ./example - # We test against the local version of `nickel-nix`, not the one in main (hence the --override-input). - nix flake lock --override-input nickel-nix path:${self.outPath} --accept-flake-config - nix run .#regenerate-lockfile --accept-flake-config - nix develop --accept-flake-config --print-build-logs < /dev/null - popd - ''; - } - ); - examples = pkgs.lib.flip pkgs.lib.mapAttrs (builtins.readDir ./examples) ( - name: _: - mkTest { - name = "test ${name}"; - script = '' - cp -r ${self.outPath}/examples/${name} ./${name} - chmod -R u+w ./${name} - cd ./${name} - nix flake lock --override-input nickel-nix path:${self.outPath} - nix run .#regenerate-lockfile --accept-flake-config - nix build --accept-flake-config - ''; - } - ); - }; - devShells.default = pkgs.mkShell { packages = [ inputs.nickel.packages."${system}".default diff --git a/templates/default/dev-shell.ncl b/templates/default/dev-shell.ncl new file mode 100644 index 00000000..f3453eaf --- /dev/null +++ b/templates/default/dev-shell.ncl @@ -0,0 +1,8 @@ +let nixel = (import "./nickel.lock.ncl").nickel-nix in + +{ + output = { + name = "nickel-shell", + } +} +& nixel.builders.BashShell diff --git a/templates/devshells/clojure/flake.nix b/templates/default/flake.nix similarity index 89% rename from templates/devshells/clojure/flake.nix rename to templates/default/flake.nix index e0de00a6..dd4dd1aa 100644 --- a/templates/devshells/clojure/flake.nix +++ b/templates/default/flake.nix @@ -1,6 +1,4 @@ { - description = "A basic flake with a shell"; - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; diff --git a/templates/devshells/c/nickel.lock.ncl b/templates/default/nickel.lock.ncl similarity index 100% rename from templates/devshells/c/nickel.lock.ncl rename to templates/default/nickel.lock.ncl diff --git a/templates/devshells/c/dev-shell.ncl b/templates/devshells/c/dev-shell.ncl deleted file mode 100644 index 2a2b2635..00000000 --- a/templates/devshells/c/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.CShell diff --git a/templates/devshells/c/flake.nix b/templates/devshells/c/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/c/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/clojure/dev-shell.ncl b/templates/devshells/clojure/dev-shell.ncl deleted file mode 100644 index a7cb7393..00000000 --- a/templates/devshells/clojure/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.ClojureShell diff --git a/templates/devshells/clojure/nickel.lock.ncl b/templates/devshells/clojure/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/clojure/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/erlang/dev-shell.ncl b/templates/devshells/erlang/dev-shell.ncl deleted file mode 100644 index 44922137..00000000 --- a/templates/devshells/erlang/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.ErlangShell diff --git a/templates/devshells/erlang/flake.nix b/templates/devshells/erlang/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/erlang/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/erlang/nickel.lock.ncl b/templates/devshells/erlang/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/erlang/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/go/dev-shell.ncl b/templates/devshells/go/dev-shell.ncl deleted file mode 100644 index 10e8e449..00000000 --- a/templates/devshells/go/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.GoShell diff --git a/templates/devshells/go/flake.nix b/templates/devshells/go/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/go/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/go/nickel.lock.ncl b/templates/devshells/go/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/go/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/haskell/dev-shell.ncl b/templates/devshells/haskell/dev-shell.ncl deleted file mode 100644 index 9e3837c2..00000000 --- a/templates/devshells/haskell/dev-shell.ncl +++ /dev/null @@ -1,9 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - ghcVersion = "927", - output = { - name = "nickel-shell", - } -} -& builders.HaskellStackShell diff --git a/templates/devshells/haskell/flake.nix b/templates/devshells/haskell/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/haskell/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/haskell/nickel.lock.ncl b/templates/devshells/haskell/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/haskell/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/javascript/dev-shell.ncl b/templates/devshells/javascript/dev-shell.ncl deleted file mode 100644 index 00fccfcf..00000000 --- a/templates/devshells/javascript/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.JavascriptShell diff --git a/templates/devshells/javascript/flake.nix b/templates/devshells/javascript/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/javascript/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/javascript/nickel.lock.ncl b/templates/devshells/javascript/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/javascript/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/php/dev-shell.ncl b/templates/devshells/php/dev-shell.ncl deleted file mode 100644 index 86bcf759..00000000 --- a/templates/devshells/php/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.PhpShell diff --git a/templates/devshells/php/flake.nix b/templates/devshells/php/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/php/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/php/nickel.lock.ncl b/templates/devshells/php/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/php/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/python310/dev-shell.ncl b/templates/devshells/python310/dev-shell.ncl deleted file mode 100644 index d345d8b1..00000000 --- a/templates/devshells/python310/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.Python310Shell diff --git a/templates/devshells/python310/flake.nix b/templates/devshells/python310/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/python310/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/python310/nickel.lock.ncl b/templates/devshells/python310/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/python310/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/racket/dev-shell.ncl b/templates/devshells/racket/dev-shell.ncl deleted file mode 100644 index 78f70c1b..00000000 --- a/templates/devshells/racket/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.RacketShell diff --git a/templates/devshells/racket/flake.nix b/templates/devshells/racket/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/racket/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/racket/nickel.lock.ncl b/templates/devshells/racket/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/racket/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/rust/create-env.sh b/templates/devshells/rust/create-env.sh deleted file mode 100755 index 6a366827..00000000 --- a/templates/devshells/rust/create-env.sh +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env bash - -for devenv in $(awk '/= BashShell/ { print $1 }' ./nixel/builders.ncl) -do - ENV_NAME="$(echo $devenv | tr [A-Z] [a-z] | sed 's/shell$//')" - DEST="../$ENV_NAME" - if ! [[ ./ -ef "$DEST" ]]; - then - echo $ENV_NAME - - rm -fr "$DEST" - mkdir -p "$DEST" - cp -r nixel flake.* "$DEST" - - cat < "${DEST}/dev-shell.ncl" -let builders = import "nixel/builders.ncl" in - -{ - output = { - name = "nickel-shell", - } -} & builders.$devenv -EOF - fi -done diff --git a/templates/devshells/rust/dev-shell.ncl b/templates/devshells/rust/dev-shell.ncl deleted file mode 100644 index f140a714..00000000 --- a/templates/devshells/rust/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.RustShell diff --git a/templates/devshells/rust/flake.nix b/templates/devshells/rust/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/rust/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/rust/nickel.lock.ncl b/templates/devshells/rust/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/rust/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/scala/dev-shell.ncl b/templates/devshells/scala/dev-shell.ncl deleted file mode 100644 index 68f9cf74..00000000 --- a/templates/devshells/scala/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.ScalaShell diff --git a/templates/devshells/scala/flake.nix b/templates/devshells/scala/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/scala/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/scala/nickel.lock.ncl b/templates/devshells/scala/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/scala/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/templates/devshells/zig/dev-shell.ncl b/templates/devshells/zig/dev-shell.ncl deleted file mode 100644 index 1cf7efab..00000000 --- a/templates/devshells/zig/dev-shell.ncl +++ /dev/null @@ -1,8 +0,0 @@ -let builders = (import "./nickel.lock.ncl").nickel-nix.builders in - -{ - output = { - name = "nickel-shell", - } -} -& builders.ZigShell diff --git a/templates/devshells/zig/flake.nix b/templates/devshells/zig/flake.nix deleted file mode 100644 index e0de00a6..00000000 --- a/templates/devshells/zig/flake.nix +++ /dev/null @@ -1,14 +0,0 @@ -{ - description = "A basic flake with a shell"; - - inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; - inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; - - nixConfig = { - extra-substituters = ["https://nickel-nix.cachix.org"]; - extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; - }; - - outputs = {nickel-nix, ...} @ inputs: - nickel-nix.flake.outputsFromNickel ./. inputs {}; -} diff --git a/templates/devshells/zig/nickel.lock.ncl b/templates/devshells/zig/nickel.lock.ncl deleted file mode 100644 index a8798724..00000000 --- a/templates/devshells/zig/nickel.lock.ncl +++ /dev/null @@ -1,8 +0,0 @@ -{ - nickel-nix = { - builders = import "../../../builders.ncl", - contracts = import "../../../contracts.ncl", - - nix = import "../../../nix.ncl", - }, -} diff --git a/test-template.sh b/test-template.sh new file mode 100755 index 00000000..3a100862 --- /dev/null +++ b/test-template.sh @@ -0,0 +1,38 @@ +#!/usr/bin/env bash + +set -xeuo pipefail + +test_one () { + target="$1" + PROJECT_ROOT=$PWD + WORKDIR=$(mktemp -d) + function clean() { + rm -rf "${WORKDIR}" + } + trap clean EXIT + pushd "${WORKDIR}" + + nix flake new --template "path:$PROJECT_ROOT" example --accept-flake-config + + pushd ./example + sed -i "s/Nickel/$target/" dev-shell.ncl + # We test against the local version of `nickel-nix`, not the one in main (hence the --override-input). + nix flake lock --override-input nickel-nix path:$PROJECT_ROOT --accept-flake-config + nix run .#regenerate-lockfile --accept-flake-config + nix develop --accept-flake-config --print-build-logs < /dev/null + popd + popd + clean +} + +if [[ -n ${1+x} ]]; then + test_one "$1" +else + all_targets=$(nickel export <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') + for target in $all_targets; do + test_one $target + done +fi + + +target=${1:-Nickel} From 056b02b668b628be77c3ad128eff5fd680633d74 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= <7226587+thufschmitt@users.noreply.github.com> Date: Wed, 5 Jul 2023 16:18:45 +0200 Subject: [PATCH 02/10] Use a working shell for the template Co-authored-by: Yuriy Taraday --- test-template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-template.sh b/test-template.sh index 3a100862..d71e2d0c 100755 --- a/test-template.sh +++ b/test-template.sh @@ -15,7 +15,7 @@ test_one () { nix flake new --template "path:$PROJECT_ROOT" example --accept-flake-config pushd ./example - sed -i "s/Nickel/$target/" dev-shell.ncl + sed -i "s/BashShell/$target/" dev-shell.ncl # We test against the local version of `nickel-nix`, not the one in main (hence the --override-input). nix flake lock --override-input nickel-nix path:$PROJECT_ROOT --accept-flake-config nix run .#regenerate-lockfile --accept-flake-config From bb01493032a6d91863e6b5b25ccdeeb7bd54b1b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Wed, 5 Jul 2023 16:42:40 +0200 Subject: [PATCH 03/10] Fix the test-template script --- test-template.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test-template.sh b/test-template.sh index d71e2d0c..528da901 100755 --- a/test-template.sh +++ b/test-template.sh @@ -28,7 +28,7 @@ test_one () { if [[ -n ${1+x} ]]; then test_one "$1" else - all_targets=$(nickel export <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') + all_targets=$(nickel export --format raw <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') for target in $all_targets; do test_one $target done From 413e5833bf8de345f7c87b1d05772205cbae3267 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Wed, 5 Jul 2023 16:58:51 +0200 Subject: [PATCH 04/10] Make sure that all the shells work by default Fix the broken ones and give default arguments to the ones that require it. Also blacklists `NickelPkg` as it's not a shell (arguably shouldn't be in the same record as the shells, but that's a refactoring for later) --- lib/builders.ncl | 9 +-------- test-template.sh | 3 +++ 2 files changed, 4 insertions(+), 8 deletions(-) diff --git a/lib/builders.ncl b/lib/builders.ncl index b485f1d5..ec89f866 100644 --- a/lib/builders.ncl +++ b/lib/builders.ncl @@ -166,15 +166,11 @@ in & { inputs_spec = { php = {}, - intelephense = { - path = "nodePackages"."intelephense", - }, }, inputs, output.packages = { php = inputs.php, - intelephense = inputs.intelephense, }, }, @@ -193,7 +189,6 @@ in }, }, - # nodePackages_latest.typescript-language-server is marked broken in nixpkgs JavascriptShell = BashShell & { @@ -239,8 +234,6 @@ in }, }, - # broken: PyLTI-0.7.0 not supported for interpreter python3.10 - # works with a regular nix shell though Python310Shell = BashShell & { @@ -276,7 +269,7 @@ in HaskellStackShell = BashShell & { - ghcVersion, # User-defined. To keep in sync with the one used by stack + ghcVersion | default = "927", # User-defined. To keep in sync with the one used by stack inputs_spec = { stack = {}, ormolu = {}, diff --git a/test-template.sh b/test-template.sh index 528da901..082f93e6 100755 --- a/test-template.sh +++ b/test-template.sh @@ -30,6 +30,9 @@ if [[ -n ${1+x} ]]; then else all_targets=$(nickel export --format raw <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') for target in $all_targets; do + if [[ "$target" == NickelPkg ]]; then + continue + fi test_one $target done fi From 01066495bf60bedb972fcc956f08b9386bde51a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Wed, 5 Jul 2023 17:08:54 +0200 Subject: [PATCH 05/10] Expose the test script as an `app` --- flake.nix | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/flake.nix b/flake.nix index 83309625..16658183 100644 --- a/flake.nix +++ b/flake.nix @@ -142,6 +142,21 @@ program = pkgs.lib.getExe (self.lib.${system}.buildLockFile contents); }; + apps.test.templates = + let testScript = pkgs.writeShellApplication { + name = "test-templates"; + runtimeInputs = [ inputs.nickel.packages."${system}".nickel ]; + text = '' + set -euo pipefail + cd ${./.} + exec ${pkgs.runtimeShell} ./test-template.sh "$@" + ''; + }; in + { + type = "app"; + program = pkgs.lib.getExe testScript; + }; + devShells.default = pkgs.mkShell { packages = [ inputs.nickel.packages."${system}".default From 2bf7686ed02f8836b169945b74b14130207ec93c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Wed, 5 Jul 2023 17:20:50 +0200 Subject: [PATCH 06/10] Remove a dead line of code --- test-template.sh | 3 --- 1 file changed, 3 deletions(-) diff --git a/test-template.sh b/test-template.sh index 082f93e6..ffb395e6 100755 --- a/test-template.sh +++ b/test-template.sh @@ -36,6 +36,3 @@ else test_one $target done fi - - -target=${1:-Nickel} From 2234606c3195c3be1574263112d2f8a1f3ef86ca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Thu, 27 Jul 2023 07:10:27 +0200 Subject: [PATCH 07/10] Restore the example --- .github/workflows/templates.yml | 3 +- examples/c-hello-world/flake.nix | 14 +++++ examples/c-hello-world/hello.c | 6 ++ examples/c-hello-world/nickel.lock.ncl | 8 +++ examples/c-hello-world/package.ncl | 29 +++++++++ flake.nix | 6 +- run-test.sh | 83 ++++++++++++++++++++++++++ test-template.sh | 38 ------------ 8 files changed, 145 insertions(+), 42 deletions(-) create mode 100644 examples/c-hello-world/flake.nix create mode 100644 examples/c-hello-world/hello.c create mode 100644 examples/c-hello-world/nickel.lock.ncl create mode 100644 examples/c-hello-world/package.ncl create mode 100755 run-test.sh delete mode 100755 test-template.sh diff --git a/.github/workflows/templates.yml b/.github/workflows/templates.yml index 50f8ab6c..05e01917 100644 --- a/.github/workflows/templates.yml +++ b/.github/workflows/templates.yml @@ -25,4 +25,5 @@ jobs: - name: Test devshells run: | - nix develop --accept-flake-config --command bash test-template.sh + nix develop --accept-flake-config --command bash run-test.sh template + nix develop --accept-flake-config --command bash run-test.sh example examples/c-hello-world diff --git a/examples/c-hello-world/flake.nix b/examples/c-hello-world/flake.nix new file mode 100644 index 00000000..e0de00a6 --- /dev/null +++ b/examples/c-hello-world/flake.nix @@ -0,0 +1,14 @@ +{ + description = "A basic flake with a shell"; + + inputs.nixpkgs.url = "nixpkgs/nixos-unstable"; + inputs.nickel-nix.url = "github:nickel-lang/nickel-nix"; + + nixConfig = { + extra-substituters = ["https://nickel-nix.cachix.org"]; + extra-trusted-public-keys = ["nickel-nix.cachix.org-1:/Ziozgt3g0CfGwGS795wyjRa9ArE89s3tbz31S6xxFM="]; + }; + + outputs = {nickel-nix, ...} @ inputs: + nickel-nix.flake.outputsFromNickel ./. inputs {}; +} diff --git a/examples/c-hello-world/hello.c b/examples/c-hello-world/hello.c new file mode 100644 index 00000000..73e1b0a9 --- /dev/null +++ b/examples/c-hello-world/hello.c @@ -0,0 +1,6 @@ +#include + +int main() { + printf("Hello, world!"); + return 0; +} diff --git a/examples/c-hello-world/nickel.lock.ncl b/examples/c-hello-world/nickel.lock.ncl new file mode 100644 index 00000000..3a95f954 --- /dev/null +++ b/examples/c-hello-world/nickel.lock.ncl @@ -0,0 +1,8 @@ +{ + nickel-nix = { + builders = import "/nix/store/qb3qvz3xxvnwy5ma1b60ba2gw8pw9vas-5626jyxg49xsax707lciippzazpldgjn-source/builders.ncl", + contracts = import "/nix/store/qb3qvz3xxvnwy5ma1b60ba2gw8pw9vas-5626jyxg49xsax707lciippzazpldgjn-source/contracts.ncl", + + nix = import "/nix/store/qb3qvz3xxvnwy5ma1b60ba2gw8pw9vas-5626jyxg49xsax707lciippzazpldgjn-source/nix.ncl", + }, +} diff --git a/examples/c-hello-world/package.ncl b/examples/c-hello-world/package.ncl new file mode 100644 index 00000000..21783ad7 --- /dev/null +++ b/examples/c-hello-world/package.ncl @@ -0,0 +1,29 @@ +let nickel-nix = (import "./nickel.lock.ncl").nickel-nix in + +nickel-nix.builders.NixpkgsPkg & { + inputs_spec = { + bash.input = "nixpkgs", + coreutils.input = "nixpkgs", + gcc.input = "nixpkgs", + }, + + inputs, + + output = + { + name = "hello", + version = "0.1", + structured_env = { + buildInputs.gcc = inputs.gcc, + buildInputs.coreutils = inputs.coreutils, + buildInputs.bash = inputs.bash, + }, + env = { + buildCommand = nix-s%" + gcc %{nickel-nix.lib.import_file "hello.c"} -o hello + mkdir -p $out/bin + cp hello $out/bin/hello + "%, + }, + } +} diff --git a/flake.nix b/flake.nix index 16658183..7346d3ac 100644 --- a/flake.nix +++ b/flake.nix @@ -142,14 +142,14 @@ program = pkgs.lib.getExe (self.lib.${system}.buildLockFile contents); }; - apps.test.templates = + apps.run-test = let testScript = pkgs.writeShellApplication { name = "test-templates"; - runtimeInputs = [ inputs.nickel.packages."${system}".nickel ]; + runtimeInputs = [ inputs.nickel.packages."${system}".nickel-lang-cli ]; text = '' set -euo pipefail cd ${./.} - exec ${pkgs.runtimeShell} ./test-template.sh "$@" + exec ${pkgs.runtimeShell} ./run-test.sh "$@" ''; }; in { diff --git a/run-test.sh b/run-test.sh new file mode 100755 index 00000000..5627dc34 --- /dev/null +++ b/run-test.sh @@ -0,0 +1,83 @@ +#!/usr/bin/env bash + +set -xeuo pipefail + +usage() { + cat < -- test instantiating the template using the given shell +$0 example -- Try running the example at +EOF + exit 1 +} + +pushd_temp () { + WORKDIR=$(mktemp -d) + function clean() { + rm -rf "${WORKDIR}" + } + trap clean EXIT + pushd "${WORKDIR}" +} + +prepare_shell() { + # We test against the local version of `nickel-nix`, not the one in main (hence the --override-input). + nix flake lock --override-input nickel-nix path:$PROJECT_ROOT --accept-flake-config + nix run .#regenerate-lockfile --accept-flake-config +} + +# Note: running in a subshell (hence the parens and not braces around the function body) so that the trap-based cleanup happens whenever we exit +test_one_template () ( + target="$1" + pushd_temp + + nix flake new --template "path:$PROJECT_ROOT" example --accept-flake-config + + pushd ./example + sed -i "s/BashShell/$target/" dev-shell.ncl + prepare_shell + nix develop --accept-flake-config --print-build-logs < /dev/null + popd + popd + clean +) + +test_template () { + if [[ -n ${1+x} ]]; then + test_one_template "$1" + else + all_targets=$(nickel export --format raw <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') + for target in $all_targets; do + if [[ "$target" == NickelPkg ]] || [[ "$target" == "NixpkgsPkg" ]]; then + continue + fi + test_one_template $target + done + fi +} + +test_example () ( + examplePath=$(realpath "$1") + pushd_temp + cp -r "$examplePath" . + pushd * + prepare_shell + nix build --print-build-logs + popd + popd +) + +PROJECT_ROOT=$PWD + +if [[ -z ${1+x} ]]; then + usage +elif [[ $1 == "template" ]]; then + shift + test_template "$@" +elif [[ $1 == "example" ]]; then + shift + test_example "$@" +else + usage +fi diff --git a/test-template.sh b/test-template.sh deleted file mode 100755 index ffb395e6..00000000 --- a/test-template.sh +++ /dev/null @@ -1,38 +0,0 @@ -#!/usr/bin/env bash - -set -xeuo pipefail - -test_one () { - target="$1" - PROJECT_ROOT=$PWD - WORKDIR=$(mktemp -d) - function clean() { - rm -rf "${WORKDIR}" - } - trap clean EXIT - pushd "${WORKDIR}" - - nix flake new --template "path:$PROJECT_ROOT" example --accept-flake-config - - pushd ./example - sed -i "s/BashShell/$target/" dev-shell.ncl - # We test against the local version of `nickel-nix`, not the one in main (hence the --override-input). - nix flake lock --override-input nickel-nix path:$PROJECT_ROOT --accept-flake-config - nix run .#regenerate-lockfile --accept-flake-config - nix develop --accept-flake-config --print-build-logs < /dev/null - popd - popd - clean -} - -if [[ -n ${1+x} ]]; then - test_one "$1" -else - all_targets=$(nickel export --format raw <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') - for target in $all_targets; do - if [[ "$target" == NickelPkg ]]; then - continue - fi - test_one $target - done -fi From e2df93d098d8e4ef6b7ddc96cfa1b16b04d1d53e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Thu, 27 Jul 2023 16:35:19 +0200 Subject: [PATCH 08/10] Use `nix run` for the tests --- .github/workflows/templates.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/templates.yml b/.github/workflows/templates.yml index 05e01917..6b5fd5b9 100644 --- a/.github/workflows/templates.yml +++ b/.github/workflows/templates.yml @@ -25,5 +25,5 @@ jobs: - name: Test devshells run: | - nix develop --accept-flake-config --command bash run-test.sh template - nix develop --accept-flake-config --command bash run-test.sh example examples/c-hello-world + nix run .#run-test template + nix run .#run-test example examples/c-hello-world From 8deaa421be7008845a4cd6dbb06b2e28de47be3f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Thu, 27 Jul 2023 20:54:59 +0200 Subject: [PATCH 09/10] Don't cd in the flake dir when running the tests Let the user do it, and benefit from the shellcheck of `writeShellApplication`. --- flake.nix | 6 +----- run-test.sh | 8 ++++---- 2 files changed, 5 insertions(+), 9 deletions(-) diff --git a/flake.nix b/flake.nix index 7346d3ac..e97682b4 100644 --- a/flake.nix +++ b/flake.nix @@ -146,11 +146,7 @@ let testScript = pkgs.writeShellApplication { name = "test-templates"; runtimeInputs = [ inputs.nickel.packages."${system}".nickel-lang-cli ]; - text = '' - set -euo pipefail - cd ${./.} - exec ${pkgs.runtimeShell} ./run-test.sh "$@" - ''; + text = builtins.readFile ./run-test.sh; }; in { type = "app"; diff --git a/run-test.sh b/run-test.sh index 5627dc34..9604fa36 100755 --- a/run-test.sh +++ b/run-test.sh @@ -23,7 +23,7 @@ pushd_temp () { prepare_shell() { # We test against the local version of `nickel-nix`, not the one in main (hence the --override-input). - nix flake lock --override-input nickel-nix path:$PROJECT_ROOT --accept-flake-config + nix flake lock --override-input nickel-nix "path:$PROJECT_ROOT" --accept-flake-config nix run .#regenerate-lockfile --accept-flake-config } @@ -47,12 +47,12 @@ test_template () { if [[ -n ${1+x} ]]; then test_one_template "$1" else - all_targets=$(nickel export --format raw <<<'std.record.fields (import "builders.ncl") |> std.string.join " "') + all_targets=$(nickel export --format raw <<<'std.record.fields ((import "lib/nix.ncl").builders) |> std.string.join " "') for target in $all_targets; do if [[ "$target" == NickelPkg ]] || [[ "$target" == "NixpkgsPkg" ]]; then continue fi - test_one_template $target + test_one_template "$target" done fi } @@ -61,7 +61,7 @@ test_example () ( examplePath=$(realpath "$1") pushd_temp cp -r "$examplePath" . - pushd * + pushd ./* prepare_shell nix build --print-build-logs popd From 719acd19e559bf18791b9ab9cc8bbce87f4dc30b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Th=C3=A9ophane=20Hufschmitt?= Date: Thu, 27 Jul 2023 20:55:47 +0200 Subject: [PATCH 10/10] Avoid a fishy `pushd *` --- run-test.sh | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/run-test.sh b/run-test.sh index 9604fa36..98aa502b 100755 --- a/run-test.sh +++ b/run-test.sh @@ -60,8 +60,8 @@ test_template () { test_example () ( examplePath=$(realpath "$1") pushd_temp - cp -r "$examplePath" . - pushd ./* + cp -r "$examplePath" ./example + pushd ./example prepare_shell nix build --print-build-logs popd