Cannot blacklist unfreeRedistributableFirmware - nixos

I want to blacklist unfreeRedistributableFirmware license because despite being nonfree, NixOS currently doesn't treat it as such. So I add this to my configuration.nix.
boot = {
kernelPackages = pkgs.linuxPackages_latest-libre;
...
}
nixpkgs.config = {
allowBroken = true;
blacklistedLicenses = with lib.licenses; [
unfreeRedistributableFirmware
];
...
};
However, I keep getting firmware-linux-nonfree error after running nixox-rebuild even though I declare Linux-libre kernel.
error: Package ‘firmware-linux-nonfree-2021-07-16’ in /nix/store/c84snp1irc764vsr81dcv61qrq78wdnv-nixos-21.05.2734.74d017edb67/nixos/pkgs/os-specific/linux/firmware/firmware-linux-nonfree/default.nix:23 has a blocklisted license (‘unfreeRedistributableFirmware’), refusing to evaluate.
Any tip or workaround will be appreciated.

The culprit is this imported module in /etc/nixos/hardware-configuration.nix
imports = [ (modulesPath + "/installer/scan/not-detected.nix") ];
This module contains hardware.enableRedistributableFirmware = lib.mkDefault true;. I just comment it out and all the non-free firmware are gone.
But that file can be overwritten by nixos-generate-config so it is better to declare hardware.enableRedistributableFirmware = false; in configuration.nix instead.

Related

What language this file is written?

I am trying to understand in what language this file is written in? I would like to know but here authors did not specify the language.
https://github.com/status-im/status-react/blob/develop/nix/status-go/default.nix
{ lib, callPackage, mkShell, openjdk, androidPkgs }:
let
inherit (lib)
catAttrs concatStrings concatStringsSep fileContents makeBinPath
getConfig optional attrValues mapAttrs attrByPath;
# Metadata common to all builds of status-go
meta = {
description = "The Status Go module that consumes go-ethereum.";
license = lib.licenses.mpl20;
platforms = with lib.platforms; linux ++ darwin;
};
# Source can be changed with a local override from config
source = callPackage ./source.nix { };
# Params to be set at build time, important for About section and metrics
goBuildParams = {
GitCommit = source.rev;
Version = source.cleanVersion;
};
# These are necessary for status-go to show correct version
paramsLdFlags = attrValues (mapAttrs (name: value:
"-X github.com/status-im/status-go/params.${name}=${value}"
) goBuildParams);
goBuildLdFlags = paramsLdFlags ++ [
"-s" # -s disabled symbol table
"-w" # -w disables DWARF debugging information
];
goBuildFlags = [ "-v" ];
in rec {
mobile = callPackage ./mobile {
inherit meta source goBuildFlags goBuildLdFlags;
};
shell = mkShell {
inputsFrom = [ mobile.android mobile.ios ];
};
}
It the Nix expression language.

How to get use `callCabal2nix` to supply package list to 'ghcWithPackages'?

I have a list of ~46 dependencies.
I produce a shell using among other things a call to:
server = pkgs.haskellPackages.callCabal2nix "server" ./server.cabal { };
within an override of pkgs.haskellPackages that goes into pkgs.myHaskellPackages.
The shell works fine. However, I have another nix for building a docker and this requires a build input that comes from:
ghc = pkgs.myHaskellPackages.ghcWithPackages (p: [ longlistofdependencies ]);
How do I specify the long list of dependencies without having to write them out manually, defeating the purpose of using callCabal2nix in the first place.
let
bootstrap = import <nixpkgs> { };
nixpkgs = builtins.fromJSON (builtins.readFile ./nixpkgs-unstable.json);
src = bootstrap.fetchFromGitHub {
owner = "NixOS";
repo = "nixpkgs";
inherit (nixpkgs) rev sha256;
};
config = {
allowBroken = true;
packageOverrides = pkgs: rec {
servantSrc = pkgs.fetchFromGitHub {
owner = "haskell-servant";
repo = "servant";
rev = "73c87bc2bc0685649f2337b06ab4fdc66c4ce1dd";
sha256 = "0sw4mrncmfna30cyxrvinc1krqhfxn5dcc1ggzqfy39s0yl9q98r";
#sha256 = "0000000000000000000000000000000000000000000000000000";
} + "/servant";
myHaskellPackages = pkgs.haskellPackages.override {
overrides = haskellPackagesNew: haskellPackagesOld: rec {
server =
haskellPackagesNew.callCabal2nix "server" ./server.cabal { };
servant =
haskellPackagesNew.callCabal2nix "servant" servantSrc {};
# several other overridden packages
};
};
};
};
pkgs = import src { inherit config; };
devShell = pkgs.myHaskellPackages.shellFor {
packages = p: [
p.server
];
buildInputs = with pkgs.haskellPackages; [
hlint
brittany
haskell-language-server
];
};
# Every time a dependency changes in the cabal file, this has to be edited as well.
ghc = pkgs.myHaskellPackages.ghcWithPackages (p: [
p.aeson p.aeson-qq p.base p.blaze-html p.bytestring p.cache p.containers
p.contravariant-extras p.criterion p.either p.hashable p.hasql
p.hasql-migration p.hasql-pool p.hasql-th p.hasql-transaction p.hspec
p.http-client p.http-conduit p.http-types p.immortal-queue p.lens p.linear
p.monad-logger p.mtl p.pqueue p.pretty-simple p.QuickCheck p.raw-strings-qq
p.servant-blaze p.servant-docs p.servant-server
p.string-interpolate p.text p.text-format p.time p.tuple p.unordered-containers
p.utf8-string p.vector p.vector-split p.wai p.wai-cors p.warp p.xlsx p.yaml
]);
in {
inherit devShell;
inherit ghc;
inherit pkgs;
}
The ghc output is used in docker.nix as a build input:
let
inherit (import ./pinned-nixpkgs.nix) ghc pkgs;
pricing-server =
pkgs.stdenv.mkDerivation {
name = "my-server";
pname = "my-server";
version = "1.1.0";
src = ./.;
buildPhase = ''
ghc -O2 --make -outputdir ./tmp2 Main.hs
'';
installPhase = ''
mkdir -p $out/bin
cp Main $out/bin
cp -r ./sql $out/bin
'';
buildInputs = [ ghc ];
};
in
dockerTools.buildImage {
# irrelevant to the question.
}
A possible solution is pkgs.myHaskellPackages.server.getBuildInputs.haskellBuildInputs, or pkgs.myHaskellPackages.server.getCabalDeps.libraryHaskellDepends.
You can explore these attributes, or any expression, with nix repl. You may have to expose some values from your let bindings though. In this case I just browsed through haskellPackages.warp in nix repl <nixpkgs>.
I also noticed you use rec in an overlay. This will work for you until it doesn't. I'd recommend to remove rec to avoid accessing attributes in a third way and use the more standard haskellPackagesNew.servant instead.

How can I make this Haskell development environment in Nix?

I'm trying to make a Haskell development environment for a web project that just has the dependencies hakyll, blaze, and clay. Only, clay appears to fail to build, complaining that Setup: Encountered missing dependencies:
hspec >=2.2.0 && <2.6, hspec-discover >=2.2.0 && <2.6, and I can't seem to get past this.
I tried running cabal2nix . --shell > shell.nix on this cabal file:
name: open-editions
version: 0.1.0.0
build-type: Simple
cabal-version: >= 1.10
executable site
main-is: site.hs
build-depends: base == 4.*
, blaze-html
, clay
, hakyll == 4.12.*
ghc-options: -threaded
default-language: Haskell2010
But I'm running into the missing dependencies problem. Any ideas?
Edit: here's the shell.nix that I'm generating from the above, using cabal2nix:
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
let
inherit (nixpkgs) pkgs;
f = { mkDerivation, base, blaze-html, clay, hakyll, stdenv }:
mkDerivation {
pname = "open-editions";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ base blaze-html clay hakyll ];
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (haskellPackages.callPackage f {});
in
if pkgs.lib.inNixShell then drv.env else drv
And here's how I've been trying to modify it, so that it overrides Clay:
{ haskellLib, super, nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
let
inherit (nixpkgs) pkgs;
clay = haskellLib.doJailbreak super.clay;
f = { mkDerivation, base, blaze-html, clay, hakyll, stdenv }:
mkDerivation {
pname = "open-editions";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
executableHaskellDepends = [ base blaze-html clay hakyll ];
license = "unknown";
hydraPlatforms = stdenv.lib.platforms.none;
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (haskellPackages.callPackage f {});
in
if pkgs.lib.inNixShell then drv.env else drv
But I'm obviously doing something wrong, since I'm getting: error: cannot auto-call a function that has an argument without a default value ('haskellLib').
This is typically caused by a package pinning an old version of dependency, not available in nixpkgs. Peter is correct that clay needs to bump the hspec version.
However, you can try to temporarily fix it by jailbreaking the package (removing the version bounds) in nixpkgs, see:
https://github.com/NixOS/nixpkgs/blob/cc98350d55522ebb2b7d35db32bc7c2fc5b8b273/pkgs/development/haskell-modules/configuration-common.nix#L1088-L1089
In case the package does not build with newer version of hspec, you could try to add the old version to the package set and override the package to use it:
https://github.com/NixOS/nixpkgs/blob/cc98350d55522ebb2b7d35db32bc7c2fc5b8b273/pkgs/development/haskell-modules/configuration-common.nix#L1170
But that would require require re-generating hackage-packages.nix so I do not recommend it.
It is better idea to patch the package to support newer version of the dependency and add the patch to overrides:
https://github.com/NixOS/nixpkgs/blob/cc98350d55522ebb2b7d35db32bc7c2fc5b8b273/pkgs/development/haskell-modules/configuration-common.nix#L1187-L1190
Also do not forget to open an issue upstream – I see you already did – or a pull request.
It's probably not really relevant anymore, but I encountered the same problem with clay.
I use an overlay to modify the (Haskell) package set. It looks like this (called overlays.nix):
let
customHaskellPackages = self: super: {
haskellPackages = super.haskellPackages.override {
overrides = hself: hsuper: {
# Since clay is not really maintained any longer, the upper
# version bounds have gone stale.
# Everything works fine; we just need to free it from its
# too-tight chains.
clay =
super.haskell.lib.doJailbreak
hsuper.clay;
# Other packages would go here, too
some-foo-package =
super.haskell.lib.dontCheck
(hself.callPackage ./some-foo-package.nix {});
};
};
};
in
[ customHaskellPackages ]
My default.nix is created by cabal2nix . > default.nix from my cabal file, which in turn just specifies clay as a dependency.
In a (very simplified) release.nix file you can use the overlay as follows:
let
overlays = import ./nix/overlays.nix;
# I might have needed this for clay, but it might have been sth else
config = { allowBroken = true; };
pkgs = import <nixpkgs> { inherit config; inherit overlays; };
in
pkgs.haskellPackage.myApplication
# Or use haskellPackages.callPackage ./something.nix {} here if you didn't
# add your project to haskellPackages in the overlay
After that, nix-build release.nix works just fine.
I don't use the --shell option to create a shell.nix file, but create it myself and import the release.nix file. Then I enrich my shell environment by adding in a couple of build tools. This works as expected as well.

How to write a shell.nix file which combines other nix-shell environments?

I want to write a shell.nix file that will provide me a development environment which includes developer tools + haskell dependencies. I would like to keep my nix expressions separate - for now that means one file containing information about my editor, and one file containing information about my haskell project.
I have tried to set up a really basic environment, but can't get it to work. I have two files which I can create a nix-shell from already:
# my-haskell-shell.nix - generated by cabal2nix --shell
{ nixpkgs ? import <nixpkgs> {}, compiler ? "default", doBenchmark ? false }:
let
inherit (nixpkgs) pkgs;
f = { mkDerivation, base, cabal-install, hpack, stdenv }:
mkDerivation {
pname = "hello-world";
version = "0.1.0.0";
src = ./.;
isLibrary = false;
isExecutable = true;
libraryToolDepends = [ hpack ];
executableHaskellDepends = [ base ];
executableToolDepends = [ cabal-install hpack ];
preConfigure = "hpack";
license = stdenv.lib.licenses.mit;
};
haskellPackages = if compiler == "default"
then pkgs.haskellPackages
else pkgs.haskell.packages.${compiler};
variant = if doBenchmark then pkgs.haskell.lib.doBenchmark else pkgs.lib.id;
drv = variant (haskellPackages.callPackage f {});
in
if pkgs.lib.inNixShell then drv.env else drv
# my-neovim-shell.nix
with import <nixpkgs> {};
let
my-neovim = neovim.override { vimAlias = false; };
in
stdenv.mkDerivation {
name = "neovim-dev-env";
buildInputs = [
my-neovim
];
}
Both of these produce useful shell environments! (That is, nix-shell my-haskell-env.nix and nix-shell my-neovim-env.nix give me cabal and neovim respectively, but not both).
My attempt at producing a shell.nix which will provide an environment with both neovim and cabal available is this:
# shell.nix
with import <nixpkgs> {};
let
my-neovim-shell-env = import ./my-neovim-shell.nix;
my-haskell-shell-env = import ./my-haskell-shell.nix {};
in
stdenv.mkDerivation {
name = "my-new-env";
buildInputs = [
my-neovim-shell-env
my-haskell-shell-env
];
}
This does not work however. It seems to try to build the neovim environment:
$ nix-shell
these derivations will be built:
/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv
building '/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv'...
unpacking sources
variable $src or $srcs should point to the source
builder for '/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv' failed with exit code 1
error: build of '/nix/store/k9ygid1wl75vf2nq7jzfh32mv5f8i956-neovim-dev-env.drv' failed
I don't know how to fix this; what am I doing wrong? I suspect maybe I should not be using mkDerivation?
Managed to find a solution. Maybe there is a better way, but this works:
Suppose you have a package.yaml, then
$ cabal2nix . > app.nix
# shell.nix
let
p = import <nixpkgs> {};
app = p.haskellPackages.callPackage (./app.nix) {};
lib = p.haskell.lib;
in
lib.overrideCabal app (old: { buildTools = [p.my-nvim] ++ (old.buildTools or []); })
(where I've added my-nvim to my ~/.config/nixpkgs/overlays/)
Now I have access to the my-nvim package and ghc, etc:
$ nix-shell
$ nvim # works
$ ghc # works
Inspiration from https://github.com/p-implies-q/nix-util

Nix & Haskell - using default.nix from cabal2nix and a generic shell.nix

From a pretty basic cabal file
cabal2nix ./. > default.nix
and then a shell.nix of
let
pkgs = import <nixpkgs> {};
haskellPackages = pkgs.haskellPackages_ghc784.override {
extension = self: super: {
thispackage = self.callPackage ./default.nix {};
};
};
in pkgs.myEnvFun {
name = haskellPackages.thispackage.name;
buildInputs = [
(haskellPackages.ghcWithPackages (hs: ([
hs.cabalInstall
] ++ hs.thispackage.propagatedNativeBuildInputs)))
];
}
When in the nix-shell and running cabal configure it complains of missing packages such as text.
If I put the text package explicitly into the shell.nix such as
let
pkgs = import <nixpkgs> {};
haskellPackages = pkgs.haskellPackages_ghc784.override {
extension = self: super: {
thispackage = self.callPackage ./default.nix {};
};
};
in pkgs.myEnvFun {
name = haskellPackages.thispackage.name;
buildInputs = [
(haskellPackages.ghcWithPackages (hs: ([
hs.cabalInstall
hs.text
] ++ hs.thispackage.propagatedNativeBuildInputs)))
];
}
The cabal configure is fine, but I would expect hs.thispackage.propagatedNativeBuildInputs to be supplying these packages.
The very basic haskell project can be seen at
https://github.com/fatlazycat/haskell-nix-helloworld
Am I wrong in assuming you can work in this way ?
Thanks
The propagatedNativeBuildInputs attribute is used by Haskell libraries to
propagate their build inputs down to other builds that depend on them. Your
package, however, is not a library --- it's an executable ---, so there's no
need to propagate the build inputs and thus propagatedNativeBuildInputs is
empty. Instead, you'll find the information you need in
hs.thispackage.extraBuildInputs.
Generally speaking, the definition of these kind of nix-shell environments
has become a lot easier in the release-15.09 branch (or nixos-unstable),
though. Simply run cabal2nix --shell . >shell.nix and you get a shell.nix
file that you can use for building with nix-build shell.nix as well as for
entering an interactive development environment with nix-shell.
http://nixos.org/nixpkgs/manual/#users-guide-to-the-haskell-infrastructure has
a lot more information about the subject.

Resources