Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate nitrokey-firmware into monorepo #90

Draft
wants to merge 21 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions flake.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

11 changes: 8 additions & 3 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,19 @@
inputs.treefmt-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.sops-nix.url = "github:Mic92/sops-nix";
inputs.sops-nix.inputs.nixpkgs.follows = "nixpkgs";
inputs.rust-overlay.url = "github:oxalica/rust-overlay";
inputs.rust-overlay.inputs.flake-utils.follows = "flake-utils";
inputs.rust-overlay.inputs.nixpkgs.follows = "nixpkgs";

outputs = {
self,
nixpkgs,
flake-utils,
treefmt-nix,
sops-nix,
rust-overlay,
...
}:
} @ inputs:
with builtins; let
inherit
(nixpkgs.lib)
Expand Down Expand Up @@ -54,15 +58,16 @@
};
explicitPkgs = import ./pkgs {
inherit (pkgs) lib;
inherit callPackage;
inherit callPackage inputs;
};
allPackages = pkgsByName // explicitPkgs;
in
allPackages;

importNixpkgs = system: overlays:
import nixpkgs {
inherit system overlays;
inherit system;
overlays = overlays ++ [rust-overlay.overlays.default];
};

importNixosConfigurations = import ./configs/all-configurations.nix;
Expand Down
74 changes: 74 additions & 0 deletions pkgs/by-name/nitrokey-storage/package.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
{
lib,
stdenv,
fetchzip,
fetchFromGitHub,
}: let
pname = "nitrokey-storage-firmware";
version = "0.57";

src = fetchFromGitHub {
owner = "Nitrokey";
repo = pname;
rev = "V${version}";
sha256 = "sha256-u8IK57NVS/IOPIE3Ah/O8WuOIr0EY6AF1bEaeDgIBuk=";
};

toolchain = stdenv.mkDerivation {
pname = "avr32-toolchain";
version = "3.0.0.201009140852";

src = fetchzip {
url = "https://ww1.microchip.com/downloads/archive/avr32studio-ide-2.6.0.753-linux.gtk.x86_64.zip";
sha256 = "sha256-MwsaGyNqbO0lBy1rcczuvKOaGbO3f0V+j84sUCkRlxc=";
};

postPatch = ''
cp ${src}/pm_240.h plugins/com.atmel.avr.toolchains.linux.x86_64_3.0.0.201009140852/os/linux/x86_64/avr32/include/avr32/pm_231.h
'';

installPhase = ''
runHook preInstall
cp -r plugins/com.atmel.avr.toolchains.linux.x86_64_3.0.0.201009140852/os/linux/x86_64 $out
rm -r $out/avr $out/bin/avr-*
runHook postInstall
'';

meta = {
homepage = "https://web.archive.org/web/20210419192039/https://www.microchip.com/mplab/avr-support/avr-and-sam-downloads-archive";
# The zip does not explicitly say this,
# it only mentions the license(s) of AVR32 Studio.
# Because it is very clearly a fork of GCC 4.3.3,
# it should be licensed under GPLv2+
license = lib.licenses.gpl2Plus;
description = "AVR32 toolchain";
platforms = ["x86_64-linux"];
};
};
in
stdenv.mkDerivation rec {
inherit pname version src;

sourceRoot = "source/src";

postPatch = ''
substituteInPlace Makefile \
--replace '$(shell git describe)' "V${version}"
'';

makeFlags = ["CC=${toolchain}/bin/avr32-gcc" "nitrokey-storage-V${version}-reproducible.hex"];

enableParallelBuilding = true;

installPhase = ''
runHook preInstall
install -D nitrokey-storage-V${version}-reproducible.hex $out/nitrokey-storage-V${version}-reproducible.hex
runHook postInstall
'';

meta = with lib; {
description = "Firmware for the Nitrokey Storage device";
homepage = "https://github.com/Nitrokey/nitrokey-storage-firmware";
license = licenses.gpl3Plus;
};
}
16 changes: 16 additions & 0 deletions pkgs/default.nix
Original file line number Diff line number Diff line change
@@ -1,7 +1,19 @@
{
lib,
callPackage,
inputs,
}: let
linuxSystem = "x86_64-linux";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@lorenzleutgeb I'm not sure what to do with this. I'm quite sure I don't understand the overall structure of the flake and that's why I'm confused. I know it's documented with some comments, but I still don't get it. Perhaps I'll take another look. There's just too much passing of values around and I lose track.

pkgsArm = import inputs.nixpkgs {
system = linuxSystem;
crossSystem.config = "arm-none-eabi";
};
pkgsAvr = import inputs.nixpkgs {
system = linuxSystem;
crossSystem.config = "avr";
};
stdenvArm = pkgsArm.stdenv;
stdenvAvr = pkgsAvr.stdenv;
self = rec {
# LiberaForms is intentionally disabled.
# Refer to <https://github.com/ngi-nix/ngipkgs/issues/40>.
Expand All @@ -28,6 +40,10 @@
pretalx-venueless
pretalx-public-voting
;
nitrokey-3 = callPackage ./nitrokey-firmware/nitrokey-3 {};
nitrokey-pro = callPackage ./nitrokey-firmware/nitrokey-pro.nix {inherit stdenvArm;};
nitrokey-start = callPackage ./nitrokey-firmware/nitrokey-start.nix {gcc11StdenvArm = pkgsArm.gcc11Stdenv;};
nitrokey-trng-rs232 = callPackage ./nitrokey-firmware/nitrokey-trng-rs232.nix {inherit stdenvAvr;};
};
in
self
Loading
Loading