Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove flake dependency on nixpkgs/core #2

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
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
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,23 @@ There are two main parts:
- `stdlib` - mostly copied from Nixpkg's standard library. Meant to be forwards-compatible.
- `auxlib` - library bits specifically for aux / auxpkgs. Not necessarily forwards-compatible.

## `extra/`

Due to limitations with flakes, both tests and documentation are stored in `extra/`.
This avoids the `lib` flake having to depend on other places for testing and documentation tools, which are basically dev dependencies.

This directory uses `npins`, as using flakes requires constantly running `nix flake update` to pick up local changes.

## Testing

Tests are stored in `tests/<part>`. You can run them all with `nix-build tests/default.nix`, which will run them with the minimum and maximum supported nix versions.
Tests are stored in `extra/tests/<part>`. You can run them all with `nix-build -E '(import ./extra {}).checks.tests` (or `.stdlib`, `.auxlib`).

Alternatively, if using flakes you can run `nix flake check`. This will also check formatting using `nixfmt`.
You should also check your formatting with `nix-build -E '(import ./extra {}).checks.formatting`.

## Documentation

Reference documentation for library functions is written above each function as a multi-line comment.
These comments are processed using [nixdoc](https://github.com/nix-community/nixdoc), although currently we aren't doing much with the output.
The nixdoc README describes the [comment format](https://github.com/nix-community/nixdoc#comment-format).

You can build the documentation with `nix-build -E '(import ./extra {}).packages.docs'`.
63 changes: 63 additions & 0 deletions extra/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
{
nixpkgs ? (import ./npins).nixpkgs,
}:
let
libSrc = ../.;
lib = import libSrc;
pkgs = import nixpkgs {
overlays = [
# update nixfmt, as nixpkgs is pretty out of date
(
final: prev:
prev
// {
nixfmt = prev.nixfmt.overrideAttrs {
src = final.fetchFromGitHub {
owner = "nixos";
repo = "nixfmt";
rev = "3bcb63c13e7aaf0b8e14081cf0c14c44f62e840a";
sha256 = "sha256-8QWhKKqpHSlHuvFW8wdWTbG0pJ6XtuxZQ3HhR4uPbRA=";
};
};
}
)
];
};
in
{
devShell = pkgs.mkShellNoCC { packages = [ pkgs.nixfmt ]; };

packages = {
docs = pkgs.callPackage ./doc { inherit libSrc; };
};

checks =
let
auxlib = import ./tests/auxlib { inherit pkgs libSrc; };
stdlib = import ./tests/stdlib { inherit pkgs libSrc; };
tests = pkgs.symlinkJoin {
name = "auxlib-tests";
paths = [
auxlib
stdlib
];
};
formatting = pkgs.callPackage ./tests/formatting.nix { inherit libSrc; };
in
{
all = pkgs.symlinkJoin {
name = "auxlib-checks";
paths = [
tests
formatting
];
};

inherit
auxlib
stdlib
tests
formatting
;
};
}
23 changes: 14 additions & 9 deletions doc/default.nix → extra/doc/default.nix
Original file line number Diff line number Diff line change
@@ -1,15 +1,20 @@
{ lib, runCommand, nixdoc, ... }:
{
auxlib,
lib,
runCommand,
nixdoc,
...
}:
let
inherit (lib) escapeShellArg concatMapStringsSep;
sections = import ./sections.nix;
in runCommand "auxolotl-stdlib-docs" { buildInputs = [ nixdoc ]; } ''
sections = import ./sections.nix auxlib;
in
runCommand "auxolotl-stdlib-docs" { buildInputs = [ nixdoc ]; } ''
mkdir $out
function docgen {
name=$1
path=$2
description=$3
echo $path
set -x
nixdoc -c "$name" -d "lib.$name: $description" -f "$path" > "$out/$name.md"
echo "$name.md" >> "$out/index.md"
}
Expand All @@ -19,10 +24,10 @@ in runCommand "auxolotl-stdlib-docs" { buildInputs = [ nixdoc ]; } ''
cat > "$out/index.md" << 'EOF'
```{=include=} sections auto-id-prefix=auto-generated
EOF
${concatMapStringsSep "\n" (section:
"docgen ${escapeShellArg section.name} ${section.path} ${
escapeShellArg section.description
};") sections}
${concatMapStringsSep "\n" (
section:
"docgen ${escapeShellArg section.name} ${section.path} ${escapeShellArg section.description};"
) sections}

echo '```' >> "$out/index.md"
''
43 changes: 23 additions & 20 deletions doc/sections.nix → extra/doc/sections.nix
Original file line number Diff line number Diff line change
@@ -1,93 +1,96 @@
auxlib:
let
libPath = "${auxlib}/nix";
in
[
{
name = "asserts";
description = "assertion functions";
path = ../nix/stdlib/asserts.nix;
path = "${libPath}/stdlib/asserts.nix";
}
{
name = "attrsets";
description = "attribute set functions";
path = ../nix/stdlib/attrsets.nix;
path = "${libPath}/stdlib/attrsets.nix";
}
{
name = "strings";
description = "string manipulation functions";
path = ../nix/stdlib/strings.nix;
path = "${libPath}/stdlib/strings.nix";
}
{
name = "versions";
description = "version string functions";
path = ../nix/stdlib/versions.nix;
path = "${libPath}/stdlib/versions.nix";
}
{
name = "trivial";
description = "miscellaneous functions";
path = ../nix/stdlib/trivial.nix;
path = "${libPath}/stdlib/trivial.nix";
}
{
name = "fixed-points";
description = "explicit recursion functions";
path = ../nix/stdlib/fixed-points.nix;
path = "${libPath}/stdlib/fixed-points.nix";
}
{
name = "lists";
description = "list manipulation functions";
path = ../nix/stdlib/lists.nix;
path = "${libPath}/stdlib/lists.nix";
}
{
name = "debug";
description = "debugging functions";
path = ../nix/stdlib/debug.nix;
path = "${libPath}/stdlib/debug.nix";
}
{
name = "options";
description = "NixOS / nixpkgs option handling";
path = ../nix/stdlib/options.nix;
path = "${libPath}/stdlib/options.nix";
}
{
name = "path";
description = "path functions";
path = ../nix/stdlib/path/default.nix;
path = "${libPath}/stdlib/path/default.nix";
}
{
name = "filesystem";
description = "filesystem functions";
path = ../nix/stdlib/filesystem.nix;
path = "${libPath}/stdlib/filesystem.nix";
}
{
name = "fileset";
description = "file set functions";
path = ../nix/stdlib/fileset/default.nix;
path = "${libPath}/stdlib/fileset/default.nix";
}
{
name = "sources";
description = "source filtering functions";
path = ../nix/stdlib/sources.nix;
path = "${libPath}/stdlib/sources.nix";
}
{
name = "cli";
description = "command-line serialization functions";
path = ../nix/stdlib/cli.nix;
path = "${libPath}/stdlib/cli.nix";
}
{
name = "gvariant";
description = "GVariant formatted string serialization functions";
path = ../nix/stdlib/gvariant.nix;
path = "${libPath}/stdlib/gvariant.nix";
}
{
name = "customisation";
description =
"Functions to customise (derivation-related) functions, derivatons, or attribute sets";
path = ../nix/stdlib/customisation.nix;
description = "Functions to customise (derivation-related) functions, derivatons, or attribute sets";
path = "${libPath}/stdlib/customisation.nix";
}
{
name = "meta";
description = "functions for derivation metadata";
path = ../nix/stdlib/meta.nix;
path = "${libPath}/stdlib/meta.nix";
}
{
name = "derivations";
description = "miscellaneous derivation-specific functions";
path = ../nix/stdlib/derivations.nix;
path = "${libPath}/stdlib/derivations.nix";
}
]
65 changes: 65 additions & 0 deletions extra/npins/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
# Generated by npins. Do not modify; will be overwritten regularly
let
data = builtins.fromJSON (builtins.readFile ./sources.json);
version = data.version;

mkSource =
spec:
assert spec ? type;
let
path =
if spec.type == "Git" then
mkGitSource spec
else if spec.type == "GitRelease" then
mkGitSource spec
else if spec.type == "PyPi" then
mkPyPiSource spec
else if spec.type == "Channel" then
mkChannelSource spec
else
builtins.throw "Unknown source type ${spec.type}";
in
spec // { outPath = path; };

mkGitSource =
{
repository,
revision,
url ? null,
hash,
...
}:
assert repository ? type;
# At the moment, either it is a plain git repository (which has an url), or it is a GitHub/GitLab repository
# In the latter case, there we will always be an url to the tarball
if url != null then
(builtins.fetchTarball {
inherit url;
sha256 = hash; # FIXME: check nix version & use SRI hashes
})
else
assert repository.type == "Git";
builtins.fetchGit {
url = repository.url;
rev = revision;
# hash = hash;
};

mkPyPiSource =
{ url, hash, ... }:
builtins.fetchurl {
inherit url;
sha256 = hash;
};

mkChannelSource =
{ url, hash, ... }:
builtins.fetchTarball {
inherit url;
sha256 = hash;
};
in
if version == 3 then
builtins.mapAttrs (_: mkSource) data.pins
else
throw "Unsupported format version ${toString version} in sources.json. Try running `npins upgrade`"
11 changes: 11 additions & 0 deletions extra/npins/sources.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
{
"pins": {
"nixpkgs": {
"type": "Channel",
"name": "nixos-23.11",
"url": "https://releases.nixos.org/nixos/23.11/nixos-23.11.7122.9ddcaffecdf0/nixexprs.tar.xz",
"hash": "1mgli2h99cg1db95gm9n59l8ws7kyi0lhb5dyxqzxlb8csg76j9m"
}
},
"version": 3
}
23 changes: 23 additions & 0 deletions extra/tests/auxlib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
# The pkgs used for dependencies for the testing itself
# Don't test properties of pkgs.lib, but rather the lib in the parent directory
pkgs ? import <nixpkgs> { } // {
lib = throw "pkgs.lib accessed, but the lib tests should use nixpkgs' lib path directly!";
},
libSrc,
nix ? pkgs-nixVersions.stable,
nixVersions ? [
pkgs-nixVersions.minimum
nix
pkgs-nixVersions.unstable
],
pkgs-nixVersions ? import ../nix-for-tests.nix { inherit pkgs; },
}:

let
testWithNix = nix: import ./test-with-nix.nix { inherit libSrc nix pkgs; };
in
pkgs.symlinkJoin {
name = "auxlib-tests";
paths = map testWithNix nixVersions;
}
18 changes: 18 additions & 0 deletions extra/tests/auxlib/test-with-nix.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# * Runs all library tests with a particular version of Nix.
{
pkgs,
libSrc,
# Only ever use this nix; see comment at top
nix,
}:
pkgs.runCommand "auxlib-tests-nix-${nix.version}"
{
buildInputs = [
# TODO: Tests!
];
strictDeps = true;
}
''
mkdir $out
echo success > $out/${nix.version}
''
13 changes: 13 additions & 0 deletions extra/tests/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
pkgs ? import <nixpkgs> { } // {
lib = throw "pkgs.lib accessed, but the lib tests should use nixpkgs' lib path directly!";
},
libSrc ? ../..,
}:
pkgs.symlinkJoin {
name = "nixpkgs-lib-tests";
paths = [
(import ./stdlib { inherit pkgs libSrc; })
(import ./auxlib { inherit pkgs libSrc; })
];
}
10 changes: 10 additions & 0 deletions extra/tests/formatting.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{
libSrc,
runCommand,
nixfmt,
}:
runCommand "aux-lib-formatting" { buildInputs = [ nixfmt ]; } ''
find ${libSrc} -iname '*.nix' -type f -print0 | xargs -0 -i nixfmt -c {}
mkdir $out
touch $out/formatted
''
Loading