From 972678950297ab158541a8afec2cbcd01a996959 Mon Sep 17 00:00:00 2001 From: Alejandro Soto Date: Wed, 4 Oct 2023 16:35:45 -0600 Subject: nix: move flake to top-level dir --- flake.lock | 27 +++++++++ flake.nix | 179 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ nix/flake.lock | 27 --------- nix/flake.nix | 179 -------------------------------------------------------- nix/sd-card.nix | 39 ------------ 5 files changed, 206 insertions(+), 245 deletions(-) create mode 100644 flake.lock create mode 100644 flake.nix delete mode 100644 nix/flake.lock delete mode 100644 nix/flake.nix delete mode 100644 nix/sd-card.nix diff --git a/flake.lock b/flake.lock new file mode 100644 index 0000000..dcf2be8 --- /dev/null +++ b/flake.lock @@ -0,0 +1,27 @@ +{ + "nodes": { + "nixpkgs": { + "locked": { + "lastModified": 1696143757, + "narHash": "sha256-r69r9PBwNYReBavktCOP6jmtnpF0DEZWABBnJuzqkK0=", + "owner": "nixos", + "repo": "nixpkgs", + "rev": "3b9e1bd994c34b020ed7898b805a104511294d63", + "type": "github" + }, + "original": { + "owner": "nixos", + "ref": "release-23.05", + "repo": "nixpkgs", + "type": "github" + } + }, + "root": { + "inputs": { + "nixpkgs": "nixpkgs" + } + } + }, + "root": "root", + "version": 7 +} diff --git a/flake.nix b/flake.nix new file mode 100644 index 0000000..3fcb236 --- /dev/null +++ b/flake.nix @@ -0,0 +1,179 @@ +{ + inputs.nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; + + outputs = { self, nixpkgs }: + let + system = "x86_64-linux"; + pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; + + crossSystem = "arm-linux"; + cross = import nixpkgs { + inherit system; + + config.allowUnsupportedSystem = true; + + crossSystem = { + config = "arm-unknown-linux-gnueabi"; + + gcc = { + # > Switch "--with-arch" may not be used with switch "--with-cpu" + # > make[1]: *** [Makefile:4315: configure-gcc] Error 1 + #arch = "armv4"; + + # Ver SA110 en arch/arm/mm/Kconfig, es parecido + cpu = "arm810"; + }; + + linux-kernel = { + name = "taller"; + target = "uImage"; + makeFlags = [ "LOADADDR=0x8000" ]; + autoModules = false; + baseConfig = "taller_defconfig"; + }; + }; + + # Tomó mucho conseguir esta expresión: horas de leer nixpkgs, prueba y error + crossOverlays = [ + (final: prev: { + stdenv = prev.stdenvAdapters.overrideCC prev.stdenv (prev.stdenv.cc.override { + bintools = prev.stdenv.cc.bintools.override { + bintools = prev.stdenv.cc.bintools.bintools.overrideAttrs (prev: { + patches = prev.patches ++ [ + ./nix/gas-config-tc-arm-disable-instruction-support-check.patch + ]; + }); + }; + }); + }) + ]; + }; + in + { + formatter.${system} = pkgs.nixpkgs-fmt; + + # Tomado de pkgs/build-support/vm/default.nix + packages."${crossSystem}".proof-of-concept = cross.makeInitrd { + contents = [ + { + symlink = "/init"; + + object = with cross; let + initrdUtils = runCommand "initrd-utils" + { + nativeBuildInputs = [ buildPackages.nukeReferences ]; + allowedReferences = [ "out" ]; # prevent accidents like glibc being included in the initrd + } + '' + mkdir -p $out/bin + mkdir -p $out/lib + + # Copy what we need from Glibc. + cp -p ${cross.glibc.out}/lib/ld-linux*.so.? $out/lib + cp -p ${cross.glibc.out}/lib/libc.so.* $out/lib + cp -p ${cross.glibc.out}/lib/libm.so.* $out/lib + cp -p ${cross.glibc.out}/lib/libresolv.so.* $out/lib + + # Copy BusyBox. + cp -pd ${cross.busybox}/bin/* $out/bin + + # Run patchelf to make the programs refer to the copied libraries. + for i in $out/bin/* $out/lib/*; do if ! test -L $i; then nuke-refs $i; fi; done + + for i in $out/bin/*; do + if [ -f "$i" -a ! -L "$i" ]; then + echo "patching $i..." + patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true + fi + done + ''; + + + path = lib.makeSearchPath "bin" [ + #bashInteractive + #coreutils-full + #gnugrep + #neofetch + #util-linux + ]; + in + writeScript "init" '' + #!${initrdUtils}/bin/ash + + export PATH=${initrdUtils}/bin + + mkdir -p /dev /etc /proc /sys + echo -n > /etc/fstab + + mount -t devtmpfs devtmpfs /dev + mount -t proc none /proc + mount -t sysfs none /sys + + exec ash + ''; + } + ]; + }; + + devShells."${system}" = with pkgs; { + default = mkShell { + buildInputs = [ + ncurses + openssl + SDL2 + ]; + + nativeBuildInputs = [ + binutils + gcc + cross.stdenv.cc.cc + cross.stdenv.cc.bintools + gcc-arm-embedded + gdb + gnumake + gtkwave + kermit + lcov + pkg-config + (python3.withPackages (py: [ py.numpy py.pillow py.matplotlib ])) + (quartus-prime-lite.override { supportedDevices = [ "Cyclone V" ]; }) + verilator + ]; + + shellHook = '' + export CROSS_COMPILE=arm-unknown-linux-gnueabi- + export MAKEFLAGS="AR=gcc-ar" + export CXXFLAGS="$(pkg-config --cflags sdl2 ncursesw)" + export LDFLAGS="$(pkg-config --libs sdl2 ncursesw)" + + # + export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" + export FONTCONFIG_FILE="${fontconfig.out}/etc/fonts/fonts.conf" + ''; + }; + + kbuild = mkShell { + buildInputs = [ + ncurses + ]; + + nativeBuildInputs = [ + bc + bison + flex + gcc + cross.stdenv.cc.cc + cross.stdenv.cc.bintools + gnumake + openssl # Splash de u-boot + ubootTools + ]; + + shellHook = '' + export CROSS_COMPILE=arm-unknown-linux-gnueabi- + export MAKEFLAGS="ARCH=arm O=build/taller LOADADDR=0x8000" + ''; + }; + }; + }; +} diff --git a/nix/flake.lock b/nix/flake.lock deleted file mode 100644 index dcf2be8..0000000 --- a/nix/flake.lock +++ /dev/null @@ -1,27 +0,0 @@ -{ - "nodes": { - "nixpkgs": { - "locked": { - "lastModified": 1696143757, - "narHash": "sha256-r69r9PBwNYReBavktCOP6jmtnpF0DEZWABBnJuzqkK0=", - "owner": "nixos", - "repo": "nixpkgs", - "rev": "3b9e1bd994c34b020ed7898b805a104511294d63", - "type": "github" - }, - "original": { - "owner": "nixos", - "ref": "release-23.05", - "repo": "nixpkgs", - "type": "github" - } - }, - "root": { - "inputs": { - "nixpkgs": "nixpkgs" - } - } - }, - "root": "root", - "version": 7 -} diff --git a/nix/flake.nix b/nix/flake.nix deleted file mode 100644 index 6dabcd0..0000000 --- a/nix/flake.nix +++ /dev/null @@ -1,179 +0,0 @@ -{ - inputs.nixpkgs.url = "github:nixos/nixpkgs/release-23.05"; - - outputs = { self, nixpkgs }: - let - system = "x86_64-linux"; - pkgs = import nixpkgs { inherit system; config.allowUnfree = true; }; - - crossSystem = "arm-linux"; - cross = import nixpkgs { - inherit system; - - config.allowUnsupportedSystem = true; - - crossSystem = { - config = "arm-unknown-linux-gnueabi"; - - gcc = { - # > Switch "--with-arch" may not be used with switch "--with-cpu" - # > make[1]: *** [Makefile:4315: configure-gcc] Error 1 - #arch = "armv4"; - - # Ver SA110 en arch/arm/mm/Kconfig, es parecido - cpu = "arm810"; - }; - - linux-kernel = { - name = "taller"; - target = "uImage"; - makeFlags = [ "LOADADDR=0x8000" ]; - autoModules = false; - baseConfig = "taller_defconfig"; - }; - }; - - # Tomó mucho conseguir esta expresión: horas de leer nixpkgs, prueba y error - crossOverlays = [ - (final: prev: { - stdenv = prev.stdenvAdapters.overrideCC prev.stdenv (prev.stdenv.cc.override { - bintools = prev.stdenv.cc.bintools.override { - bintools = prev.stdenv.cc.bintools.bintools.overrideAttrs (prev: { - patches = prev.patches ++ [ - ./gas-config-tc-arm-disable-instruction-support-check.patch - ]; - }); - }; - }); - }) - ]; - }; - in - { - formatter.${system} = pkgs.nixpkgs-fmt; - - # Tomado de pkgs/build-support/vm/default.nix - packages."${crossSystem}".proof-of-concept = cross.makeInitrd { - contents = [ - { - symlink = "/init"; - - object = with cross; let - initrdUtils = runCommand "initrd-utils" - { - nativeBuildInputs = [ buildPackages.nukeReferences ]; - allowedReferences = [ "out" ]; # prevent accidents like glibc being included in the initrd - } - '' - mkdir -p $out/bin - mkdir -p $out/lib - - # Copy what we need from Glibc. - cp -p ${cross.glibc.out}/lib/ld-linux*.so.? $out/lib - cp -p ${cross.glibc.out}/lib/libc.so.* $out/lib - cp -p ${cross.glibc.out}/lib/libm.so.* $out/lib - cp -p ${cross.glibc.out}/lib/libresolv.so.* $out/lib - - # Copy BusyBox. - cp -pd ${cross.busybox}/bin/* $out/bin - - # Run patchelf to make the programs refer to the copied libraries. - for i in $out/bin/* $out/lib/*; do if ! test -L $i; then nuke-refs $i; fi; done - - for i in $out/bin/*; do - if [ -f "$i" -a ! -L "$i" ]; then - echo "patching $i..." - patchelf --set-interpreter $out/lib/ld-linux*.so.? --set-rpath $out/lib $i || true - fi - done - ''; - - - path = lib.makeSearchPath "bin" [ - #bashInteractive - #coreutils-full - #gnugrep - #neofetch - #util-linux - ]; - in - writeScript "init" '' - #!${initrdUtils}/bin/ash - - export PATH=${initrdUtils}/bin - - mkdir -p /dev /etc /proc /sys - echo -n > /etc/fstab - - mount -t devtmpfs devtmpfs /dev - mount -t proc none /proc - mount -t sysfs none /sys - - exec ash - ''; - } - ]; - }; - - devShells."${system}" = with pkgs; { - default = mkShell { - buildInputs = [ - ncurses - openssl - SDL2 - ]; - - nativeBuildInputs = [ - binutils - gcc - cross.stdenv.cc.cc - cross.stdenv.cc.bintools - gcc-arm-embedded - gdb - gnumake - gtkwave - kermit - lcov - pkg-config - (python3.withPackages (py: [ py.numpy py.pillow py.matplotlib ])) - (quartus-prime-lite.override { supportedDevices = [ "Cyclone V" ]; }) - verilator - ]; - - shellHook = '' - export CROSS_COMPILE=arm-unknown-linux-gnueabi- - export MAKEFLAGS="AR=gcc-ar" - export CXXFLAGS="$(pkg-config --cflags sdl2 ncursesw)" - export LDFLAGS="$(pkg-config --libs sdl2 ncursesw)" - - # - export LOCALE_ARCHIVE="${glibcLocales}/lib/locale/locale-archive" - export FONTCONFIG_FILE="${fontconfig.out}/etc/fonts/fonts.conf" - ''; - }; - - kbuild = mkShell { - buildInputs = [ - ncurses - ]; - - nativeBuildInputs = [ - bc - bison - flex - gcc - cross.stdenv.cc.cc - cross.stdenv.cc.bintools - gnumake - openssl # Splash de u-boot - ubootTools - ]; - - shellHook = '' - export CROSS_COMPILE=arm-unknown-linux-gnueabi- - export MAKEFLAGS="ARCH=arm O=build/taller LOADADDR=0x8000" - ''; - }; - }; - }; -} diff --git a/nix/sd-card.nix b/nix/sd-card.nix deleted file mode 100644 index d2faea8..0000000 --- a/nix/sd-card.nix +++ /dev/null @@ -1,39 +0,0 @@ -{ ... }: { - nixpkgs = { - config.allowUnsupportedSystem = true; - - crossSystem = { - config = "armv4-unknown-linux-gnueabi"; - - gcc = { - # > Switch "--with-arch" may not be used with switch "--with-cpu" - # > make[1]: *** [Makefile:4315: configure-gcc] Error 1 - #arch = "armv4"; - - # Ver SA110 en arch/arm/mm/Kconfig, es parecido - cpu = "arm810"; - }; - - linux-kernel = { - name = "taller"; - target = "uImage"; - makeFlags = [ "LOADADDR=0x01000000" ]; - autoModules = false; - # Esto es solo para construir el toplevel del system - baseConfig = "multi_v5_defconfig"; # "multi_v4_defconfig"; - }; - }; - }; - - system.stateVersion = "22.11"; - - fileSystems."/" = { - device = "tmpfs"; - fsType = "tmpfs"; - }; - - boot.loader = { - grub.enable = false; - generic-extlinux-compatible.enable = true; - }; -} -- cgit v1.2.3