Skip to content

Instantly share code, notes, and snippets.

@arianvp
Created August 6, 2020 21:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arianvp/c2067c702ed41a045bfb7c8024690de1 to your computer and use it in GitHub Desktop.
Save arianvp/c2067c702ed41a045bfb7c8024690de1 to your computer and use it in GitHub Desktop.
Nix bug

nix-shell --pure repro.nix succeeds:

$ nix-shell --pure repro.nix
[nix-shell]$ out=final.img
[nix-shell]$ genericBuild
90792
Checking that no-one is using this disk right now ... OK

Disk out.img: 44.3 MiB, 46485504 bytes, 90792 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

>>> Script header accepted.
>>> Created a new GPT disklabel (GUID: 3BD471B9-C81F-5444-A298-092FBC879AE4).
out.img1: Created a new partition 1 of type 'Linux filesystem' and of size 7.3 MiB.
out.img2: Created a new partition 2 of type 'Linux filesystem' and of size 34.8 MiB.
out.img3: Created a new partition 3 of type 'Linux filesystem' and of size 288 KiB.
out.img4: Done.

New situation:
Disklabel type: gpt
Disk identifier: 3BD471B9-C81F-5444-A298-092FBC879AE4

Device     Start   End Sectors  Size Type
out.img1    2048 16991   14944  7.3M Linux filesystem
out.img2   18432 89607   71176 34.8M Linux filesystem
out.img3   18432 19007     576  288K Linux filesystem

[nix-shell] $ 

nix-build repro.nix fails:

$ nix-build repro.nix 
warning: unknown setting 'experimental-features'
these derivations will be built:
  /nix/store/5kj9blrx1yjdymbs6l00s9yiba4fk06f-efi.drv
cannot build on 'ssh://arian@ryzen.local': cannot connect to 'arian@ryzen.local': ssh: Could not resolve hostname ryzen.local: Device or resource busy
building '/nix/store/5kj9blrx1yjdymbs6l00s9yiba4fk06f-efi.drv'...
90792
Checking that no-one is using this disk right now ... OK

Disk out.img: 44.3 MiB, 46485504 bytes, 90792 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes

>>> Script header accepted.
>>> Created a new GPT disklabel (GUID: D044EA22-2C88-0F4F-A0BB-7500F5330146).
out.img1: Created a new partition 1 of type 'Linux filesystem' and of size 7.3 MiB.
out.img2: Created a new partition 2 of type 'Linux filesystem' and of size 34.8 MiB.
out.img3: Created a new partition 3 of type 'Linux filesystem' and of size 288 KiB.
out.img4: Done.

New situation:
Disklabel type: gpt
Disk identifier: D044EA22-2C88-0F4F-A0BB-7500F5330146

Device     Start   End Sectors  Size Type
out.img1    2048 16991   14944  7.3M Linux filesystem
out.img2   18432 89607   71176 34.8M Linux filesystem
out.img3   18432 19007     576  288K Linux filesystem
builder for '/nix/store/5kj9blrx1yjdymbs6l00s9yiba4fk06f-efi.drv' failed with exit code 1
error: build of '/nix/store/5kj9blrx1yjdymbs6l00s9yiba4fk06f-efi.drv' failed

{ pkgs ? import <nixpkgs> {}}:
let inherit (pkgs) stdenv utillinux;
in
stdenv.mkDerivation {
name = "efi";
nativeBuildInputs = [
utillinux
];
buildCommand = ''
reserved=4096
espSize=14944
rootSize=71176
veritySize=576
fullSize=$(($reserved + $espSize + $rootSize + $veritySize))
echo $fullSize
truncate --size $(( $fullSize * 512 )) out.img
sfdisk out.img <<EOF
label: gpt
size=$espSize
size=$rootSize
size=$veritySize
EOF
cp out.img $out
'';
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment