Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
60 changes: 12 additions & 48 deletions .github/workflows/flake-check.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,13 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
bootstrap: [inputs, flake, npins, unflake]
bootstrap:
- test-inputs
- test-flake
- test-unflake
- test-npins
- test-npins-follows
- test-npins-transitive
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
steps:
Expand All @@ -30,23 +36,10 @@ jobs:
- uses: DeterminateSystems/magic-nix-cache-action@main
- uses: actions/checkout@v4
- run: mkdir bootstrap
- run: nix-shell ./default.nix -A flake-file.sh --run write-${{matrix.bootstrap}} --arg modules ./modules/bootstrap.nix --argstr outdir bootstrap
- run: cat bootstrap/inputs.nix
if: ${{ matrix.bootstrap == 'inputs' }}
- run: cat bootstrap/flake.nix
if: ${{ matrix.bootstrap == 'flake' }}
- run: cat bootstrap/unflake.nix
if: ${{ matrix.bootstrap == 'unflake' }}
- run: cat bootstrap/npins/sources.json
if: ${{ matrix.bootstrap == 'npins' }}
- name: Assert bootstrap npins transitive discovery (flake-parts -> nixpkgs-lib)
if: ${{ matrix.bootstrap == 'npins' }}
run: |
jq -e '.pins | has("flake-parts")' bootstrap/npins/sources.json
jq -e '.pins | has("nixpkgs-lib")' bootstrap/npins/sources.json
- run: nix-shell ./dev/_bootstrap-tests.nix --run ${{matrix.bootstrap}} --argstr outdir bootstrap
template:
name: Check template ${{matrix.template}}
needs: [find-templates]
needs: [dev, find-templates]
runs-on: ubuntu-latest
strategy:
matrix:
Expand Down Expand Up @@ -75,6 +68,7 @@ jobs:
nix run .#write-flake -L --show-trace --override-input flake-file "github:$GITHUB_REPOSITORY/$GITHUB_SHA"
nix flake check -L --show-trace --override-input flake-file "github:$GITHUB_REPOSITORY/$GITHUB_SHA"
npins:
needs: [dev]
name: Check npins
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'npins') }}
Expand All @@ -89,39 +83,8 @@ jobs:
sed -i 's/# flake-file = import/flake-file = import/' default.nix
echo "{ inputs, ... }: { npins.pkgs = import inputs.nixpkgs {}; }" | tee modules/pkgs.nix
nix-shell . -A npins.env --run write-npins
npins-transitive:
name: Check npins transitive discovery
runs-on: ubuntu-latest
env:
NIX_PATH: "nixpkgs=https://github.com/NixOS/nixpkgs/archive/nixos-unstable.tar.gz"
steps:
- uses: actions/checkout@v4
- uses: wimpysworld/nothing-but-nix@main
- uses: cachix/install-nix-action@v31
- uses: DeterminateSystems/magic-nix-cache-action@main
- name: Run write-npins with neomacs (has transitive deps)
run: |
mkdir test-out
nix-shell ./default.nix -A flake-file.sh \
--run write-npins \
--arg modules ./modules/npins-transitive-test.nix \
--argstr outdir test-out
- name: Assert declared inputs are pinned
run: |
jq -e '.pins | has("neomacs")' test-out/npins/sources.json
jq -e '.pins | has("nixpkgs")' test-out/npins/sources.json
- name: Assert transitive deps are auto-discovered
run: |
jq -e '.pins | has("crane")' test-out/npins/sources.json
jq -e '.pins | has("rust-overlay")' test-out/npins/sources.json
jq -e '.pins | has("nix-wpe-webkit")' test-out/npins/sources.json
- name: Assert dedup-by-name (nixpkgs stays as Channel, not re-pinned from neomacs dep)
run: |
jq -e '.pins.nixpkgs.type == "Channel"' test-out/npins/sources.json
- name: Show pinned sources
if: always()
run: cat test-out/npins/sources.json
unflake:
needs: [dev]
name: Check unflake
runs-on: ubuntu-latest
if: ${{ contains(github.event.pull_request.labels.*.name, 'unflake') }}
Expand All @@ -137,6 +100,7 @@ jobs:
echo "{ inputs, ... }: { unflake.pkgs = import inputs.nixpkgs {}; }" | tee modules/pkgs.nix
nix-shell . -A unflake.env --run 'write-unflake --verbose'
dev:
needs: [bootstrap]
name: Check flake dev
runs-on: ubuntu-latest
steps:
Expand Down
64 changes: 1 addition & 63 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,63 +1 @@
{
pkgs ? import <nixpkgs> { },
modules ? [ ],
outdir ? ".",
bootstrap ? [ ],
outputs ? null,
import-tree ? (
pkgs.fetchFromGitHub {
owner = "vic";
repo = "import-tree";
rev = "c968d3b54d12cf5d9c13f16f7c545a06c9d1fde6";
hash = "sha256-oYO4poyw0Sb/db2PigqugMlDwsvwLg6CSpFrMUWxA3Q=";
}
),
...
}:
let
inherit (pkgs) lib;

tree = (import import-tree) modules;

attrsOpt = lib.mkOption {
default = { };
type = lib.types.submodule { freeformType = lib.types.lazyAttrsOf lib.types.unspecified; };
};

bootstrapInputs =
let
ins = import ./modules/bootstrap.nix { inherit lib; };
take = name: { flake-file.inputs.${name} = ins.flake-file.inputs.${name}; };
names =
if bootstrap == true then lib.attrNames ins.flake-file.inputs else lib.flatten [ bootstrap ];
in
map take names;

module = {
imports = [
tree
./modules
./modules/options
./modules/npins.nix
./modules/unflake.nix
./modules/write-inputs.nix
./modules/write-flake.nix
./modules/flake-options.nix
{ imports = bootstrapInputs; }
(if outputs == null then { } else { flake-file.outputs = outputs; })
];
config.flake-file.intoPath = outdir;
options = {
lib = attrsOpt;
templates = attrsOpt;
flakeModules = attrsOpt;
};
};

evaled = lib.evalModules {
modules = [ module ];
specialArgs.inputs.self.outPath = "";
};

in
evaled.config
import ./modules/bootstrap
119 changes: 119 additions & 0 deletions dev/_bootstrap-tests.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,119 @@
{
pkgs ? import <nixpkgs> { },
outdir ? ".",
...
}@args:
let

bootstrap =
modules:
import ./.. (
args
// {
inherit modules;
}
);

empty = bootstrap {
inputs.empty.url = "github:vic/empty-flake";
outputs = _: { };
};

flake-parts = bootstrap {
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
};

flake-parts-follows = bootstrap {
inputs.nixpkgs-lib.url = "github:vic/empty-flake";
inputs.flake-parts.url = "github:hercules-ci/flake-parts";
inputs.flake-parts.inputs.nixpkgs-lib.follows = "nixpkgs-lib";
};

test-inputs = pkgs.writeShellApplication {
name = "test-inputs";
runtimeInputs = [
(empty.flake-file.apps.write-inputs pkgs)
];
text = ''
write-inputs
cat ${outdir}/inputs.nix
grep github:vic/empty-flake ${outdir}/inputs.nix
'';
};

test-flake = pkgs.writeShellApplication {
name = "test-flake";
runtimeInputs = [
pkgs.nix
(empty.flake-file.apps.write-flake pkgs)
];
text = ''
write-flake
cat ${outdir}/flake.nix
grep github:vic/empty-flake ${outdir}/flake.nix
'';
};

test-npins = pkgs.writeShellApplication {
name = "test-npins";
runtimeInputs = [
(empty.flake-file.apps.write-npins pkgs)
pkgs.jq
];
text = ''
write-npins
cat ${outdir}/npins/sources.json
jq -e '.pins | has("empty")' ${outdir}/npins/sources.json
'';
};

test-npins-transitive = pkgs.writeShellApplication {
name = "test-npins-transitive";
runtimeInputs = [
(flake-parts.flake-file.apps.write-npins pkgs)
pkgs.jq
];
text = ''
write-npins
cat ${outdir}/npins/sources.json
jq -e '.pins."flake-parts".url | contains("hercules-ci/flake-parts")' ${outdir}/npins/sources.json
jq -e '.pins."nixpkgs-lib".url | contains("nix-community/nixpkgs.lib")' ${outdir}/npins/sources.json
'';
};

test-npins-follows = pkgs.writeShellApplication {
name = "test-npins-follows";
runtimeInputs = [
(flake-parts-follows.flake-file.apps.write-npins pkgs)
pkgs.jq
];
text = ''
write-npins
cat ${outdir}/npins/sources.json
jq -e '.pins."flake-parts".url | contains("hercules-ci/flake-parts")' ${outdir}/npins/sources.json
echo FAIL jq -e '.pins."nixpkgs-lib".url | contains("vic/empty")' ${outdir}/npins/sources.json
'';
};

test-unflake = pkgs.writeShellApplication {
name = "test-unflake";
runtimeInputs = [
(empty.flake-file.apps.write-unflake pkgs)
];
text = ''
write-unflake --backend nix
grep unflake_github_vic_empty-flake ${outdir}/unflake.nix
'';
};

in
pkgs.mkShell {
buildInputs = [
test-inputs
test-flake
test-unflake
test-npins
test-npins-follows
test-npins-transitive
];
}
1 change: 1 addition & 0 deletions dev/modules/formatter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
"**/unflake.nix" # generated by: nix-shell . -A unflake.env --run write-unflake
"**/inputs.nix" # generated by: nix-shell . -A unflake.env --run write-inputs
"**/npins/default.nix" # generated by write-npins
"*.bash"
"docs/*"
];
};
Expand Down
71 changes: 0 additions & 71 deletions dev/modules/unit-tests/npins.nix

This file was deleted.

Loading