YubiKey-Guide icon indicating copy to clipboard operation
YubiKey-Guide copied to clipboard

NixOS Build Broken

Open parkerk opened this issue 3 years ago • 19 comments

While following the NixOS build instructions I came across a few issues:

Building initially gave an error

error: experimental Nix feature 'nix-command' is disabled; use '--extra-experimental-features nix-command' to override

I was able to fix this by using nix --extra-experimental-features nix-command build -f yubikey-installer.nix -o installer nixos-yubikey

The next issue was I got an error about yubioath-desktop being deprecated

error: yubioath-desktop has been deprecated by upstream in favor of yubioath-flutter

I was able to fix that by replacing yubioath-desktop with yubioath-flutter

The final issue I have is

error: builder for '/nix/store/g7pw6yjayp9qxmbh72b8pwx82j1jxq2v-hopenpgp-tools-0.23.7.drv' failed with exit code 1; last 10 log lines: > In an equation for ‘spGetSCT’: > Patterns of type ‘Pkt’ not matched: > PKESKPkt _ _ _ _ > SKESKPkt _ _ _ _ > OnePassSignaturePkt _ _ _ _ _ _ > SecretKeyPkt _ _ > ... > | > 211 | spGetSCT (SignaturePkt s) = fmap fromIntegral (sigCT s) > | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ For full logs, run 'nix log /nix/store/g7pw6yjayp9qxmbh72b8pwx82j1jxq2v-hopenpgp-tools-0.23.7.drv'.

It looks like hopengpg-tools is broken for nix? https://github.com/NixOS/nixpkgs/blob/6f3728df507fd1683cf16e49a0078dc800330259/pkgs/development/haskell-modules/configuration-hackage2nix/broken.yaml

https://github.com/NixOS/nixpkgs/search?q=hopenpgp&type=issues

I just wanted to open this issue to see if anyone has solved this. In the meantime, I'll keep researching and if I can get it working, I'll post a PR.

Thanks for this great guide drduh! And thanks to everyone else who has contributed

parkerk avatar Feb 04 '23 16:02 parkerk

It looks like the current airgapped NixOS config was based on https://github.com/dhess/nixos-yubikey (according to https://github.com/drduh/YubiKey-Guide/pull/342)

Some files of interest https://github.com/dhess/nixos-yubikey/blob/master/nix/sources.json https://github.com/dhess/nixos-yubikey/blob/master/lib/default.nix https://github.com/dhess/nixos-yubikey/blob/master/default.nix

In that repo, it looks like specific versions are being targeted to prevent hopengpg from breaking?

I have no experience with NixOS, so I just wanted to document what I've found so far, in case it helps save time for someone who knows NixOS better.

Looping in @zeorin @rvl @reissmann as you three have all made nice contributions to the Nix build. Sorry to bother you, just wanted to loop you in in case you were interested

parkerk avatar Feb 04 '23 16:02 parkerk

Hi, I've managed to make it work using a dirty workaround. I did three main things:

1 - Changed the desktop package to the flutter one, yubioath-flutter 2 - Pinned the version of the Haskel program to one that compiles properly:


pkgs = import (builtins.fetchTarball {
        url = "https://github.com/NixOS/nixpkgs/archive/3b05df1d13c1b315cecc610a2f3180f6669442f0.tar.gz";
    }) {};                                                                         
 myPkg = pkgs.haskellPackages.hopenpgp-tools;

and removed: # Testing ent (haskell.lib.justStaticExecutables haskellPackages.hopenpgp-tools) 3 - Forced the kernel of the image to be a ZFS compatible to avoid some weird license issues. boot.kernelPackages = config.boot.zfs.package.latestCompatibleLinuxPackages;

It booted and I've managed to prepare my yubikey.

Note that this is my first week in nixos, I am not sure I am doing all as it is supposed to be done. The modified file is below for inspection. Hope it helps. yubikey-installer.nix.txt

nodupe avatar Apr 09 '23 17:04 nodupe

A simple workaround is to use the stable nixos-22.05 channel:

nix build -f yubikey-installer.nix -o installer nixos-yubikey -I nixpkgs=channel:nixos-22.05

As noted above, you might have to temporarily enable nix-command, but that's a separate issue.

nix build --extra-experimental-features nix-command -f yubikey-installer.nix -o installer nixos-yubikey -I nixpkgs=channel:nixos-22.05

pkel avatar Apr 18 '23 08:04 pkel

Nixos 22.05 is now deprecated (and so is 22.11 at the time of writing, long live 23.05!)

If it is desirable, I will make a PR to pin nixpkgs to the current stable version of Nixos.

NotAShelf avatar Jun 18 '23 00:06 NotAShelf

Apparently neither the updated version from @nodupe of yubikey-installer.nix, nor the additional command-line options for nix build from @pkel work anymore:

[vagrant@nixbox:~]$ time nix build -f yubikey-installer.nix -o installer nixos-yubikey -I nixpkgs=channel:nixos-22.05
warning: unable to download 'https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz': Peer certificate cannot be authenticated with given CA certificates (60); retrying in 332 ms
warning: unable to download 'https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz': Peer certificate cannot be authenticated with given CA certificates (60); retrying in 692 ms
warning: unable to download 'https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz': Peer certificate cannot be authenticated with given CA certificates (60); retrying in 1040 ms
warning: unable to download 'https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz': Peer certificate cannot be authenticated with given CA certificates (60); retrying in 2352 ms
warning: Nix search path entry 'channel:nixos-22.05' cannot be downloaded, ignoring
error: anonymous function at /nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs/nixos/release.nix:1:1 called with unexpected argument 'configuration', at /home/vagrant/yubikey-installer.nix:165:11

real    0m4.917s
user    0m0.075s
sys     0m0.031s

[vagrant@nixbox:~]$

Any ideas on how to get this working are welcome.

rda716 avatar Jun 23 '23 04:06 rda716

This looks like there's something wrong with your environment preventing it from verifying the certificates (or there were issues with nixos.org when you tried it that have since cleared up). The URL it complains about (https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz) resolves and has a valid certificate, and the command works fine on my machine.

MaienM avatar Jun 28 '23 09:06 MaienM

The certificate for nixos.org is expired:

[nix-shell:~]$ wget https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz
--2023-06-28 13:56:23--  https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz
Resolving nixos.org (nixos.org)... 35.229.48.116, 54.84.236.175, 2600:1f18:2489:8201::c8, ...
Connecting to nixos.org (nixos.org)|35.229.48.116|:443... connected.
ERROR: cannot verify nixos.org's certificate, issued by ‘CN=R3,O=Let's Encrypt,C=US’:
  Issued certificate has expired.
To connect to nixos.org insecurely, use `--no-check-certificate'.

The same command works when run directly on the machine that is hosting the Vagrant VM.

For some reason, the certificate for nixos.org cannot be updated.

Output of nix-info:

[vagrant@nixbox:~]$ nix-shell -p nix-info --run "nix-info -m"
 - system: `"x86_64-linux"`
 - host os: `Linux 4.14.32, NixOS, 18.03.131807.489a14add9a (Impala)`
 - multi-user?: `yes`
 - sandbox: `no`
 - version: `nix-env (Nix) 2.0`
 - nixpkgs: `/nix/var/nix/profiles/per-user/root/channels/nixos/nixpkgs`

rda716 avatar Jun 28 '23 14:06 rda716

Nixos 22.05 is now deprecated (and so is 22.11 at the time of writing, long live 23.05!)

If it is desirable, I will make a PR to pin nixpkgs to the current stable version of Nixos.

That would be very helpful, but not sure how easy that is to do.

rda716 avatar Jun 28 '23 14:06 rda716

The certificate for nixos.org is expired:

[nix-shell:~]$ wget https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz
--2023-06-28 13:56:23--  https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz
Resolving nixos.org (nixos.org)... 35.229.48.116, 54.84.236.175, 2600:1f18:2489:8201::c8, ...
Connecting to nixos.org (nixos.org)|35.229.48.116|:443... connected.
ERROR: cannot verify nixos.org's certificate, issued by ‘CN=R3,O=Let's Encrypt,C=US’:
  Issued certificate has expired.
To connect to nixos.org insecurely, use `--no-check-certificate'.

That doesn't match with what I see on my end. My first instinct would be to suspect the date of your machine being out of sync (and out of the range of validity of the certificate), but from the output you've provided this appears not to be the case. I've even forced curl to use the same IP address you're connecting to, and I still get a valid certificate.

> curl -v https://nixos.org/channels/nixos-22.05/nixexprs.tar.xz --connect-to nixos.org:443:35.229.48.116:443
* Connecting to hostname: 35.229.48.116
* Connecting to port: 443
*   Trying 35.229.48.116:443...
* Connected to 35.229.48.116 (35.229.48.116) port 443 (#0)
* ALPN: offers h2,http/1.1
* TLSv1.3 (OUT), TLS handshake, Client hello (1):
* TLSv1.3 (IN), TLS handshake, Server hello (2):
* TLSv1.3 (IN), TLS handshake, Encrypted Extensions (8):
* TLSv1.3 (IN), TLS handshake, Certificate (11):
* TLSv1.3 (IN), TLS handshake, CERT verify (15):
* TLSv1.3 (IN), TLS handshake, Finished (20):
* TLSv1.3 (OUT), TLS change cipher, Change cipher spec (1):
* TLSv1.3 (OUT), TLS handshake, Finished (20):
* SSL connection using TLSv1.3 / TLS_AES_128_GCM_SHA256
* ALPN: server accepted h2
* Server certificate:
*  subject: CN=*.nixos.org
*  start date: May 21 04:51:08 2023 GMT
*  expire date: Aug 19 04:51:07 2023 GMT
*  subjectAltName: host "nixos.org" matched cert's "nixos.org"
*  issuer: C=US; O=Let's Encrypt; CN=R3
*  SSL certificate verify ok.
> nix-info -m
 - system: `"x86_64-linux"`
 - host os: `Linux 6.1.34, NixOS, 23.11 (Tapir), 23.11.20230617.04af42f`
 - multi-user?: `yes`
 - sandbox: `yes`
 - version: `nix-env (Nix) 2.15.1`
 - nixpkgs: `/nix/store/vby8c3909sglr03fxkclkly29vs49ncy-source`

There's something weird happening here, though I have no idea whether it's something on your end or on nixos.org's end. You're using a pretty old version of NixOS, maybe there's an issue with a root/intermediate certificate that is distributed as part of that which has expired? Might be worth jumping into one of the help channels of NixOS to see if they can help you out.

A possible workaround might be (if you can download the file on another machine and transfer it) to specify a file:// path: -I nixpkgs=file://path-to-downloaded-nixexprs.tar.xz.

MaienM avatar Jun 28 '23 15:06 MaienM

First off thanks to all the contributers to this repo. It is a really well documented guide.

In order for nix build to complete without issues, a certain version of nixpkgs should be used. The easiest way is to use the -I flag (As mentioned by @pkel). It is also possible to update this code and use a nix flake, which has a pinned version of nixpkgs in its inputs section. If I understood correctly, this shouldn't be a problem as it is intended for a complete offline installation.

@drduh is it acceptible if someone created a pull request with the simple solution (using -I to set nixpgks version)?

kaikikokuke avatar Jul 11 '23 13:07 kaikikokuke

In order for nix build to complete without issues, a certain version of nixpkgs should be used. The easiest way is to use the -I flag (As mentioned by @pkel). It is also possible to update this code and use a nix flake

I spent some time trying to make yubikey-installer.nix work with flakes, but to no avail: I could not find a signature similar to this one:

nix-repl> builtins.functionArgs (import <nixpkgs/nixos/release.nix>)         
{ configuration = true; nixpkgs = true; stableBranch = true; supportedSystems = true; }

... when nixpkgs is imported via a flake.

I think it we need to at least specify -I to make sure this keeps building when nixpkgs evolves, especially across releases/breaking changes. I would personally also favor flakes, since that adds full determinism, and the trade-offs, in my view, seem to be OK with the nature of this image.

@kaikikokuke do you have an example you could share that makes this work with flakes?

motiejus avatar Jul 18 '23 08:07 motiejus

Sorry @motiejus for the late reply. I don't have a working example at the moment, as I don't have much free time. But I'll try to provide a working flake.nix soon. In a flake, you could use outPath , which provides the path to the parent folder containing the source in a flake. So in a flake, where nixpkgs is in the inputs, you could access release.nix like so:

{
  description = "A very basic flake";

  inputs.nixpkgs.url = "github:NixOS/nixpkgs/nixos-22.05";

  outputs = {
    self,
    nixpkgs,
  }: let
    releasePath = self.inputs.nixpkgs.outPath + "/nixos/release.nix";
  in {
    
    yubikeyInstallerDerivation = ... ;
    packages.x86_64-linux.default = yubikeyInstallerDerivation;
  };
}

We also need to make it a derivation, so it can be built using nix build. I hope this helps a bit for the time being.

kaikikokuke avatar Jul 27 '23 08:07 kaikikokuke

Hey all, :wave:

Sorry for the radio silence on this issue. I kept meaning to get round to fixing this, but my bandwidth for OSS has been really low recently. Anyway, my GPG key expired :joy: and I need to extend/renew it so this suddenly became a pressing issue.

PR is up at https://github.com/drduh/YubiKey-Guide/pull/396. Please try it out and let me know how it goes.

zeorin avatar Oct 03 '23 22:10 zeorin

Apparently neither the updated version from @nodupe of yubikey-installer.nix, nor the additional command-line options for nix build from @pkel work anymore:

warning: Nix search path entry 'channel:nixos-22.05' cannot be downloaded, ignoring

Any ideas on how to get this working are welcome.

Experiencing the same with 23.05 (not with YubiKey but the whole rebuild/install part), but it's more about at «none»:0: (source not available)

bphd avatar Oct 21 '23 17:10 bphd

@bphd Would you be able to copy/paste your command line input together with its output here? I just ran nix-build yubikey-installer.nix --out-link installer --attr nixos-yubikey with the current yubikey-installer.nix and it built just fine.

zeorin avatar Oct 23 '23 12:10 zeorin

@bphd Would you be able to copy/paste your command line input together with its output here? I just ran nix-build yubikey-installer.nix --out-link installer --attr nixos-yubikey with the current yubikey-installer.nix and it built just fine.

I've figured that I was asking 25.03 instead of 23.05, hence the problem

bphd avatar Oct 24 '23 09:10 bphd

My attempt to build is failing with

error: cannot download optparse-applicative-0.18.1.0-r1.cabal from any mirror
error: builder for '/nix/store/ym132z6q999lplzw22y9zyji6w5as1w2-optparse-applicative-0.18.1.0-r1.cabal.drv' failed with exit code 1;
       last 7 log lines:
       >
       > trying https://hackage.haskell.org/package/optparse-applicative-0.18.1.0/revision/1.cabal
       >   % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
       >                                  Dload  Upload   Total   Spent    Left  Speed
       >   0    77    0     0    0     0      0      0 --:--:-- --:--:-- --:--:--     0
       > curl: (22) The requested URL returned error: 404
       > error: cannot download optparse-applicative-0.18.1.0-r1.cabal from any mirror
       For full logs, run 'nix-store -l /nix/store/ym132z6q999lplzw22y9zyji6w5as1w2-optparse-applicative-0.18.1.0-r1.cabal.drv'.

EricWardner avatar Oct 30 '23 16:10 EricWardner

@EricWardner the version number it's trying to download there doesn't seem correct… Not sure where it would get that from, the version in the README.md is 0.18.1.0, not 0.18.1.0-r1.cabal.

zeorin avatar Nov 01 '23 09:11 zeorin

I attempted the conversion to a flake. See https://github.com/drduh/YubiKey-Guide/issues/406. Feedback is much appreciated :)

thomaseizinger avatar Dec 17 '23 06:12 thomaseizinger