diff --git a/firmware/.envrc b/firmware/.envrc new file mode 100644 index 0000000..29316ce --- /dev/null +++ b/firmware/.envrc @@ -0,0 +1 @@ +use flake ..#firmware --override-input rootdir "file+file://"<(printf %s "$PWD") diff --git a/firmware/.gitignore b/firmware/.gitignore new file mode 100644 index 0000000..c4a847d --- /dev/null +++ b/firmware/.gitignore @@ -0,0 +1 @@ +/result diff --git a/firmware/base.nix b/firmware/base.nix new file mode 100644 index 0000000..16f3ac4 --- /dev/null +++ b/firmware/base.nix @@ -0,0 +1,19 @@ +{ lib, ... }: +let + inherit (lib) mkOption; +in +{ + options.my.build = { + image = mkOption { + description = "Final output image for distribution."; + type = lib.types.unspecified; + }; + }; + + config = { + system = { + stateVersion = "24.11"; + }; + }; +} + diff --git a/firmware/default.nix b/firmware/default.nix new file mode 100644 index 0000000..5ff893e --- /dev/null +++ b/firmware/default.nix @@ -0,0 +1,32 @@ +{ inputs, ... }: +let + mkSystem = target: inputs.nixpkgs.lib.nixosSystem { + modules = [ + ./base.nix + target + ]; + }; +in +{ + flake.nixosConfigurations = { + qclk-rpi3 = mkSystem target/rpi3.nix; + }; + + perSystem = { libMy, pkgs, ... }: { + devenv.shells.firmware = libMy.withRootdir { + packages = with pkgs; [ + nixos-rebuild + nixVersions.latest + ]; + + scripts = { + build.exec = '' + nix build "..#nixosConfigurations.qclk-$1.config.system.build.toplevel" + ''; + build-image.exec = '' + nix build "..#nixosConfigurations.qclk-$1.config.my.build.image" + ''; + }; + }; + }; +} diff --git a/firmware/target/rpi3.nix b/firmware/target/rpi3.nix new file mode 100644 index 0000000..62a5961 --- /dev/null +++ b/firmware/target/rpi3.nix @@ -0,0 +1,8 @@ +{ pkgs, modulesPath, config, ... }: { + imports = [ + "${modulesPath}/installer/sd-card/sd-image-aarch64.nix" + ]; + + nixpkgs.system = "aarch64-linux"; + my.build.image = config.system.build.sdImage; +} diff --git a/flake.nix b/flake.nix index 2ed3d5c..6e44b9b 100644 --- a/flake.nix +++ b/flake.nix @@ -16,6 +16,7 @@ devenv.flakeModule ./mcu + ./firmware ]; systems = [ "x86_64-linux" ];