nix-shell can't find standard attribute - nix

I'm running nixos 19.09 and trying to follow along with the instructions for creating a ruby package. But in one of the first steps I'm getting an error that the withPackages attribute can't be found.
Command:
$ nix-shell -p "ruby.withPackages (ps: with ps; [ nokogiri pry ])" --show-trace
Result:
while evaluating the attribute 'buildInputs' of the derivation 'shell' at /nix/store/b6cqdsczmwxfkmc65483x7fgwdl129ar-nixpkgs-19.03.173684.c8db7a8a16e/nixpkgs/pkgs/build-support/trivial-builders.nix:7:14:
while evaluating 'getOutput' at /nix/store/b6cqdsczmwxfkmc65483x7fgwdl129ar-nixpkgs-19.03.173684.c8db7a8a16e/nixpkgs/lib/attrsets.nix:464:23, called from undefined position:
while evaluating anonymous function at /nix/store/b6cqdsczmwxfkmc65483x7fgwdl129ar-nixpkgs-19.03.173684.c8db7a8a16e/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:141:17, called from undefined position:
attribute 'withPackages' missing, at (string):1:94
I'm guessing that I messed up my nix store somehow, but I don't know how to debug it.
Additional Info:
$ echo $NIX_PATH
$HOME/.nix-defexpr/channels:nixpkgs=/nix/var/nix/profiles/per-user/root/channels/nixos:nixos-config=/etc/nixos/configuration.nix:/nix/var/nix/profiles/per-user/root/channels
$ nix-channel --list
nixpkgs https://nixos.org/channels/nixos-19.03
unstable https://nixos.org/channels/nixos-unstable
$ sudo nix-channel --list
<blank>

After #RobertHensing pointed out that it looked like I was on 19.03, and asked me to print out my channels, I tried just updating the channel list to point to 19.09 instead of 19.03 (with nix-channel --add) and that fixed it.

Related

How to instsall nix-linter

I've tried to install nix-linter with 3 way. None works
nix package manager
nix-env -iA nixpkgs.nix-linter
Package is marked as broken, refusing to evaluate.
It propose me several option to add broken package ( export NIXPKGS_ALLOW_BROKEN=1 ). But I don't understand exactly what will be the repercutions. I prefer not to follow this option
with cachix
I follow this tutorial
and add this line
echo "trusted-users = root myusername" | sudo tee -a /etc/nix/nix.conf && sudo pkill nix-daemon
normally after cachix use nix-linter there is a cache that nix-build use
But it doesn't work. I get an error saying that there is no default.nix in my repository
https://github.com/Synthetica9/nix-linter
cachix use nix-linter
git clone https://github.com/Synthetica9/nix-linter
cd nix-linter
$(nix-build -A nix-linter)/bin/nix-linter --help
error: attribute 'nix-linter' in selection path 'nix-linter' not found
-bash: /bin/nix-linter: No such file or directory
somebody from cacheix said that this package is no longer maintain and I should try statix.
statix works

Cardano-node nix-build error: attribute 'ff' in selection path 'scripts.ff.node' not found

Using the recommended nix build method from this guide for a cardano-node from scratch (on Debian or Ubuntu latest) running this command:
$ nix-build -A scripts.ff.node -o ff-node-local
I get the following error:
error: attribute 'ff' in selection path 'scripts.ff.node' not found
To get past that error, try using a more updated guide here, and run the following nix-build command instead:
nix-build -A scripts.mainnet.node -o mainnet-node-local

nixos-rebuild value is a function while a set was expected

Can no longer rebuild - now to debug this?
$ sudo nixos-rebuild build --show-trace
building Nix...
error: while evaluating the attribute 'config' at /nix/var/nix/profiles/per-user/root/channels/nixos/nixos/lib/eval-config.nix:64:5:
while evaluating the attribute 'config' at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:96:25:
...
user/root/channels/nixos/lib/modules.nix:195:9:
while evaluating 'addMeta' at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:173:19, called from /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:195:18:
value is a function while a set was expected, at /nix/var/nix/profiles/per-user/root/channels/nixos/lib/modules.nix:195:27
here are the channels
$ sudo nix-channel --list
nixos https://nixos.org/channels/nixos-20.03
nixos-unstable https://nixos.org/channels/nixos-unstable
nixpkgs https://nixos.org/channels/nixpkgs-unstable
and tried clearing sudo rm -rf /nix/var/nix/profiles/per-user/root/ to no effect

How to update nix language version (builtins.langVersion)?

I want to run nixpkgs test locally, I have found this manual, but it doesn't work
$ cd my/nixpkgs
$ nix-build --show-trace nixos/tests/login.nix
error: while evaluating the attribute ‘buildCommand’ of the derivation ‘vm-test-run-login’ at /home/bjorn/projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute ‘buildCommand’ of the derivation ‘nixos-test-driver-login’ at /home/bjorn/projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute ‘buildCommand’ of the derivation ‘nixos-vm’ at /home/bjorn/projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating the attribute ‘text’ of the derivation ‘run-nixos-vm’ at /home/bjorn/projects/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:148:11:
while evaluating anonymous function at /home/bjorn/projects/nixpkgs/pkgs/build-support/closure-info.nix:9:1, called from /home/bjorn/projects/nixpkgs/nixos/modules/virtualisation/qemu-vm.nix:105:13:
assertion failed at /home/bjorn/projects/nixpkgs/pkgs/build-support/closure-info.nix:11:1
because of this assert
assert builtins.langVersion >= 5;
How to update langVersion?
$ nix-repl
Welcome to Nix version 1.11.16. Type :? for help.
nix-repl> builtins.langVersion
3
nix-repl>
If you want to stay on 17.09 for a while longer, you can upgrade just Nix using this NixOS configuration:
{ pkgs, ... }: {
nix.package = pkgs.nixUnstable;
}
Otherwise you may prefer to switch to 18.03 instead of unstable. If you're going to use unstable, make sure you're using nixos-unstable, not nixpkgs-unstable. See https://nixos.wiki/wiki/Nixpkgs#Channels
Thx to David Grayson
I had to update nixos to unstable (sudo nix-channel is important)
sudo nix-channel --add https://nixos.org/channels/nixos-unstable nixos
sudo nixos-rebuild switch --upgrade
nix-instantiate --eval -E '(import <nixos> {}).lib.nixpkgsVersion'
nix-instantiate --eval -E 'builtins.langVersion'

Nix and Haskell-ng install error : attribute ‘nixpkgs’ in selection path ‘nixpkgs.haskellEnv’ not found

I am following this guide to set up nix and haskell-ng. But when I get to the step
nix-env -iA nixpkgs.haskellEnv
then I get the error:
error: attribute ‘nixpkgs’ in selection path ‘nixpkgs.haskellEnv’ not
found
Any idea what is going wrong?
The command nix-env -f "<nixpkgs>" -iA haskellEnv should work.
Citing from http://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure:
Attribute paths are deterministic inside of Nixpkgs, but the path necessary to
reach Nixpkgs varies from system to system. We dodged that problem by giving
nix-env an explicit -f "<nixpkgs>" parameter, but if you call nix-env
without that flag, then chances are the invocation fails:
$ nix-env -iA haskellPackages.cabal-install
error: attribute ‘haskellPackages’ in selection path
‘haskellPackages.cabal-install’ not found
On NixOS, for example, Nixpkgs does not exist in the top-level namespace by
default. To figure out the proper attribute path, it's easiest to query for the
path of a well-known Nixpkgs package, i.e.:
$ nix-env -qaP coreutils
nixos.coreutils coreutils-8.23
If your system responds like that (most NixOS installations will), then the
attribute path to haskellPackages is nixos.haskellPackages. Thus, if you
want to use nix-env without giving an explicit -f flag, then that's the way
to do it:
$ nix-env -qaP -A nixos.haskellPackages
$ nix-env -iA nixos.haskellPackages.cabal-install

Resources