Unverified Commit 4ca52fdf authored by Robert Hensing's avatar Robert Hensing Committed by GitHub
Browse files

Merge pull request #323613 from CyberShadow/fix-nix-path-without-channels-v2

nix-channel: do not set empty nix-path when disabling channels
parents cabb09a2 2d9a6864
Loading
Loading
Loading
Loading
+49 −0
Original line number Diff line number Diff line
@@ -116,6 +116,55 @@ It has two modes:

: The `lychee` package to use.

## `shellcheck` {#tester-shellcheck}

Runs files through `shellcheck`, a static analysis tool for shell scripts.

:::{.example #ex-shellcheck}
# Run `testers.shellcheck`

A single script

```nix
testers.shellcheck {
  name = "shellcheck";
  src = ./script.sh;
}
```

Multiple files

```nix
let
  inherit (lib) fileset;
in
testers.shellcheck {
  name = "shellcheck";
  src = fileset.toSource {
    root = ./.;
    fileset = fileset.unions [
      ./lib.sh
      ./nixbsd-activate
    ];
  };
}
```

:::

### Inputs {#tester-shellcheck-inputs}

[`src` (path or string)]{#tester-shellcheck-param-src}

: The path to the shell script(s) to check.
  This can be a single file or a directory containing shell files.
  All files in `src` will be checked, so you may want to provide `fileset`-based source instead of a whole directory.

### Return value {#tester-shellcheck-return}

A derivation that runs `shellcheck` on the given script(s).
The build will fail if `shellcheck` finds any issues.

## `testVersion` {#tester-testVersion}

Checks that the output from running a command contains the specified version string in it as a whole word.
+4 −0
Original line number Diff line number Diff line
@@ -12,6 +12,7 @@ let
    mkDefault
    mkIf
    mkOption
    stringAfter
    types
    ;

@@ -97,5 +98,8 @@ in
    systemd.tmpfiles.rules = lib.mkIf cfg.channel.enable [
      ''f /root/.nix-channels - - - - ${config.system.defaultChannel} nixos\n''
    ];

    system.activationScripts.no-nix-channel = mkIf (!cfg.channel.enable)
      (stringAfter [ "etc" "users" ] (builtins.readFile ./nix-channel/activation-check.sh));
  };
}
+21 −0
Original line number Diff line number Diff line
# shellcheck shell=bash

explainChannelWarning=0
if [[ -e "/root/.nix-defexpr/channels" ]]; then
    warn '/root/.nix-defexpr/channels exists, but channels have been disabled.'
    explainChannelWarning=1
fi
if [[ -e "/nix/var/nix/profiles/per-user/root/channels" ]]; then
    warn "/nix/var/nix/profiles/per-user/root/channels exists, but channels have been disabled."
    explainChannelWarning=1
fi
while IFS=: read -r _ _ _ _ _ home _ ; do
    if [[ -n  "$home" && -e "$home/.nix-defexpr/channels" ]]; then
        warn "$home/.nix-defexpr/channels exists, but channels have been disabled." 1>&2
        explainChannelWarning=1
    fi
done < <(getent passwd)
if [[ $explainChannelWarning -eq 1 ]]; then
    echo "Due to https://github.com/NixOS/nix/issues/9574, Nix may still use these channels when NIX_PATH is unset." 1>&2
    echo "Delete the above directory or directories to prevent this." 1>&2
fi
+19 −0
Original line number Diff line number Diff line
# Run:
#   nix-build -A nixosTests.nix-channel
{ lib, testers }:
let
  inherit (lib) fileset;

  runShellcheck = testers.shellcheck {
    src = fileset.toSource {
      root = ./.;
      fileset = fileset.unions [
        ./activation-check.sh
      ];
    };
  };

in
lib.recurseIntoAttrs {
  inherit runShellcheck;
}
+2 −0
Original line number Diff line number Diff line
@@ -33,6 +33,8 @@ let
    ''
      #!${pkgs.runtimeShell}

      source ${./lib/lib.sh}

      systemConfig='@out@'

      export PATH=/empty
Loading