mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-30 01:26:15 +02:00
Merge pull request #8073 from tweag/fix-root-channels-location
Fix root channels location
This commit is contained in:
commit
1d539aa287
7 changed files with 83 additions and 18 deletions
8
.github/workflows/ci.yml
vendored
8
.github/workflows/ci.yml
vendored
|
@ -58,7 +58,7 @@ jobs:
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
||||||
- uses: cachix/install-nix-action@v19
|
- uses: cachix/install-nix-action@v20
|
||||||
with:
|
with:
|
||||||
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
|
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
|
||||||
- uses: cachix/cachix-action@v12
|
- uses: cachix/cachix-action@v12
|
||||||
|
@ -79,7 +79,7 @@ jobs:
|
||||||
steps:
|
steps:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
||||||
- uses: cachix/install-nix-action@v19
|
- uses: cachix/install-nix-action@v20
|
||||||
with:
|
with:
|
||||||
install_url: '${{needs.installer.outputs.installerURL}}'
|
install_url: '${{needs.installer.outputs.installerURL}}'
|
||||||
install_options: "--tarball-url-prefix https://${{ env.CACHIX_NAME }}.cachix.org/serve"
|
install_options: "--tarball-url-prefix https://${{ env.CACHIX_NAME }}.cachix.org/serve"
|
||||||
|
@ -91,6 +91,8 @@ jobs:
|
||||||
- run: exec sh -c "nix-instantiate -E 'builtins.currentTime' --eval"
|
- run: exec sh -c "nix-instantiate -E 'builtins.currentTime' --eval"
|
||||||
- run: exec zsh -c "nix-instantiate -E 'builtins.currentTime' --eval"
|
- run: exec zsh -c "nix-instantiate -E 'builtins.currentTime' --eval"
|
||||||
- run: exec fish -c "nix-instantiate -E 'builtins.currentTime' --eval"
|
- run: exec fish -c "nix-instantiate -E 'builtins.currentTime' --eval"
|
||||||
|
- run: exec bash -c "nix-channel --add https://releases.nixos.org/nixos/unstable/nixos-23.05pre466020.60c1d71f2ba nixpkgs"
|
||||||
|
- run: exec bash -c "nix-channel --update && nix-env -iA nixpkgs.hello && hello"
|
||||||
|
|
||||||
docker_push_image:
|
docker_push_image:
|
||||||
needs: [check_secrets, tests]
|
needs: [check_secrets, tests]
|
||||||
|
@ -104,7 +106,7 @@ jobs:
|
||||||
- uses: actions/checkout@v3
|
- uses: actions/checkout@v3
|
||||||
with:
|
with:
|
||||||
fetch-depth: 0
|
fetch-depth: 0
|
||||||
- uses: cachix/install-nix-action@v19
|
- uses: cachix/install-nix-action@v20
|
||||||
with:
|
with:
|
||||||
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
|
install_url: https://releases.nixos.org/nix/nix-2.13.3/install
|
||||||
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
- run: echo CACHIX_NAME="$(echo $GITHUB_REPOSITORY-install-tests | tr "[A-Z]/" "[a-z]-")" >> $GITHUB_ENV
|
||||||
|
|
|
@ -8,6 +8,7 @@
|
||||||
#include "eval-inline.hh"
|
#include "eval-inline.hh"
|
||||||
#include "filetransfer.hh"
|
#include "filetransfer.hh"
|
||||||
#include "function-trace.hh"
|
#include "function-trace.hh"
|
||||||
|
#include "profiles.hh"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
|
@ -2491,8 +2492,8 @@ Strings EvalSettings::getDefaultNixPath()
|
||||||
|
|
||||||
if (!evalSettings.restrictEval && !evalSettings.pureEval) {
|
if (!evalSettings.restrictEval && !evalSettings.pureEval) {
|
||||||
add(settings.useXDGBaseDirectories ? getStateDir() + "/nix/defexpr/channels" : getHome() + "/.nix-defexpr/channels");
|
add(settings.useXDGBaseDirectories ? getStateDir() + "/nix/defexpr/channels" : getHome() + "/.nix-defexpr/channels");
|
||||||
add(settings.nixStateDir + "/profiles/per-user/root/channels/nixpkgs", "nixpkgs");
|
add(rootChannelsDir() + "/nixpkgs", "nixpkgs");
|
||||||
add(settings.nixStateDir + "/profiles/per-user/root/channels");
|
add(rootChannelsDir());
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
|
|
|
@ -282,28 +282,48 @@ std::string optimisticLockProfile(const Path & profile)
|
||||||
|
|
||||||
Path profilesDir()
|
Path profilesDir()
|
||||||
{
|
{
|
||||||
auto profileRoot = createNixStateDir() + "/profiles";
|
auto profileRoot =
|
||||||
|
(getuid() == 0)
|
||||||
|
? rootProfilesDir()
|
||||||
|
: createNixStateDir() + "/profiles";
|
||||||
createDirs(profileRoot);
|
createDirs(profileRoot);
|
||||||
return profileRoot;
|
return profileRoot;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path rootProfilesDir()
|
||||||
|
{
|
||||||
|
return settings.nixStateDir + "/profiles/per-user/root";
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
Path getDefaultProfile()
|
Path getDefaultProfile()
|
||||||
{
|
{
|
||||||
Path profileLink = settings.useXDGBaseDirectories ? createNixStateDir() + "/profile" : getHome() + "/.nix-profile";
|
Path profileLink = settings.useXDGBaseDirectories ? createNixStateDir() + "/profile" : getHome() + "/.nix-profile";
|
||||||
try {
|
try {
|
||||||
auto profile =
|
auto profile = profilesDir() + "/profile";
|
||||||
getuid() == 0
|
|
||||||
? settings.nixStateDir + "/profiles/default"
|
|
||||||
: profilesDir() + "/profile";
|
|
||||||
if (!pathExists(profileLink)) {
|
if (!pathExists(profileLink)) {
|
||||||
replaceSymlink(profile, profileLink);
|
replaceSymlink(profile, profileLink);
|
||||||
}
|
}
|
||||||
|
// Backwards compatibiliy measure: Make root's profile available as
|
||||||
|
// `.../default` as it's what NixOS and most of the init scripts expect
|
||||||
|
Path globalProfileLink = settings.nixStateDir + "/profiles/default";
|
||||||
|
if (getuid() == 0 && !pathExists(globalProfileLink)) {
|
||||||
|
replaceSymlink(profile, globalProfileLink);
|
||||||
|
}
|
||||||
return absPath(readLink(profileLink), dirOf(profileLink));
|
return absPath(readLink(profileLink), dirOf(profileLink));
|
||||||
} catch (Error &) {
|
} catch (Error &) {
|
||||||
return profileLink;
|
return profileLink;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Path defaultChannelsDir()
|
||||||
|
{
|
||||||
|
return profilesDir() + "/channels";
|
||||||
|
}
|
||||||
|
|
||||||
|
Path rootChannelsDir()
|
||||||
|
{
|
||||||
|
return rootProfilesDir() + "/channels";
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -68,13 +68,32 @@ void lockProfile(PathLocks & lock, const Path & profile);
|
||||||
rebuilt. */
|
rebuilt. */
|
||||||
std::string optimisticLockProfile(const Path & profile);
|
std::string optimisticLockProfile(const Path & profile);
|
||||||
|
|
||||||
/* Creates and returns the path to a directory suitable for storing the user’s
|
/**
|
||||||
profiles. */
|
* Create and return the path to a directory suitable for storing the user’s
|
||||||
|
* profiles.
|
||||||
|
*/
|
||||||
Path profilesDir();
|
Path profilesDir();
|
||||||
|
|
||||||
/* Resolve the default profile (~/.nix-profile by default, $XDG_STATE_HOME/
|
/**
|
||||||
nix/profile if XDG Base Directory Support is enabled), and create if doesn't
|
* Return the path to the profile directory for root (but don't try creating it)
|
||||||
exist */
|
*/
|
||||||
|
Path rootProfilesDir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Create and return the path to the file used for storing the users's channels
|
||||||
|
*/
|
||||||
|
Path defaultChannelsDir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Return the path to the channel directory for root (but don't try creating it)
|
||||||
|
*/
|
||||||
|
Path rootChannelsDir();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Resolve the default profile (~/.nix-profile by default,
|
||||||
|
* $XDG_STATE_HOME/nix/profile if XDG Base Directory Support is enabled),
|
||||||
|
* and create if doesn't exist
|
||||||
|
*/
|
||||||
Path getDefaultProfile();
|
Path getDefaultProfile();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -169,6 +169,7 @@ static int main_nix_channel(int argc, char ** argv)
|
||||||
|
|
||||||
// Figure out the name of the channels profile.
|
// Figure out the name of the channels profile.
|
||||||
profile = profilesDir() + "/channels";
|
profile = profilesDir() + "/channels";
|
||||||
|
createDirs(dirOf(profile));
|
||||||
|
|
||||||
enum {
|
enum {
|
||||||
cNone,
|
cNone,
|
||||||
|
|
|
@ -1403,11 +1403,11 @@ static int main_nix_env(int argc, char * * argv)
|
||||||
try {
|
try {
|
||||||
createDirs(globals.instSource.nixExprPath);
|
createDirs(globals.instSource.nixExprPath);
|
||||||
replaceSymlink(
|
replaceSymlink(
|
||||||
fmt("%s/profiles/per-user/%s/channels", settings.nixStateDir, getUserName()),
|
defaultChannelsDir(),
|
||||||
globals.instSource.nixExprPath + "/channels");
|
globals.instSource.nixExprPath + "/channels");
|
||||||
if (getuid() != 0)
|
if (getuid() != 0)
|
||||||
replaceSymlink(
|
replaceSymlink(
|
||||||
fmt("%s/profiles/per-user/root/channels", settings.nixStateDir),
|
rootChannelsDir(),
|
||||||
globals.instSource.nixExprPath + "/channels_root");
|
globals.instSource.nixExprPath + "/channels_root");
|
||||||
} catch (Error &) { }
|
} catch (Error &) { }
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,14 @@ let
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
mockChannel = pkgs:
|
||||||
|
pkgs.runCommandNoCC "mock-channel" {} ''
|
||||||
|
mkdir nixexprs
|
||||||
|
mkdir $out
|
||||||
|
echo -n 'someContent' > nixexprs/someFile
|
||||||
|
tar cvf - nixexprs | bzip2 > $out/nixexprs.tar.bz2
|
||||||
|
'';
|
||||||
|
|
||||||
disableSELinux = "sudo setenforce 0";
|
disableSELinux = "sudo setenforce 0";
|
||||||
|
|
||||||
images = {
|
images = {
|
||||||
|
@ -189,6 +197,9 @@ let
|
||||||
echo "Running installer..."
|
echo "Running installer..."
|
||||||
$ssh "set -eux; $installScript"
|
$ssh "set -eux; $installScript"
|
||||||
|
|
||||||
|
echo "Copying the mock channel"
|
||||||
|
scp -r -P 20022 $ssh_opts ${mockChannel pkgs} vagrant@localhost:channel
|
||||||
|
|
||||||
echo "Testing Nix installation..."
|
echo "Testing Nix installation..."
|
||||||
$ssh <<EOF
|
$ssh <<EOF
|
||||||
set -ex
|
set -ex
|
||||||
|
@ -204,6 +215,17 @@ let
|
||||||
|
|
||||||
out=\$(nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > \$out"]; }')
|
out=\$(nix-build --no-substitute -E 'derivation { name = "foo"; system = "x86_64-linux"; builder = "/bin/sh"; args = ["-c" "echo foobar > \$out"]; }')
|
||||||
[[ \$(cat \$out) = foobar ]]
|
[[ \$(cat \$out) = foobar ]]
|
||||||
|
|
||||||
|
if pgrep nix-daemon; then
|
||||||
|
MAYBESUDO="sudo"
|
||||||
|
else
|
||||||
|
MAYBESUDO=""
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
$MAYBESUDO \$(which nix-channel) --add file://\$HOME/channel myChannel
|
||||||
|
$MAYBESUDO \$(which nix-channel) --update
|
||||||
|
[[ \$(nix-instantiate --eval --expr 'builtins.readFile <myChannel/someFile>') = '"someContent"' ]]
|
||||||
EOF
|
EOF
|
||||||
|
|
||||||
echo "Done!"
|
echo "Done!"
|
||||||
|
|
Loading…
Reference in a new issue