Skip to content

Commit

Permalink
Test templates (#1)
Browse files Browse the repository at this point in the history
* Testing templates

* Running nix flake init on an empty directory

* Fix mktemp flag

* Remove suffix

* Calling flake show

* Print workspace

* Quote template source

* Run nix-shell

* Add hasVersion to python plugin

* Use relative paths for testing template

* Fix path to asdf2nix

* Point inputs to a specific commit during the testing phase

* Run git add --all

* Print the content of templates/default/flake.nix

* Fix plugins input

* Setup nixpkgs-python cache

* Use a matrix to test templates

* Add devenv template

* Customize test command for each template

* Add descriptions to CI steps

* Add description to templates
  • Loading branch information
sestrella authored Nov 15, 2023
1 parent 715fe99 commit 354e559
Show file tree
Hide file tree
Showing 6 changed files with 93 additions and 9 deletions.
36 changes: 33 additions & 3 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,40 @@ concurrency:
cancel-in-progress: true

jobs:
templates:
strategy:
matrix:
template:
- name: default
test: nix develop --accept-flake-config -c python --version
- name: devenv
test: nix develop --accept-flake-config --impure -c python --version
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v23
- name: Replace inputs on templates
run: sed -i 's/github:sestrella\/asdf2nix/github:sestrella\/asdf2nix\/${{ github.sha }}/g' templates/*/flake.nix
- name: Create a temporary directory
run: echo "tmpdir=$(mktemp -d)" >> "$GITHUB_OUTPUT"
id: mktemp
- name: Scaffold a new project
run: nix flake init -t ${{ github.workspace }}#${{ matrix.template.name }}
working-directory: ${{ steps.mktemp.outputs.tmpdir }}
- name: Run smoke test
run: ${{ matrix.template.test }}
working-directory: ${{ steps.mktemp.outputs.tmpdir }}

test:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: cachix/install-nix-action@v23
- run: nix eval --impure .#tests
- name: Checkout code
uses: actions/checkout@v4
- name: Install Nix
uses: cachix/install-nix-action@v23
- name: Run tests
run: nix eval --impure .#tests
working-directory: tests

12 changes: 9 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -83,9 +83,15 @@
(removeComments
(fileLines versionsFile)))));

templates.default = {
description = "TODO";
path = ./templates/default;
templates = {
default = {
description = "Install Nix packages from asdf versions file";
path = ./templates/default;
};
devenv = {
description = "Integration with devenv";
path = ./templates/devenv;
};
};
};
}
8 changes: 6 additions & 2 deletions plugins/python/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@
inputs.nixpkgs-python.url = "github:cachix/nixpkgs-python";

outputs = { self, nixpkgs-python }: {
lib.packageFromVersion = { system ? builtins.currentSystem, version }:
nixpkgs-python.packages.${system}.${version};
lib = {
hasVersion = { version, system ? builtins.currentSystem }:
builtins.hasAttr version nixpkgs-python.packages.${system};
packageFromVersion = { version, system ? builtins.currentSystem }:
nixpkgs-python.packages.${system}.${version};
};
};
}
7 changes: 6 additions & 1 deletion templates/default/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

nixConfig = {
extra-substituters = "https://cache.nixos.org https://nixpkgs-python.cachix.org";
extra-trusted-public-keys = "nixpkgs-python.cachix.org-1:hxjI7pFxTyuTHn2NkvWCrAUcNZLNS3ZAvfYNuYifcEU=";
};

outputs = { self, asdf2nix-python, asdf2nix, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
Expand All @@ -14,7 +19,7 @@
inherit system;
versionsFile = ./.tool-versions;
plugins = {
python = asdf2nix-python.lib.packageFromVersion;
python = asdf2nix-python.lib;
};
};
in
Expand Down
1 change: 1 addition & 0 deletions templates/devenv/.tool-versions
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
python 3.12.0
38 changes: 38 additions & 0 deletions templates/devenv/flake.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
{
inputs = {
asdf2nix-python.url = "github:sestrella/asdf2nix?dir=plugins/python";
asdf2nix.url = "github:sestrella/asdf2nix";
devenv.url = "github:cachix/devenv";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
};

nixConfig = {
extra-substituters = "https://cache.nixos.org https://nixpkgs-python.cachix.org";
extra-trusted-public-keys = "nixpkgs-python.cachix.org-1:hxjI7pFxTyuTHn2NkvWCrAUcNZLNS3ZAvfYNuYifcEU=";
};

outputs = inputs@{ self, asdf2nix-python, asdf2nix, devenv, flake-utils, nixpkgs }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
packages = asdf2nix.lib.packagesFromVersionsFile {
inherit system;
versionsFile = ./.tool-versions;
plugins = {
python = asdf2nix-python.lib;
};
};
in
{
devShells.default = devenv.lib.mkShell {
inherit inputs pkgs;
modules = [
({ pkgs, config, ... }: {
languages.python.enable = true;
languages.python.package = packages.python;
})
];
};
});
}

0 comments on commit 354e559

Please sign in to comment.