From 75ef37f3cbd699de3e7c4439e959633cba690d5a Mon Sep 17 00:00:00 2001 From: Hao Date: Tue, 4 Jun 2024 08:21:57 +1000 Subject: [PATCH 1/2] 1. Use type alias featureType 2. Fix the URL pointing to Just import --- nix/feature.nix | 2 +- nix/features.nix | 6 +++--- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/nix/feature.nix b/nix/feature.nix index 1daca27..17589c6 100644 --- a/nix/feature.nix +++ b/nix/feature.nix @@ -21,7 +21,7 @@ description = '' The justfile code for importing this feature's justfile. - See https://just.systems/man/en/chapter_53.html + See https://just.systems/man/en/chapter_55.html ''; default = if config.enable diff --git a/nix/features.nix b/nix/features.nix index b811de6..e093495 100644 --- a/nix/features.nix +++ b/nix/features.nix @@ -25,15 +25,15 @@ in options.features = { convco = lib.mkOption { description = "Add the 'changelog' target calling convco"; - type = types.submodule { imports = [ featureMod ]; }; + type = featureType; }; rust = lib.mkOption { description = "Add 'w' and 'test' targets for running cargo"; - type = types.submodule { imports = [ featureMod ]; }; + type = featureType; }; treefmt = lib.mkOption { description = "Add the 'fmt' target to format source tree using treefmt"; - type = types.submodule { imports = [ featureMod ]; }; + type = featureType; }; }; From b92a197fcaaf59a30a2ae078ce776d8941d6e1df Mon Sep 17 00:00:00 2001 From: Hao Date: Wed, 5 Jun 2024 12:08:49 +1000 Subject: [PATCH 2/2] Add CI --- .github/workflows/ci.yaml | 24 ++++++++ dev/flake.lock | 115 ++++++++++++++++++++++++++++++++++++++ dev/flake.nix | 32 +++++++++++ flake.nix | 13 +++++ test/flake.nix | 61 ++++++++++++++++++++ 5 files changed, 245 insertions(+) create mode 100644 .github/workflows/ci.yaml create mode 100644 dev/flake.lock create mode 100644 dev/flake.nix create mode 100644 test/flake.nix diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml new file mode 100644 index 0000000..22d8b2e --- /dev/null +++ b/.github/workflows/ci.yaml @@ -0,0 +1,24 @@ +name: "CI" +on: + push: + branches: + - main + pull_request: +jobs: + checks: + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-14] + steps: + - uses: actions/checkout@v4 + - uses: cachix/install-nix-action@v25 + with: + nix_path: nixpkgs=channel:nixos-unstable + extra_nix_config: | + trusted-public-keys = cache.garnix.io:CTFPyKSLcx5RMJKfLo5EEPUObbA78b0YQ2DTCJXqr9g= cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY= + substituters = https://cache.garnix.io?priority=41 https://cache.nixos.org/ + - uses: yaxitech/nix-install-pkgs-action@v3 + with: + packages: "github:srid/nixci" + - run: nixci build diff --git a/dev/flake.lock b/dev/flake.lock new file mode 100644 index 0000000..d994455 --- /dev/null +++ b/dev/flake.lock @@ -0,0 +1,115 @@ +{ + "nodes": { + "flake-parts": { + "inputs": { + "nixpkgs-lib": "nixpkgs-lib" + }, + "locked": { + "lastModified": 1685662779, + "narHash": "sha256-cKDDciXGpMEjP1n6HlzKinN0H+oLmNpgeCTzYnsA2po=", + "owner": "hercules-ci", + "repo": "flake-parts", + "rev": "71fb97f0d875fd4de4994dfb849f2c75e17eb6c3", + "type": "github" + }, + "original": { + "owner": "hercules-ci", + "repo": "flake-parts", + "type": "github" + } + }, + "just-flake": { + "locked": { + "lastModified": 1713316411, + "narHash": "sha256-NkJfU6H+6vgHkPtZ2ESbZ/h2wnsDQrZvB4vbdUIBx8Q=", + "owner": "juspay", + "repo": "just-flake", + "rev": "0e33952a4bcd16cd54ee3aba8111606c237d4526", + "type": "github" + }, + "original": { + "owner": "juspay", + "repo": "just-flake", + "type": "github" + } + }, + "nixpkgs": { + "locked": { + "lastModified": 1709613862, + "narHash": "sha256-mH+c2gFEzEe49lhUWJ0ieIaMaJ1W85E6G1xLm8ege90=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "311a4be96d940a0c673e88bd5bc83ea4f005cc02", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixpkgs-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs-lib": { + "locked": { + "dir": "lib", + "lastModified": 1685564631, + "narHash": "sha256-8ywr3AkblY4++3lIVxmrWZFzac7+f32ZEhH/A8pNscI=", + "owner": "NixOS", + "repo": "nixpkgs", + "rev": "4f53efe34b3a8877ac923b9350c874e3dcd5dc0a", + "type": "github" + }, + "original": { + "dir": "lib", + "owner": "NixOS", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "nixpkgs_2": { + "locked": { + "lastModified": 1708475490, + "narHash": "sha256-g1v0TsWBQPX97ziznfJdWhgMyMGtoBFs102xSYO4syU=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "0e74ca98a74bc7270d28838369593635a5db3260", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "nixos-unstable", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "flake-parts": "flake-parts", + "just-flake": "just-flake", + "nixpkgs": "nixpkgs", + "treefmt-nix": "treefmt-nix" + } + }, + "treefmt-nix": { + "inputs": { + "nixpkgs": "nixpkgs_2" + }, + "locked": { + "lastModified": 1717278143, + "narHash": "sha256-u10aDdYrpiGOLoxzY/mJ9llST9yO8Q7K/UlROoNxzDw=", + "owner": "numtide", + "repo": "treefmt-nix", + "rev": "3eb96ca1ae9edf792a8e0963cc92fddfa5a87706", + "type": "github" + }, + "original": { + "owner": "numtide", + "repo": "treefmt-nix", + "type": "github" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/dev/flake.nix b/dev/flake.nix new file mode 100644 index 0000000..58f08e9 --- /dev/null +++ b/dev/flake.nix @@ -0,0 +1,32 @@ +{ + inputs = { + nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable"; + flake-parts.url = "github:hercules-ci/flake-parts"; + treefmt-nix.url = "github:numtide/treefmt-nix"; + just-flake.url = "github:juspay/just-flake"; + }; + outputs = inputs@{ self, nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + imports = [ + inputs.treefmt-nix.flakeModule + ]; + perSystem = { pkgs, lib, config, ... }: { + treefmt = { + projectRoot = inputs.just-flake; + projectRootFile = "flake.nix"; + programs = { + nixpkgs-fmt.enable = true; + }; + }; + devShells.default = pkgs.mkShell { + packages = with pkgs; [ + nixd + ]; + inputsFrom = [ + config.treefmt.build.devShell + ]; + }; + }; + }; +} diff --git a/flake.nix b/flake.nix index 2bfc7b7..690d2f7 100644 --- a/flake.nix +++ b/flake.nix @@ -2,5 +2,18 @@ description = "A `flake-parts` module for including `just` in devShell"; outputs = _: { flakeModule = import ./flake-module.nix; + + # https://github.com/srid/nixci + nixci.default = let overrideInputs = { just-flake = ./.; }; in { + dev = { + inherit overrideInputs; + dir = "dev"; + }; + + test = { + inherit overrideInputs; + dir = "test"; + }; + }; }; } diff --git a/test/flake.nix b/test/flake.nix new file mode 100644 index 0000000..7b23405 --- /dev/null +++ b/test/flake.nix @@ -0,0 +1,61 @@ +{ + # Since there is no flake.lock file (to avoid incongruent just-flake + # pinning), we must specify revisions for *all* inputs to ensure + # reproducibility. + inputs = { + nixpkgs = { }; + flake-parts = { }; + just-flake = { }; + }; + outputs = inputs@{ self, nixpkgs, flake-parts, ... }: + flake-parts.lib.mkFlake { inherit inputs; } { + systems = nixpkgs.lib.systems.flakeExposed; + imports = [ + inputs.just-flake.flakeModule + ]; + + perSystem = { config, self', pkgs, lib, ... }: { + just-flake = { + commonFileName = "justfile"; + + features = { + convco.enable = true; + }; + }; + + devShells.test = pkgs.mkShell { + inputsFrom = [ + config.just-flake.outputs.devShell + ]; + }; + + # Our test + checks.test = + pkgs.runCommandNoCC "test" + { + nativeBuildInputs = with pkgs; [ + which + ] ++ self'.devShells.test.nativeBuildInputs; + } + '' + ( + set -x + echo "Testing ..." + + which just || \ + (echo "just should be in devshell"; exit 2) + + ${self'.devShells.test.shellHook} + + grep -q treefmt justfile && \ + (echo "justfile should not import treefmt"; exit 2) + + grep -q convco justfile || \ + (echo "justfile should import convco"; exit 2) + + touch $out + ) + ''; + }; + }; +}