Skip to content

Commit

Permalink
✨ Add support for nixpkgs up to 23.11
Browse files Browse the repository at this point in the history
- Change linter from nix-lint to statix since the former is broken in
23.11 and seems somewhat unmaintained. Fix all lints as well.
  • Loading branch information
abbec authored and sakarias88 committed Feb 6, 2024
1 parent 392e2f7 commit 2192673
Show file tree
Hide file tree
Showing 26 changed files with 215 additions and 102 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/checks.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ on:
default: true
type: boolean

nix-lint:
nixlint:
description: "If linting of nix files should run, default true."
default: true
type: boolean
Expand Down Expand Up @@ -63,7 +63,7 @@ jobs:

lint:
name: Lint Nix Expressions 🦕 📝 👀
if: ${{ inputs.nix-lint }}
if: ${{ inputs.nixlint }}
runs-on: ubuntu-latest

steps:
Expand All @@ -75,7 +75,7 @@ jobs:
install_url: https://releases.nixos.org/nix/nix-${{ inputs.nix-version }}/install

- name: Lint Nix files 🦕 📝 👀
run: nix run .#checks.nix-lint
run: nix run .#checks.nixlint

actionlint:
name: Lint Github Actions 🐙 🐱 🎬
Expand Down
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,14 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0

## [Unreleased]

### Added
- Support for nixpkgs up to 23.11

### Changed
- The default linter is now statix instead of nix-lint. The name of the nix attribute and
script is also changed from `nix-lint` to `nixlint` to be consistent with other linting
tools.

### Fixed
- Shells were assuming that the `name` attribute always existed on derivations.
This is not always true and `pname` can now also be used.
Expand Down
2 changes: 2 additions & 0 deletions ci/actionlint
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@

set -uo pipefail

@preamble@

# the two ignores are for an older version of the actionlint tool
# TODO: check version?

Expand Down
2 changes: 2 additions & 0 deletions ci/check
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ set -uo pipefail
shopt -s nullglob
shopt -s extglob

@preamble@

export NEDRYLAND_CHECK_COLOR=1
emoji_index=0
exit_code=0
Expand Down
30 changes: 18 additions & 12 deletions ci/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
, mktemp
, shellcheck
, shfmt
, nix-linter
, statix
, bash
, gnused
, python3
Expand All @@ -17,24 +17,30 @@ runCommandLocal "check"
mktemp = "${mktemp}/bin/mktemp";
shellcheck = "${shellcheck}/bin/shellcheck";
shfmt = "${shfmt}/bin/shfmt";
nixLinter = "${nix-linter}/bin/nix-linter";
nixLinter = "${statix}/bin/statix";
bash = "${bash}/bin/bash";
sed = "${gnused}/bin/sed";
pyflakes = "${python3.pkgs.pyflakes}/bin/pyflakes";
actionlint = "${actionlint}/bin/actionlint";
preamble = ''
if [[ ",''${NEDRYLAND_NO_USE_CHECK_FILES:-}," =~ ",$(basename "$0")," ]]; then
echo "forcing file list off for tool \"$(basename "$0")\""
unset NEDRYLAND_CHECK_FILES
fi
'';
}
(builtins.foldl'
(buildScript: inputScript:
let
outputScript = "${(builtins.placeholder "out")}/bin/${builtins.head (builtins.split "\\\." (builtins.baseNameOf inputScript))}";
in
''
${buildScript}
mkdir -p "$(dirname "${outputScript}")"
substituteAll ${inputScript} ${outputScript}
chmod +x ${outputScript}
''
let
outputScript = "${(builtins.placeholder "out")}/bin/${builtins.head (builtins.split "\\\." (builtins.baseNameOf inputScript))}";
in
''
${buildScript}
mkdir -p "$(dirname "${outputScript}")"
substituteAll ${inputScript} ${outputScript}
chmod +x ${outputScript}
''
)
""
[ ./nixfmt ./shellcheck ./nix-lint ./check ./actionlint ]
[ ./nixfmt ./shellcheck ./nixlint ./check ./actionlint ]
)
2 changes: 2 additions & 0 deletions ci/nixfmt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
set -uo pipefail
color="auto"

@preamble@

[ -n "${NEDRYLAND_CHECK_COLOR:-}" ] && color="always"

check="--check"
Expand Down
11 changes: 7 additions & 4 deletions ci/nix-lint → ci/nixlint
Original file line number Diff line number Diff line change
@@ -1,16 +1,19 @@
#! @bash@
# shellcheck shell=bash

set -uo pipefail
@preamble@

set -uo pipefail
if [ $# -eq 0 ]; then
if [ -z "${NEDRYLAND_CHECK_FILES:-}" ]; then
@nixLinter@ -r .
@nixLinter@ check .
exit $?
else
exitCode=0
while mapfile -t -n 50 nix_files && ((${#nix_files[@]})); do
if ! @nixLinter@ "${nix_files[@]}"; then
# statix cannot support multiple files
# https://github.com/nerdypepper/statix/issues/69
while mapfile -t -n 1 nix_files && ((${#nix_files[@]})); do
if ! @nixLinter@ check "${nix_files[@]}"; then
exitCode=1;
fi
done <<< "$(grep ".nix$" < "$NEDRYLAND_CHECK_FILES")"
Expand Down
3 changes: 3 additions & 0 deletions ci/shellcheck
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@
# shellcheck shell=bash

set -uo pipefail

@preamble@

color="auto"
[ -n "${NEDRYLAND_CHECK_COLOR:-}" ] && color="always"

Expand Down
12 changes: 6 additions & 6 deletions component.nix
Original file line number Diff line number Diff line change
Expand Up @@ -13,16 +13,16 @@ rec {
mkComponentInner = attrs@{ name, nedrylandType ? "component", ... }:
let
component =
(attrs // {
attrs // {
inherit name path nedrylandType;
} // (pkgs.lib.optionalAttrs (nedrylandType != "component-set" && attrs ? deployment) {
# the deploy target is simply the sum of everything
# in the deployment set
deploy = mkCombinedDeployment "${name}-deploy" attrs.deployment;
deployment = attrs.deployment //
(pkgs.linkFarm
"${name}-deployment"
(pkgs.lib.mapAttrsToList (name: path: { inherit name path; }) attrs.deployment));
(pkgs.linkFarm
"${name}-deployment"
(pkgs.lib.mapAttrsToList (name: path: { inherit name path; }) attrs.deployment));
}) // (pkgs.lib.optionalAttrs (nedrylandType != "component-set" && attrs ? docs && !pkgs.lib.isDerivation attrs.docs) {
# the docs target is a symlinkjoin of all sub-derivations
docs =
Expand All @@ -41,7 +41,7 @@ rec {
echo '${builtins.toJSON attrsWithResolvedDocDrvs}' > $out/share/doc/${name}/metadata.json
'';
};
}));
});

docsRequirement = (parseConfig {
key = "docs";
Expand Down Expand Up @@ -98,7 +98,7 @@ rec {
if value.isNedrylandComponent or false then
[
({
accessPath = (path ++ [ name ]);
accessPath = path ++ [ name ];
} // value)
] ++ (recurse (path ++ [ name ]) value)
else
Expand Down
49 changes: 24 additions & 25 deletions default.nix
Original file line number Diff line number Diff line change
@@ -1,21 +1,10 @@
let
gitignore = import (builtins.fetchTarball {
url = "https://github.com/hercules-ci/gitignore.nix/archive/a20de23b925fd8264fd7fad6454652e142fd7f73.tar.gz";
sha256 = "sha256:07vg2i9va38zbld9abs9lzqblz193vc5wvqd6h7amkmwf66ljcgh";
});

gitIgnoreOverlay = _: prev: (gitignore {
lib = prev.lib // (prev.lib.optionalAttrs (! prev.lib ? inPureEvalMode) {
inPureEvalMode = ! builtins ? currentSystem;
});
});

f = { pkgs, skipNixpkgsVersionCheck ? false }:
assert pkgs.lib.assertMsg
(!skipNixpkgsVersionCheck && pkgs.lib.versionAtLeast (builtins.replaceStrings [ "pre-git" ] [ "" ] (pkgs.lib.version or "0.0.0")) "22.05")
"Nedryland supports nixpkgs versions >= 22.05, you have ${pkgs.lib.version or "unknown"}}";
let
pkgs' = pkgs.extend gitIgnoreOverlay;
pkgs' = pkgs;
version = "9.0.0";
versionAtLeast = pkgs'.lib.versionAtLeast version;
in
Expand Down Expand Up @@ -90,10 +79,19 @@ let
(!(attrs ? name) -> attrs ? pname && attrs ? version)
"mkDerivation missing required argument name, alternatively supply pname and version.";
let
gitignore = (import (builtins.fetchTarball {
url = "https://github.com/hercules-ci/gitignore.nix/archive/a20de23b925fd8264fd7fad6454652e142fd7f73.tar.gz";
sha256 = "sha256:07vg2i9va38zbld9abs9lzqblz193vc5wvqd6h7amkmwf66ljcgh";
})) {
lib = pkgs'.lib // (pkgs'.lib.optionalAttrs (! pkgs'.lib ? inPureEvalMode) {
inPureEvalMode = ! builtins ? currentSystem;
});
};

customerFilter = src:
let
# IMPORTANT: use a let binding like this to memoize info about the git directories.
srcIgnored = pkgs'.gitignoreFilter src;
srcIgnored = gitignore.gitignoreFilter src;
in
filter:
path: type:
Expand All @@ -105,7 +103,7 @@ let
inherit (attrs) src;
filter = customerFilter attrs.src attrs.srcFilter;
name = "${attrs.name or attrs.pname}-source";
} else pkgs'.gitignoreSource attrs.src;
} else gitignore.gitignoreSource attrs.src;
in
stdenv.mkDerivation ((builtins.removeAttrs attrs [ "stdenv" "srcFilter" "shellCommands" ]) //
{
Expand All @@ -118,18 +116,19 @@ let
}
// pkgs'.lib.optionalAttrs (attrs.doCheck or true)
(
let checkAttrs = {
# LintPhase for checks that does not require to run the built program
lintPhase = attrs.lintPhase or ''echo "No lintPhase defined, doing nothing"'';
preInstallPhases = attrs.preInstallPhases or [ ] ++ [ "lintPhase" ];
nativeBuildInputs = attrs.nativeBuildInputs or [ ] ++ attrs.lintInputs or [ ];
};
let
checkAttrs = {
# LintPhase for checks that does not require to run the built program
lintPhase = attrs.lintPhase or ''echo "No lintPhase defined, doing nothing"'';
preInstallPhases = attrs.preInstallPhases or [ ] ++ [ "lintPhase" ];
nativeBuildInputs = attrs.nativeBuildInputs or [ ] ++ attrs.lintInputs or [ ];
};
in
(checkAttrs // pkgs'.lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && attrs.doCrossCheck or false) {
checkAttrs // pkgs'.lib.optionalAttrs (stdenv.hostPlatform != stdenv.buildPlatform && attrs.doCrossCheck or false) {
crossCheckPhase = attrs.crossCheckPhase or attrs.checkPhase or ''echo "No checkPhase or crossCheckPhase defined (but doCrossCheck is true), doing nothing"'';
preInstallPhases = checkAttrs.preInstallPhases ++ [ "crossCheckPhase" ];
nativeBuildInputs = checkAttrs.nativeBuildInputs ++ attrs.checkInputs or [ ];
})
}
)
// (pkgs'.lib.optionalAttrs (attrs ? src) {
src = if pkgs'.lib.isStorePath attrs.src then attrs.src else filteredSrc;
Expand Down Expand Up @@ -166,7 +165,7 @@ let
extFn (
builtins.intersectAttrs args (components // { inherit components; })
// builtins.intersectAttrs args pkgs'
// builtins.intersectAttrs args (let base = (pkgs'.lib.recursiveUpdate initialBase combinedBaseExtensions); in base // { inherit base; })
// builtins.intersectAttrs args (let base = pkgs'.lib.recursiveUpdate initialBase combinedBaseExtensions; in base // { inherit base; })
)
))
)
Expand Down Expand Up @@ -313,7 +312,7 @@ let
)
(resolvedComponents // extraTargets);
in
(rec {
rec {
inherit (appliedAttrs) name;
pkgs = pkgs';

Expand Down Expand Up @@ -350,7 +349,7 @@ let

} // (pkgs'.lib.optionalAttrs
(appliedAttrs ? version)
{ inherit (appliedAttrs) version; }));
{ inherit (appliedAttrs) version; });
override =
f;
};
Expand Down
2 changes: 1 addition & 1 deletion documentation/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ in

builtins.mapAttrs
(_: f: attrs: {
docfunction = (name: type: (f ({ inherit name type; } // attrs)));
docfunction = name: type: (f ({ inherit name type; } // attrs));
})
rec {
mkProjectDocs =
Expand Down
32 changes: 25 additions & 7 deletions examples/dependencies/child/flake.lock

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

4 changes: 2 additions & 2 deletions examples/dependencies/child/flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
description = "Example project demonstrating project dependencies.";

inputs = {
pkgs.url = github:NixOS/nixpkgs/nixos-22.11;
flake-utils.url = github:numtide/flake-utils;
pkgs.url = "github:NixOS/nixpkgs/nixos-23.11";
flake-utils.url = "github:numtide/flake-utils";
};

outputs = { pkgs, flake-utils, ... }:
Expand Down
2 changes: 1 addition & 1 deletion examples/dependencies/father/project.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
(nedryland { inherit pkgs; }).mkProject {
name = "dep-example-father";

components = {}: { };
components = _: { };

baseExtensions = [
./extensions/mkfather.nix
Expand Down
Loading

0 comments on commit 2192673

Please sign in to comment.