Merge "Add pre-commit checks" into main

This commit is contained in:
Rebecca Turner 2024-03-30 22:26:59 +00:00 committed by Gerrit Code Review
commit 4b730f328e
102 changed files with 496 additions and 392 deletions

View file

@ -48,4 +48,3 @@ PointerAlignment: Middle
SortIncludes: Never
SpaceAfterCStyleCast: true
SpaceAfterTemplateKeyword: false

View file

@ -17,4 +17,3 @@ jobs:
with:
fetch-depth: 0
- run: bash scripts/check-hydra-status.sh

2
.gitignore vendored
View file

@ -159,3 +159,5 @@ result-*
buildtime.bin
.envrc.local
# We generate this with a Nix shell hook
/.pre-commit-config.yaml

20
COPYING
View file

@ -55,7 +55,7 @@ modified by someone else and passed on, the recipients should know
that what they have is not the original version, so that the original
author's reputation will not be affected by problems that might be
introduced by others.
Finally, software patents pose a constant threat to the existence of
any free program. We wish to make sure that a company cannot
effectively restrict the users of a free program by obtaining a
@ -111,7 +111,7 @@ modification follow. Pay close attention to the difference between a
"work based on the library" and a "work that uses the library". The
former contains code derived from the library, whereas the latter must
be combined with the library in order to run.
GNU LESSER GENERAL PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
@ -158,7 +158,7 @@ Library.
You may charge a fee for the physical act of transferring a copy,
and you may at your option offer warranty protection in exchange for a
fee.
2. You may modify your copy or copies of the Library or any portion
of it, thus forming a work based on the Library, and copy and
distribute such modifications or work under the terms of Section 1
@ -216,7 +216,7 @@ instead of to this License. (If a newer version than version 2 of the
ordinary GNU General Public License has appeared, then you can specify
that version instead if you wish.) Do not make any other change in
these notices.
Once this change is made in a given copy, it is irreversible for
that copy, so the ordinary GNU General Public License applies to all
subsequent copies and derivative works made from that copy.
@ -267,7 +267,7 @@ Library will still fall under Section 6.)
distribute the object code for the work under the terms of Section 6.
Any executables containing that work also fall under Section 6,
whether or not they are linked directly with the Library itself.
6. As an exception to the Sections above, you may also combine or
link a "work that uses the Library" with the Library to produce a
work containing portions of the Library, and distribute that work
@ -329,7 +329,7 @@ restrictions of other proprietary libraries that do not normally
accompany the operating system. Such a contradiction means you cannot
use both them and the Library together in an executable that you
distribute.
7. You may place library facilities that are a work based on the
Library side-by-side in a single library together with other library
facilities not covered by this License, and distribute such a combined
@ -370,7 +370,7 @@ subject to these terms and conditions. You may not impose any further
restrictions on the recipients' exercise of the rights granted herein.
You are not responsible for enforcing compliance by third parties with
this License.
11. If, as a consequence of a court judgment or allegation of patent
infringement or for any other reason (not limited to patent issues),
conditions are imposed on you (whether by court order, agreement or
@ -422,7 +422,7 @@ conditions either of that version or of any later version published by
the Free Software Foundation. If the Library does not specify a
license version number, you may choose any version ever published by
the Free Software Foundation.
14. If you wish to incorporate parts of the Library into other free
programs whose distribution conditions are incompatible with these,
write to the author to ask for permission. For software which is
@ -456,7 +456,7 @@ SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH
DAMAGES.
END OF TERMS AND CONDITIONS
How to Apply These Terms to Your New Libraries
If you develop a new library, and you want it to be of the greatest
@ -500,5 +500,3 @@ necessary. Here is a sample; alter the names:
Ty Coon, President of Vice
That's all there is to it!

0
doc/manual/anchors.jq Executable file → Normal file
View file

View file

@ -37,4 +37,3 @@ error:
error: uh oh!
```

View file

@ -27,4 +27,3 @@
/package-management/channels* /command-ref/nix-channel 301!
/package-management/s3-substituter* /command-ref/new-cli/nix3-help-stores#s3-binary-cache-store 301!

View file

@ -112,4 +112,3 @@ Build inputs used as instructions to a build task are marked accordingly:
| |
+--------------------------------------------------------------------+
```

View file

@ -67,4 +67,3 @@ Configuration options can be set on the command line, overriding the values set
The `extra-` prefix is supported for settings that take a list of items (e.g. `--extra-trusted users alice` or `--option extra-trusted-users alice`).
# Available settings

View file

@ -184,4 +184,3 @@ channel:
```console
$ nix-env --file https://github.com/NixOS/nixpkgs/archive/nixos-14.12.tar.gz --install --attr firefox
```

View file

@ -30,4 +30,3 @@ $ nix-env --list-generations
97 2004-02-06 16:22:45
98 2004-02-06 16:24:33 (current)
```

View file

@ -212,4 +212,3 @@ To show all packages in the latest revision of the Nixpkgs repository:
```console
$ nix-env --file https://github.com/NixOS/nixpkgs/archive/master.tar.gz --query --available
```

View file

@ -79,4 +79,3 @@ To make files from `binutils` take precedence over files from `gcc`:
$ nix-env --set-flag priority 5 binutils
$ nix-env --set-flag priority 10 gcc
```

View file

@ -27,4 +27,3 @@ contain just Firefox:
```console
$ nix-env --profile /nix/var/nix/profiles/browser --set firefox
```

View file

@ -30,4 +30,3 @@ Switching will fail if the specified generation does not exist.
$ nix-env --switch-generation 42
switching from generation 50 to 42
```

View file

@ -138,4 +138,3 @@ This is illustrated by the following examples:
2.3a < 2.3c
2.3pre1 < 2.3c
2.3pre1 < 2.3q

View file

@ -32,4 +32,3 @@ This operation has the following options:
$ nix-store --add-fixed sha256 ./hello-2.10.tar.gz
/nix/store/3x7dwzq014bblazs7kq20p9hyzz0qh8g-hello-2.10.tar.gz
```

View file

@ -69,4 +69,3 @@ To delete at least 100 MiBs of unreachable paths:
```console
$ nix-store --gc --max-freed $((100 * 1024 * 1024))
```

View file

@ -33,4 +33,3 @@ The following options are allowed for all `nix-store` operations, but may not al
If there are multiple results, then multiple symlinks will be
created by sequentially numbering symlinks beyond the first one
(e.g., `foo`, `foo-2`, `foo-3`, and so on).

View file

@ -37,4 +37,3 @@ hashing files in `/nix/store/qhqx7l2f1kmwihc9bnxs7rc159hsxnf3-gcc-4.1.1'
541838819 bytes (516.74 MiB) freed by hard-linking 54143 files;
there are 114486 files with equal contents out of 215894 files in total
```

View file

@ -28,4 +28,3 @@ export stdenv; stdenv='/nix/store/7c8asx3yfrg5dg1gzhzyq2236zfgibnn-stdenv'
export system; system='x86_64-linux'
export _args; _args='-e /nix/store/9krlzvny65gdc8s7kpb6lkx8cd02c25c-default-builder.sh'
```

View file

@ -225,4 +225,3 @@ $ nix-store --query --roots $(which svn)
/nix/var/nix/profiles/default-82-link
/home/eelco/.local/state/nix/profiles/profile-97-link
```

View file

@ -35,4 +35,3 @@ ktorrent-2.2.1/
ktorrent-2.2.1/NEWS
...
```

View file

@ -32,4 +32,3 @@ $ nix-store --repair-path /nix/store/dj7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13
fetching path `/nix/store/d7a81wsm1ijwwpkks3725661h3263p5-glibc-2.13'...
```

View file

@ -35,4 +35,3 @@ $ cat <<EOF >>/root/.ssh/authorized_keys
command="nice -n20 nix-store --serve --write" ssh-rsa AAAAB3NzaC1yc2EAAAA...
EOF
```

View file

@ -26,4 +26,3 @@ To verify the integrity of the `svn` command and all its dependencies:
```console
$ nix-store --verify-path $(nix-store --query --requisites $(which svn))
```

View file

@ -289,4 +289,3 @@ search/replaced in it for each new build.
The installer now supports a `--tarball-url-prefix` flag which _may_ have
solved this need?
-->

View file

@ -145,4 +145,3 @@ which you may remove.
> complete. macOS (Catalina+) directly controls root directories and its
> read-only root will prevent you from manually deleting the empty `/nix`
> mountpoint.

View file

@ -161,4 +161,3 @@ All comparison operators are implemented in terms of `<`, and the following equi
Equivalent to `!`*b1* `||` *b2*.
[Logical implication]: #logical-implication

View file

@ -3,11 +3,11 @@
"flake-compat": {
"flake": false,
"locked": {
"lastModified": 1673956053,
"narHash": "sha256-4gtG9iQuiKITOjNQQeQIpoIB6b16fm+504Ch3sNKLd8=",
"lastModified": 1696426674,
"narHash": "sha256-kvjfFW7WAETZlt09AgDn1MrtKzP7t90Vf7vypd3OL1U=",
"owner": "edolstra",
"repo": "flake-compat",
"rev": "35bb57c0c8d8b62bbfd284272c928ceb64ddbde9",
"rev": "0f9255e01c2351cc7d116c072cb317785dd33b33",
"type": "github"
},
"original": {
@ -16,13 +16,52 @@
"type": "github"
}
},
"flake-utils": {
"inputs": {
"systems": "systems"
},
"locked": {
"lastModified": 1710146030,
"narHash": "sha256-SZ5L6eA7HJ/nmkzGG7/ISclqe6oZdOZTNoesiInkXPQ=",
"owner": "numtide",
"repo": "flake-utils",
"rev": "b1d9ab70662946ef0850d488da1c9019f3a9752a",
"type": "github"
},
"original": {
"owner": "numtide",
"repo": "flake-utils",
"type": "github"
}
},
"gitignore": {
"inputs": {
"nixpkgs": [
"pre-commit-hooks",
"nixpkgs"
]
},
"locked": {
"lastModified": 1709087332,
"narHash": "sha256-HG2cCnktfHsKV0s4XW83gU3F57gaTljL9KNSuG6bnQs=",
"owner": "hercules-ci",
"repo": "gitignore.nix",
"rev": "637db329424fd7e46cf4185293b9cc8c88c95394",
"type": "github"
},
"original": {
"owner": "hercules-ci",
"repo": "gitignore.nix",
"type": "github"
}
},
"nixpkgs": {
"locked": {
"lastModified": 1709884566,
"narHash": "sha256-NSYJg2sfdO/XS3L8XN/59Zhzn0dqWm7XtVnKI2mHq3w=",
"lastModified": 1711481231,
"narHash": "sha256-J/fW3Xhm3WsJPNd8ksZmfMnol5aOG2qEMDPbOnNNdTQ=",
"owner": "NixOS",
"repo": "nixpkgs",
"rev": "2be119add7b37dc535da2dd4cba68e2cf8d1517e",
"rev": "9d6ddb13cee3cc1192e4430277708c732685f38a",
"type": "github"
},
"original": {
@ -48,11 +87,56 @@
"type": "github"
}
},
"pre-commit-hooks": {
"inputs": {
"flake-compat": [
"flake-compat"
],
"flake-utils": "flake-utils",
"gitignore": "gitignore",
"nixpkgs": [
"nixpkgs"
],
"nixpkgs-stable": [
"nixpkgs"
]
},
"locked": {
"lastModified": 1711562502,
"narHash": "sha256-SLo1yf/lfozph818VME9Y56uhaZWY0juZcj/qJZPPrs=",
"owner": "9999years",
"repo": "git-hooks.nix",
"rev": "d2f6f9376c38fb0c48526720793a17f10cd3ac10",
"type": "github"
},
"original": {
"owner": "9999years",
"ref": "add-default-pre-commit-hooks",
"repo": "git-hooks.nix",
"type": "github"
}
},
"root": {
"inputs": {
"flake-compat": "flake-compat",
"nixpkgs": "nixpkgs",
"nixpkgs-regression": "nixpkgs-regression"
"nixpkgs-regression": "nixpkgs-regression",
"pre-commit-hooks": "pre-commit-hooks"
}
},
"systems": {
"locked": {
"lastModified": 1681028828,
"narHash": "sha256-Vy1rq5AaRuLzOxct8nz4T6wlgyUR7zLU309k9mBC768=",
"owner": "nix-systems",
"repo": "default",
"rev": "da67096a3b9bf56a91d16901293e51ba5b49a27e",
"type": "github"
},
"original": {
"owner": "nix-systems",
"repo": "default",
"type": "github"
}
}
},

View file

@ -1,11 +1,23 @@
{
description = "The purely functional package manager";
inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11-small";
inputs.nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
inputs.flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixos-23.11-small";
nixpkgs-regression.url = "github:NixOS/nixpkgs/215d4d0fd80ca5163643b03a33fde804a29cc1e2";
pre-commit-hooks = {
# Can go back to `cachix/git-hooks.nix` when this is merged:
# https://github.com/cachix/git-hooks.nix/pull/401
url = "github:9999years/git-hooks.nix/add-default-pre-commit-hooks";
inputs = {
flake-compat.follows = "flake-compat";
nixpkgs.follows = "nixpkgs";
nixpkgs-stable.follows = "nixpkgs";
};
};
flake-compat = { url = "github:edolstra/flake-compat"; flake = false; };
};
outputs = { self, nixpkgs, nixpkgs-regression, flake-compat }:
outputs = { self, nixpkgs, nixpkgs-regression, pre-commit-hooks, flake-compat }:
let
inherit (nixpkgs) lib;
@ -278,6 +290,49 @@
}
);
};
pre-commit = builtins.mapAttrs (system: pre-commit-lib: pre-commit-lib.run {
src = self;
hooks = {
no-commit-to-branch = {
enable = true;
settings.branch = ["main"];
};
check-case-conflicts.enable = true;
check-executables-have-shebangs = {
enable = true;
stages = [ "commit" ];
};
check-shebang-scripts-are-executable = {
enable = true;
stages = [ "commit" ];
};
check-symlinks = {
enable = true;
excludes = [ "^tests/functional/lang/symlink-resolution/broken$" ];
};
check-merge-conflicts.enable = true;
end-of-file-fixer = {
enable = true;
excludes = [
"\\.drv$"
"^tests/functional/lang/"
];
};
mixed-line-endings = {
enable = true;
excludes = [ "^tests/functional/lang/" ];
};
# TODO: Once the test suite is nicer, clean up and start
# enforcing trailing whitespace on tests that don't explicitly
# check for it.
trim-trailing-whitespace = {
enable = true;
stages = [ "commit" ];
excludes = [ "^tests/functional/lang/" ];
};
};
}) pre-commit-hooks.lib;
};
checks = forAllSystems (system: let
@ -295,6 +350,7 @@
nixpkgsLibTests = self.hydraJobs.tests.nixpkgsLibTests.${system};
rl-next = rl-next-check "rl-next" ./doc/manual/rl-next;
rl-next-dev = rl-next-check "rl-next-dev" ./doc/manual/rl-next-dev;
pre-commit = self.hydraJobs.pre-commit.${system};
} // (lib.optionalAttrs (builtins.elem system linux64BitSystems)) {
dockerImage = self.hydraJobs.dockerImage.${system};
});
@ -340,6 +396,7 @@
busybox-sandbox-shell = pkgs.busybox-sandbox-shell or pkgs.default-busybox-sandbox;
forDevShell = true;
};
pre-commit = self.hydraJobs.pre-commit.${pkgs.system} or {};
in
(nix.override {
buildUnreleasedNotes = true;
@ -348,6 +405,7 @@
# Required for clang-tidy checks
buildInputs = prev.buildInputs
++ [ pkgs.just ]
++ lib.optional (pre-commit ? enabledPackages) pre-commit.enabledPackages
++ lib.optionals (stdenv.cc.isClang) [ pkgs.llvmPackages.llvm pkgs.llvmPackages.clang-unwrapped.dev ];
nativeBuildInputs = prev.nativeBuildInputs
++ lib.optional (stdenv.cc.isClang && !stdenv.buildPlatform.isDarwin) pkgs.buildPackages.bear
@ -379,6 +437,8 @@
# Make bash completion work.
XDG_DATA_DIRS+=:$out/share
${lib.optionalString (pre-commit ? shellHook) pre-commit.shellHook}
'';
} // lib.optionalAttrs (stdenv.buildPlatform.isLinux && pkgs.glibcLocales != null) {
# Required to make non-NixOS Linux not complain about missing locale files during configure in a dev shell

0
maintainers/build-release-notes.py Executable file → Normal file
View file

View file

@ -193,4 +193,3 @@ release:
## Recovering from mistakes
`upload-release.pl` should be idempotent. For instance a wrong `IS_LATEST` value can be fixed that way, by running the script on the actual latest release.

View file

@ -84,4 +84,3 @@ except Exception as e:
print(f'{name}: INTERNAL ERROR running test ({sys.argv}): {e}', file=sys.stderr)
print(f'this is a bug in {name}')
sys.exit(99)

View file

@ -8,5 +8,3 @@ namespace nix {
void setPersonality(std::string_view system);
}

View file

@ -152,5 +152,3 @@ void ThreadPool::doWork(bool mainThread)
}
}

0
tests/functional/ca/build-cache.sh Normal file → Executable file
View file

View file

@ -3,4 +3,3 @@ source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1
cd .. && source build-dry.sh

0
tests/functional/ca/build.sh Normal file → Executable file
View file

0
tests/functional/ca/eval-store.sh Normal file → Executable file
View file

View file

@ -3,4 +3,3 @@ source common.sh
export NIX_TESTS_CA_BY_DEFAULT=1
cd .. && source import-derivation.sh

View file

@ -5,4 +5,3 @@ source common.sh
CONTENT_ADDRESSED=true
cd ..
source ./nix-shell.sh

View file

@ -32,4 +32,3 @@ rec {
'';
};
}

View file

@ -7,5 +7,3 @@ requireDaemonNewerThan "2.4pre20210626"
export NIX_TESTS_CA_BY_DEFAULT=1
cd ..
source ./post-hook.sh

0
tests/functional/ca/substitute.sh Normal file → Executable file
View file

0
tests/functional/dyn-drv/build-built-drv.sh Normal file → Executable file
View file

0
tests/functional/dyn-drv/dep-built-drv.sh Normal file → Executable file
View file

0
tests/functional/dyn-drv/eval-outputOf.sh Normal file → Executable file
View file

0
tests/functional/dyn-drv/text-hashed-output.sh Normal file → Executable file
View file

View file

@ -147,4 +147,3 @@ expectStderr 1 nix eval -v --raw --expr "
inputAddressed = true;
}
" | grepQuiet 'error.*The store object referred to by.*fromPath.* at .* is not input-addressed, but .*inputAddressed.* is set to .*true.*'

View file

@ -47,4 +47,3 @@ nix flake update b --flake $flakeA
# Test list-inputs with circular dependencies
nix flake metadata $flakeA

View file

@ -26,4 +26,3 @@ nix run --no-write-lock-file .#pkgAsPkg
! nix run --no-write-lock-file .#appAsPkg || fail "elements of 'apps' should be of type 'app'"
clearStore

View file

@ -1 +1,3 @@
#!/usr/bin/env bash
echo Formatting: "${@}"

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
source common.sh
set +x

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
# Don't start the daemon
source common/vars-and-functions.sh

View file

@ -1,3 +1,5 @@
#!/usr/bin/env bash
source common.sh
set -o pipefail

View file

@ -27,4 +27,3 @@ mkDerivation (
normal = { };
}.${mode}
)

View file

@ -63,4 +63,3 @@ grepQuiet 'item.*attrPath="foo".*name="dependencies-top"' $TEST_ROOT/meta.xml
# Do an install.
nix-env -i dependencies-top
[ -e $TEST_HOME/.nix-profile/foobar ]

View file

@ -14,4 +14,3 @@ Commentary "the blank below should be chomped"
Command "command three"
Commentary ""
Output "meow output"
Output ""

View file

@ -14,4 +14,3 @@ the blank below should be chomped
nix-repl> command three
meow output

0
tests/functional/shell.shebang.rb Normal file → Executable file
View file

View file

@ -51,4 +51,3 @@ namespace nix {
}
}

View file

@ -30,4 +30,3 @@ namespace nix {
ASSERT_EQ(res->reference, "refs/head/main");
}
}

View file

@ -43,4 +43,3 @@ INSTANTIATE_TEST_CASE_P(
);
}