Skip to content

Commit

Permalink
Break up the lib output (#107)
Browse files Browse the repository at this point in the history
Split the `lib` definitions into separate files and update the usage of
upstream projects like Flaky and Bash strict mode.

This also updates to Nixpkgs 24.11, obviating #105.
sellout authored Jan 7, 2025
2 parents 49e6ddf + 8982ed0 commit 8feff89
Showing 12 changed files with 172 additions and 126 deletions.
1 change: 1 addition & 0 deletions .config/project/default.nix
Original file line number Diff line number Diff line change
@@ -52,6 +52,7 @@ in {
shellcheck.enable = true;
treefmt = {
enable = true;
package = lib.mkForce pkgs.treefmt;
## Shell linter
programs.shellcheck.enable = true;
## Shell formatter
65 changes: 45 additions & 20 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

84 changes: 49 additions & 35 deletions flake.nix
Original file line number Diff line number Diff line change
@@ -17,14 +17,14 @@
};

outputs = {
bash-strict-mode,
flake-schemas,
flake-utils,
flaky,
nixpkgs,
nixpkgs-22_11,
nixpkgs-23_05,
nixpkgs-23_11,
nixpkgs-24_05,
nixpkgs-unstable,
self,
systems,
@@ -35,14 +35,15 @@
supportedSystems = import systems;

pkgsFor = system:
import nixpkgs {
inherit system;
overlays = [
bash-strict-mode.overlays.default
flaky.overlays.dependencies
self.overlays.default
];
nixpkgs.legacyPackages.${system}.appendOverlays [flaky.overlays.default];

releaseInfo = import ./release.nix;

localPackages = pkgs: {
project-manager = pkgs.callPackage ./project-manager {
inherit (releaseInfo) release;
};
};
in
{
schemas =
@@ -51,13 +52,24 @@

templates = import ./templates;

lib = import ./nix/lib.nix {
inherit bash-strict-mode flake-utils pkgsFor treefmt-nix;
project-manager = self;
};

overlays.default = final: prev: {
project-manager = self.packages.${final.system}.project-manager;
lib = import ./nix/lib {inherit flake-utils pkgsFor self treefmt-nix;};

overlays = {
default =
nixpkgs.lib.composeExtensions
flaky.overlays.default
self.overlays.local;

local = final: prev:
{
lib =
prev.lib
// {
projectConfiguration = self.lib.configuration;
defaultProjectConfiguration = self.lib.defaultConfiguration;
};
}
// localPackages final;
};

## All of the modules included in Project Manager. You generally don’t
@@ -77,27 +89,25 @@
// flake-utils.lib.eachSystem supportedSystems
(system: let
projectConfigurationsFor = pkgs:
flaky.lib.projectConfigurations.default {
flaky.lib.projectConfigurations.nix {
inherit pkgs self supportedSystems;
};

pkgs = pkgsFor system;
in {
packages = let
releaseInfo = import ./release.nix;
docs = import ./docs {
inherit pkgs self;
inherit (releaseInfo) release isReleaseBranch;
};
in {
default = self.packages.${system}.project-manager;
docs-html = docs.manual.html;
docs-json = docs.options.json;
docs-manpages = docs.manPages;
project-manager = pkgs.callPackage ./project-manager {
inherit (releaseInfo) release;
in
localPackages pkgs
// {
default = self.packages.${system}.project-manager;
docs-html = docs.manual.html;
docs-json = docs.options.json;
docs-manpages = docs.manPages;
};
};

projectConfigurations = projectConfigurationsFor pkgs;

@@ -130,14 +140,13 @@
["."]
["_"]
nixpkgs.lib.trivial.release))
(projectConfigurationsFor (import nixpkgs {
inherit system;
overlays = [overlay];
}))
(projectConfigurationsFor
(nixpkgs.legacyPackages.${system}.appendOverlays [overlay]))
.checks;
allChecks =
self.projectConfigurations.${system}.checks
// checksWith nixpkgs-22_11 (_: _: {})
## TODO: Reenable tests n 22.11 once we can build more packages on garnix.
# // checksWith nixpkgs-22_11 (final: _: {treefmt2 = final.treefmt;})
// checksWith nixpkgs-23_05 (final: prev: {
haskellPackages = prev.haskellPackages.extend (hfinal: hprev:
if final.system == "i686-linux"
@@ -159,6 +168,8 @@
});
}
else {});

treefmt2 = final.treefmt;
})
// checksWith nixpkgs-23_11 (final: prev: {
haskellPackages = prev.haskellPackages.extend (hfinal: hprev:
@@ -167,19 +178,22 @@
pandoc_3_1_9 = final.haskell.lib.dontCheck hprev.pandoc_3_1_9;
}
else {});
treefmt2 = final.treefmt;
})
## This is covered by the version used to build Project Manager
# // checksWith nixpkgs-24_05 (_: _: {})
// checksWith nixpkgs-unstable (final: prev: {
// checksWith nixpkgs-24_05 (final: prev: {
haskellPackages = prev.haskellPackages.extend (hfinal: hprev:
if final.system == "i686-linux"
then {
pandoc_3_1_9 = final.haskell.lib.dontCheck hprev.pandoc_3_1_9;
unordered-containers =
final.haskell.lib.dontCheck
hprev.unordered-containers;
}
else {});
});
})
## This is covered by the version used to build Project Manager
# // checksWith nixpkgs-24_11 (_: _: {})
// checksWith nixpkgs-unstable (_: _: {});
in
## FIXME: Because the basement override isn’t working.
if system == "i686-linux"
@@ -196,7 +210,6 @@
url = "github:sellout/flaky";
};

bash-strict-mode.follows = "flaky/bash-strict-mode";
flake-utils.follows = "flaky/flake-utils";
## The Nixpkgs release to use internally for building Project Manager
## itself, regardless of the downstream package set.
@@ -215,6 +228,7 @@
nixpkgs-22_11.url = "github:NixOS/nixpkgs/release-22.11";
nixpkgs-23_05.url = "github:NixOS/nixpkgs/release-23.05";
nixpkgs-23_11.url = "github:NixOS/nixpkgs/release-23.11";
nixpkgs-24_05.url = "github:NixOS/nixpkgs/release-24.05";
nixpkgs-unstable.url = "github:NixOS/nixpkgs/nixpkgs-unstable";

treefmt-nix = {
2 changes: 1 addition & 1 deletion garnix.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 0 additions & 1 deletion modules/programs/project-manager.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
{
bash-strict-mode,
config,
lib,
pkgs,
13 changes: 7 additions & 6 deletions modules/programs/shellcheck.nix
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
bash-strict-mode,
config,
lib,
pkgs,
pmPkgs,
self,
...
}: let
@@ -147,14 +147,15 @@ in {
else cfg.package;
in {
project = {
checks.shellcheck = bash-strict-mode.lib.checkedDrv pkgs (pkgs.runCommand "shellcheck" {
checks.shellcheck =
pmPkgs.runStrictCommand "shellcheck" {
nativeBuildInputs = [wrapped];
src = config.project.cleanRepositoryPersistedExcept [".shellcheckrc"] self;
}
''
src =
config.project.cleanRepositoryPersistedExcept [".shellcheckrc"] self;
} ''
shellcheck "$src/project-manager/project-manager"
mkdir -p "$out"
'');
'';

file.".shellcheckrc" = lib.mkIf (!cfg.wrapProgram) {
text = lib.concatLines (lib.concatLists [
4 changes: 1 addition & 3 deletions modules/programs/vale.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
bash-strict-mode,
config,
flaky,
lib,
pkgs,
pmPkgs,
@@ -116,7 +114,7 @@ in {
devPackages = [cfg.package];

checks.vale =
flaky.lib.runEmptyCommand pmPkgs "vale" {
pmPkgs.runEmptyCommand "vale" {
nativeBuildInputs = [
pkgs.cacert
pkgs.vale
44 changes: 19 additions & 25 deletions modules/project-environment.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
{
bash-strict-mode,
config,
flaky,
lib,
pkgs,
pmPkgs,
@@ -450,8 +448,9 @@ in {
"23.05" = ["0.1" "0.2" "0.3" "0.4" "0.5" "0.6" "0.7"];
"23.11" = ["0.3" "0.4" "0.5" "0.6" "0.7"];
"24.05" = ["0.3" "0.4" "0.5" "0.6" "0.7"];
## NB: These versions are only “supported” on unstable, not 24.11.
"24.11" = ["0.3" "0.4" "0.5" "0.6" "0.7"];
## NB: These versions are only “supported” on unstable, not 25.05.
"25.05" = ["0.7"];
};
pmRelease = cfg.version.release;
nixpkgsRelease = lib.trivial.release;
@@ -652,7 +651,7 @@ in {
${activationCmds}
'';
in
flaky.lib.runCommand pmPkgs
pmPkgs.runStrictCommand
"project-manager-generation-for-${cfg.name}"
{
preferLocalBuild = true;
@@ -702,8 +701,7 @@ in {
};
project = {
checks.project-manager-files =
flaky.lib.runEmptyCommand pmPkgs "project-manager-files"
{
pmPkgs.runEmptyCommand "project-manager-files" {
nativeBuildInputs = [
config.programs.git.package
config.programs.project-manager.package
@@ -712,8 +710,7 @@ in {
];

meta.description = "Check that the generated files are up-to-date.";
}
''
} ''
PRJ="$(mktemp --directory --tmpdir project.XXXXXX)"
cp -r ${self}/. $PRJ
chmod -R a+w $PRJ
@@ -761,32 +758,29 @@ in {
'';

devShells = {
project-manager = bash-strict-mode.lib.checkedDrv pkgs (pkgs.mkShell {
project-manager = pkgs.checkedDrv (pkgs.mkShell {
inherit (pkgs) system;
nativeBuildInputs = [cfg.packages.path];
shellHook = cfg.extraProfileCommands;
meta = {
description = "A shell provided by Project Manager.";
};
meta.description = "A shell provided by Project Manager.";
});

## This includes all unsandboxed checks as dependencies, so they can be
## run independently of `nix flake check`.
lax-checks =
lib.mkIf (cfg.unsandboxedChecks != {})
(bash-strict-mode.lib.checkedDrv pkgs
(pkgs.mkShell {
meta.description = ''
This shell runs all of the checks that are unsandboxed, then
exits.
'';
nativeBuildInputs =
builtins.attrValues cfg.unsandboxedChecks;

shellHook = ''
exit
'';
}));
(pkgs.checkedDrv (pkgs.mkShell {
meta.description = ''
This shell runs all of the checks that are unsandboxed, then
exits.
'';
nativeBuildInputs =
builtins.attrValues cfg.unsandboxedChecks;

shellHook = ''
exit
'';
}));
};

filterRepositoryPersistedExcept = exceptions: _type: name:
39 changes: 7 additions & 32 deletions nix/lib.nix → nix/lib/configuration.nix
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
{
bash-strict-mode,
flake-utils,
pkgsFor,
project-manager,
self,
treefmt-nix,
}: {
configuration = {
}: let
project-manager = self;
in
{
self,
modules ? [],
pkgs,
@@ -14,7 +15,7 @@
check ? true,
supportedSystems ? flake-utils.lib.defaultSystems,
}:
import ../modules {
import ../../modules {
inherit check extraSpecialArgs lib pkgs;
configuration = {
imports =
@@ -23,7 +24,6 @@
{
_module.args = {
inherit
bash-strict-mode
project-manager
self
supportedSystems
@@ -38,29 +38,4 @@
];
};
modules = builtins.attrValues project-manager.projectModules;
};

## Takes the same arguments as `configuration`, but
## defaults to loading configuration from `$PROJECT_ROOT/.config/project` and
## `$PROJECT_ROOT/.config/project/user`.
defaultConfiguration = {
self,
modules ? [],
...
} @ args: let
projectConfig = "${self}/.config/project";
userConfig = "${projectConfig}/user";
in
project-manager.lib.configuration
(args
// {
modules =
modules
++ [projectConfig]
++ (
if builtins.pathExists userConfig
then [userConfig]
else []
);
});
}
}
23 changes: 23 additions & 0 deletions nix/lib/default-configuration.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
## Takes the same arguments as `configuration`, but defaults to loading
## configuration from `$PROJECT_ROOT/.config/project` and
## `$PROJECT_ROOT/.config/project/user`.
{configuration}: {
self,
modules ? [],
...
} @ args: let
projectConfig = "${self}/.config/project";
userConfig = "${projectConfig}/user";
in
configuration
(args
// {
modules =
modules
++ [projectConfig]
++ (
if builtins.pathExists userConfig
then [userConfig]
else []
);
})
15 changes: 15 additions & 0 deletions nix/lib/default.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
flake-utils,
pkgsFor,
self,
treefmt-nix,
}: let
configuration = import ./configuration.nix {
inherit flake-utils pkgsFor self treefmt-nix;
};
in {
inherit configuration;

defaultConfiguration =
import ./default-configuration.nix {inherit configuration;};
}
7 changes: 4 additions & 3 deletions project-manager/default.nix
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
runCommand,
runStrictCommand,
lib,
bash-strict-mode,
callPackage,
@@ -21,7 +21,7 @@
or (callPackage
(pkgs.path + "/nixos/modules/installer/tools/nixos-option") {});
in
runCommand "project-manager" {
runStrictCommand "project-manager" {
preferLocalBuild = true;
buildInputs = [bash-strict-mode];
nativeBuildInputs = [gettext];
@@ -59,7 +59,8 @@ in
--subst-var-by FLAKE_TEMPLATE '${../templates/default/flake.nix}' \
--subst-var-by CONFIG_TEMPLATE '${../templates/default/.config/project/default.nix}'
patchShebangs --host $out/bin/project-manager
## See NixOS/nixpkgs#247410.
(set +u; patchShebangs --host $out/bin/project-manager)
install -D -m755 ${./completion.bash} \
$out/share/bash-completion/completions/project-manager

0 comments on commit 8feff89

Please sign in to comment.