As discussed in this question, overriding attributes of derivations, that are essential to Nix itself is more complicated than usual.
I tried to use code, provided in example, and encountered more problems. Here is my ~/.config/nixpkgs/overlays/main.nix:
_: super:
let coreutils = super.coreutils.override { aclSupport = false; };
in
{
stdenv = super.stdenv // {
overrides = self2: super2:
super.stdenv.overrides self2 super2 // {
inherit coreutils;
};
};
}
Now when I try to install my version of coreutils with nix-env -iA nixpkgs.coreutils --show-trace, I get following error:
replacing old 'coreutils-8.31'
installing 'coreutils-8.31'
error: while evaluating the attribute 'buildInputs' of the derivation 'coreutils-8.31' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:191:11:
while evaluating the attribute 'builder' of the derivation 'gmp-6.1.2' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/libraries/gmp/6.x.nix:9:3:
while evaluating the attribute 'shell' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/default.nix:103:14:
while evaluating the attribute 'gcc' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/linux/default.nix:290:7:
while evaluating 'makeOverridable' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:67:24, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/linux/default.nix:290:13:
while evaluating anonymous function at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:69:16:
while evaluating the attribute 'gcc-unwrapped' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/linux/default.nix:258:7:
while evaluating the attribute 'gcc-unwrapped.override' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:7666:3:
while evaluating 'addMetaAttrs' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/meta.nix:15:28, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:7825:10:
while evaluating 'wrapCC' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:8688:12, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:7825:19:
while evaluating 'wrapCCWith' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:8667:5, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:8688:16:
while evaluating 'callPackageWith' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:117:35, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/top-level/all-packages.nix:8676:7:
while evaluating 'makeOverridable' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:67:24, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:121:8:
while evaluating anonymous function at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:69:16:
while evaluating the attribute 'cc.nativeTools' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/default.nix:148:14:
while evaluating 'makeOverridable' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:67:24, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/linux/default.nix:101:19:
while evaluating anonymous function at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:8:1, called from /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/lib/customisation.nix:69:16:
while evaluating the attribute 'buildInputs' of the derivation 'glibc-2.27' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/libraries/glibc/common.nix:167:3:
while evaluating the attribute 'depsBuildBuild' of the derivation 'linux-headers-4.19.16' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:191:11:
while evaluating the attribute 'bintools' of the derivation 'bootstrap-stage2-gcc-wrapper' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:96:3:
while evaluating the attribute 'bintools_bin' of the derivation 'binutils-wrapper-2.31.1' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix:76:3:
while evaluating the attribute 'buildInputs' of the derivation 'binutils-2.31.1' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/tools/misc/binutils/default.nix:26:3:
while evaluating the attribute 'stdenv' of the derivation 'zlib-1.2.11' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/libraries/zlib/default.nix:18:3:
while evaluating the attribute 'defaultNativeBuildInputs' of the derivation 'bootstrap-stage1-stdenv-linux' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/default.nix:73:14:
while evaluating the attribute 'bintools' of the derivation 'bootstrap-stage1-gcc-wrapper' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/cc-wrapper/default.nix:96:3:
while evaluating the attribute 'coreutils_bin' of the derivation 'bootstrap-stage0-binutils-wrapper' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/build-support/bintools-wrapper/default.nix:76:3:
while evaluating the attribute 'buildInputs' of the derivation 'coreutils-8.31' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:191:11:
while evaluating the attribute 'nativeBuildInputs' of the derivation 'attr-2.4.48' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/libraries/attr/default.nix:4:3:
while evaluating the attribute 'nativeBuildInputs' of the derivation 'gettext-0.19.8.1' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:191:11:
while evaluating the attribute 'nativeBuildInputs' of the derivation 'bison-3.4.2' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/stdenv/generic/make-derivation.nix:191:11:
while evaluating the attribute 'postInstall' of the derivation 'perl-5.30.0' at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/interpreters/perl/default.nix:29:5:
cannot coerce null to a string, at /nix/store/dmdqvlxfk7c5gj4jg8iv77d8bmyk3c12-nixpkgs-20.03pre199995.895874d2145/nixpkgs/pkgs/development/interpreters/perl/default.nix:128:7
I fail to understand what is going on, this null-coercion happens somewhere in postInstall. Okay, I try to override perl too:
_: super:
let coreutils = super.coreutils.override { aclSupport = false; };
in
{
stdenv = super.stdenv // {
overrides = self2: super2:
super.stdenv.overrides self2 super2 // {
inherit coreutils;
perl = super.perl.overrideAttrs (_: { postInstall = ""; });
};
};
}
Now, attempt to install coreutils triggers rebuild of perl (of course), which fails with error about missing C compiler:
./UU/checkcc: line 10: cc: command not found
And here I am stuck. So, how to override coreutils?
Well I think setting's perls postInstall to "" is the cause of your error. I would ignore that and go back to the very first error. And then look up the nix file at that error's position.
You'll need to clone down nixpkgs, checkout the same commit you're on, and inspect the file which looks something like:
https://github.com/NixOS/nixpkgs/blob/bc77ec7e560672ff9f8a5b5e60f228818d230d4b/pkgs/development/interpreters/perl/default.nix#L127
postInstall =
''
# Remove dependency between "out" and "man" outputs.
rm "$out"/lib/perl5/*/*/.packlist
# Remove dependencies on glibc and gcc
sed "/ *libpth =>/c libpth => ' '," \
-i "$out"/lib/perl5/*/*/Config.pm
Related
I have this method in a class that's throwing a Cannot bind attributes in a Nil type object. Did you forget a '.new'?
method parse() {
grammar FindHeaders {
token TOP { [<not-header> | <header>]+ $ }
token not-header { ^^ <![#]> \N* \n }
token header { ^^ '#'{ 1 .. 6 } <content> \n }
token content { \N+ }
}
class HeaderActions {
method content($match) {
return if $match ~~ m/^^\#\s+<[A..Z]>+e*s/ || $match !~~ m/<[a..z]>/;
return if $match ~~ m/\|/ && ( $match ~~ m:i/project/ || $match ~~ m:i/\+\w/ );
my $tc = Lingua::EN::Titlecase.new($match);
my $new_title = $tc.title;
make($new_title);
}
}
my $t = $!content;
FindHeaders.parse($t, actions => HeaderActions.new);
}
As far as I can tell, this code matches what's in the official documentation. So not sure why I'm getting this error. I have no idea what attribute or Nil object the compiler is referring to. If I comment out the line with the make method, everything works fine.
method content($match) {
There's a reason that action methods typically use $/ as the argument name: because the make function looks for $/ in order to associate the provided object to it. You can use $match, but then need to call the make method on that instead:
$match.make($new_title);
The mention of Nil is because the failed match earlier in the action method resulted in $/ being set to Nil.
I guess you avoided the more idiomatic $/ as the parameter of the action method because it gets in the way of doing further matching in the action method. Doing further matching in action methods means that the text is being parsed twice (once in the grammar and again the action), which is not so efficient, and usually best avoided (by moving the parsing work into the grammar).
As a final style point, declaring grammars and action classes in a method is neat encapsulation if they are only used there, but it would be wise to my scope them (my grammar FindHeaders { ... }), otherwise they shall end up installed in the nearest enclosing package anyway.
Err - bit of a guess here but looks like this error is generated during creation of a new object. That points to the line my $tc = Lingua::EN::Titlecase.new($match). I wonder if you want to pass a Str into this function call e.g. with "$match" or ~$match...
In the context of a Flutter 2.0.5 app whose state I'd like to manage with Riverpod, I thought I can declare a StateNotifierProvider like this:
import 'package:flutter_riverpod/flutter_riverpod.dart';
final counterProvider = StateNotifierProvider<CounterStateNotifier>((ref) => CounterStateNotifier());
class CounterStateNotifier extends StateNotifier<int> {
CounterStateNotifier([int count = 0]) : super(count);
void increment() => state++;
}
But Android Studio (and later the Dart compiler as well) complains about the line where I declare the counterProvider variable:
The type 'StateNotifierProvider' is declared with 2 type parameters, but 1 type arguments were given.
Removing the <CounterStateNotifier> type parameter in StateNotifierProvider<CounterStateNotifier> removes the error. However, attempting to read the provider and call its increment method (setting () => context.read(counterProvider).increment() as the onPressed of an ElevatedButton, then pressing the button) gives the following runtime error:
'increment'
method not found
Receiver: 0
Arguments: []
Why is context.read(counterProvider) returning the int state instead of the notifier? And what is the reason behind the type parameter error mentioned in the first part of my question?
I should mention that I'm running my app on the web (with flutter run -d Chrome).
As of Riverpod 0.14.0, State is the default value exposed by StateNotifierProvider.
The syntax for declaring your StateNotifierProvider is now as follows:
final counterProvider = StateNotifierProvider<CounterStateNotifier, int>((ref) => CounterStateNotifier());
Accessing functions now requires adding .notifier (accessing the StateNotifier itself):
context.read(counterProvider.notifier).increment();
And like you've noticed, you now access the state like so:
final count = context.read(counterProvider);
More on the changes here.
You may also use dynamic to accept any type if value for the StateNotifierProvider
final modelProvider =
StateNotifierProvider.autoDispose<ModelClassName, dynamic>(
(ref) => ModelClassName());
i have regExp in constants:
export const Constants = {
QUERY_PARAM_CONFIG: {
REGEX: /\+/gi,
REGEX_ENCODED: /%2B/g
}
};
but when i run ng build i get an error:
ERROR in app\app.module.ts(58,21): Error during template compile of 'AppModule'
Expression form not supported in 'Constants'
'Constants' contains the error at app\configuration\constants.ts.
npm build script:
ng build --prod --output-hashing none --sourcemaps=true
any ideas?
The regex literals are not supported by AOT. See the list of supported syntax.
In order to make it work transform your regex to something supported e.g. string:
const before = /\+/gi, // before, could be the same as below
const after = { re: '\\+', flags: 'gi' }
const canBeUsedAs = new RegExp(after.re, after.flags);
By this you can still pass the meaning of the RegExp and create one on the fly whenever you need them in the runtime
I'm new to declarative pipeline and exploring its features. I tried to use regex. The following example is the result of trial and error. Is there a nicer solution out there? I'm looking for a new shiny declarative pipeline way, if there is any.
What I do not get is, why do I have to use the script{}-Enviroment and why do I have to use a local variable (def matcherX)?
working example followed by first attemts:
Working Example:
pipeline {
environment {
dummyText = 'aaa123aaa'
transfare = ''
}
agent any
stages {
stage('regex') {
steps{
script{
def matcherX = dummyText =~ /(\d+)/
transfare = matcherX[0][0]
echo transfare // results in 123
}
}
}
}
}
Error: without a script{}
/*
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
WorkflowScript: 11: Expected a step # line 11, column 21.
def matcherX = dummyText =~ /(\d+)/
^
WorkflowScript: 12: Expected a step # line 12, column 21.
transfare = matcherX[0][0]
*/
Error: with script but with a global variable
//script{
// transfare = dummyText =~ /(\d+)/
/*
// No line displayed where error occured???
an exception which occurred:
in field org.jenkinsci.plugins.pipeline.modeldefinition.withscript.WithScriptScript.script
in object org.jenkinsci.plugins.pipeline.modeldefinition.agent.impl.LabelScript#192ebed
in field groovy.lang.Closure.delegate
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2#31fd6bc8
in field groovy.lang.Closure.delegate
in object org.jenkinsci.plugins.workflow.cps.CpsClosure2#609aa9b5
in field org.jenkinsci.plugins.workflow.cps.CpsThreadGroup.closures
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup#3e51c1c3
in object org.jenkinsci.plugins.workflow.cps.CpsThreadGroup#3e51c1c3
Caused: java.io.NotSerializableException: java.util.regex.Matcher
at org.jboss.marshalling.river.RiverMarshaller.doWriteObject(RiverMarshaller.java:860)
at org.jboss.marshalling.river.BlockMarshaller.doWriteObject(BlockMarshaller.java:65)
at org.jboss.marshalling.river.BlockMarshaller.writeObject(BlockMarshaller.java:56)
*/
The script block indicates departure from the pure declarative syntax. Ideally builds (just as any other process) could take advantage of a pure declarative syntax to avoid implicit dependencies between steps.
The global variable of a matcher type fails to serialize which is needed to pass it between the Jenkins master and the slave (I guess).
I'm trying to create a spec test for the following recipe code:
if node.attribute?(node['tested_cookbook']['some_attribute'])
include_recipe('tested_cookbook::first')
else
include_recipe('tested_cookbook::second')
I have the following spec for this:
require 'spec_helper'
describe 'tested_cookbook::default' do
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2008R2') do |node|
node.set['tested_cookbook']['some_attribute'] = "some_value"
end.converge(described_recipe) }
it 'includes recipe iis' do
expect(chef_run).to include_recipe('tested_cookbook::first')
end
end
The problem is that this test will always fail.
How do I properly mock the outcome of 'node.attribute?' ?
Thank you.
I'm not sure you can override the node object in Chefspec without monkey patching, which I think is probably more trouble than it's worth. I really almost never even see node.attribute? used, so it may be somewhat of an anti-pattern. (Do you really care if it was set, vs. if it has a non-nil value or not?)
I would just avoid using attribute? in the first place, e.g.
Recipe:
if node['tested_cookbook'] && node['tested_cookbook']['some_attribute'])
include_recipe('tested_cookbook::first')
else
include_recipe('tested_cookbook::second')
end
Spec:
require 'spec_helper'
describe 'tested_cookbook::default' do
let(:chef_run) { ChefSpec::SoloRunner.new(platform: 'windows', version: '2008R2') do |node|
node.set['tested_cookbook']['some_attribute'] = "some_value"
end.converge(described_recipe) }
it 'includes recipe iis' do
expect(chef_run).to include_recipe('tested_cookbook::first')
end
end
It's common practice to give these attributes a default value, too, so it would be even more idiomatic to say:
attributes/default.rb:
default['tested_cookbook']['some_attribute'] = 'second'
recipe:
include_recipe "tested_cookbook::#{node['tested_cookbook']['some_attribute']}"
And then in your spec, do the same check as before. You're using an attribute to run ::second, but allowing someone to override it to ::first. If you don't like the pattern of actually using the attribute value to include, you could make it a flag and keep your previous if-statement too.