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

Expose finalPackages #68

Merged
merged 12 commits into from
Feb 8, 2023
18 changes: 18 additions & 0 deletions docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/usr/bin/env sh

# Renders the docs, prints the location of the docs, opens the docs if possible
#
# Does not run the link checker. That's done in runtest.sh.

nix --option sandbox false \
build --override-input haskell-flake path:${FLAKE} \
-L --show-trace \
github:hercules-ci/flake.parts-website \
"$@"

echo "Docs rendered to $PWD/result/options/haskell-flake.html"

# Works on linux
if type xdg-open &>/dev/null; then
xdg-open result/options/haskell-flake.html
fi
56 changes: 54 additions & 2 deletions flake-module.nix
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,27 @@ in
};
};
};
projectSubmodule = types.submodule (args@{ name, config, lib, ... }: {
projectSubmodule = types.submodule (args@{ name, config, lib, ... }:
let
localPackagesOverlay = self: _:
let
fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg));
filterSrc = name: src: lib.cleanSourceWith { inherit src name; filter = path: type: true; };
in
lib.mapAttrs
(name: value:
let
# callCabal2nix does not need a filtered source. It will
# only pick out the cabal and/or hpack file.
pkgProto = self.callCabal2nix name value.root { };
pkgFiltered = pkgs.haskell.lib.overrideSrc pkgProto {
src = filterSrc name value.root;
};
in
fromSdist pkgFiltered)
config.packages;
in
{
options = {
haskellPackages = mkOption {
type = types.attrsOf raw;
Expand Down Expand Up @@ -133,8 +153,40 @@ in
This is an internal option, not meant to be set by the user.
'';
};

# Derived options

finalPackages = mkOption {
type = types.attrsOf raw;
readOnly = true;
Copy link
Owner

@srid srid Feb 8, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks like readonly has no effect, because I can still set finalPackages.foo = ./.; (even finalPackages = ./.;) in test/flake.nix?

Or does it just silently ignore user values?

description = ''
The final package set, based `haskellPackages` plus
the additions and overrides specified in the other options.
'';
};
finalOverlay = mkOption {
type = types.raw;
readOnly = true;
internal = true;
};
};
config = import ./haskell-project.nix (args // { inherit self pkgs; });
config = lib.mkMerge [
{
finalPackages = config.haskellPackages.extend config.finalOverlay;

finalOverlay = lib.composeManyExtensions [
# The order here matters.
#
# User's overrides (cfg.overrides) is applied **last** so
# as to give them maximum control over the final package
# set used.
localPackagesOverlay
(pkgs.haskell.lib.packageSourceOverrides config.source-overrides)
config.overrides
];
}
(import ./haskell-project.nix (args // { inherit self pkgs; }))
];
});
in
{
Expand Down
31 changes: 1 addition & 30 deletions haskell-project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -29,36 +29,7 @@ in
let
projectKey = name;

localPackagesOverlay = self: _:
let
fromSdist = self.buildFromCabalSdist or (builtins.trace "Your version of Nixpkgs does not support hs.buildFromCabalSdist yet." (pkg: pkg));
filterSrc = name: src: lib.cleanSourceWith { inherit src name; filter = path: type: true; };
in
lib.mapAttrs
(name: value:
let
# callCabal2nix does not need a filtered source. It will
# only pick out the cabal and/or hpack file.
pkgProto = self.callCabal2nix name value.root { };
pkgFiltered = pkgs.haskell.lib.overrideSrc pkgProto {
src = filterSrc name value.root;
};
in
fromSdist pkgFiltered)
config.packages;
finalOverlay =
lib.composeManyExtensions
[
# The order here matters.
#
# User's overrides (cfg.overrides) is applied **last** so
# as to give them maximum control over the final package
# set used.
localPackagesOverlay
(pkgs.haskell.lib.packageSourceOverrides config.source-overrides)
config.overrides
];
finalPackages = config.haskellPackages.extend finalOverlay;
finalPackages = config.finalPackages;

defaultBuildTools = hp: with hp; {
inherit
Expand Down
6 changes: 6 additions & 0 deletions runtest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,10 @@ echo "\n||| Testing nix flake checks"
nix --option sandbox false \
build --override-input haskell-flake path:${FLAKE} -L .#check

echo "\n||| Testing docs"
nix --option sandbox false \
build --override-input haskell-flake path:${FLAKE} \
-L --show-trace \
github:hercules-ci/flake.parts-website#checks.x86_64-linux.linkcheck
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd remove -L --show-trace since they are not used in the commands above (or is there a reason for their inclusion, aside from debugging purposes?). Also, must sandbox be disabled for this build?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The sandbox was disabled in an earlier command, so I assumed that you run this in a setup where that's necessary. This build works fine in the sandbox, but I've only ever built it in a nice NixOS-based sandbox.

The verbosity is helpful when this runs in CI. You'll only look at it when it fails, and then you want all the info. Module system errors tend to need --show-trace, at least until we have

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

A proper CI solves this problem in the UI, but admittedly consuming an unpinned input like the site here isn't possible yet in Hercules.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Anyway, I've changed it so that logs only appear when there's a problem. Still not great if the builder hangs, but that's unlikely to be a problem here.


echo "\n||| All tests passed!"