codex-storage / nim-codex

Decentralized Durability Engine
https://codex.storage
Apache License 2.0
65 stars 25 forks source link

Add Nix Flake with derivation, shell, service #940

Open jakubgs opened 2 weeks ago

jakubgs commented 2 weeks ago

It would be helpful to have a Nix flake for this package. The most basic version would just include a build shell, but a a more advanced version would also include a full derivation and also a NixOS service module.

If possible we should also have CI job for our Nix builds.

This was requested by Corey, but Jarrad would also appreciate it.

jakubgs commented 2 weeks ago

Here is an attempt by Corey to get something working, some parts of the derivation might be useful: codex-flake.nix.txt

corpetty commented 2 weeks ago

This shell script worked, but it didn't include the CMakeLists.txt patch I had to do: shell.nix.txt

Here's how I updated the CMakeLists.txt file (from Claude.ai):

  1. Open the CMakeLists.txt file in a text editor: nano /home/petty/codex/repos/nim-codex/vendor/nim-leopard/vendor/leopard/CMakeLists.txt
  2. replace the else block (just before the add_library command), add the following:

    else()
    check_cxx_compiler_flag("-march=native" CXX_FLAG_MARCH_NATIVE)
    check_cxx_compiler_flag("-mtune=native" CXX_FLAG_MTUNE_NATIVE)
    check_cxx_compiler_flag("-msse" CXX_FLAG_SSE)
    check_cxx_compiler_flag("-msse2" CXX_FLAG_SSE2)
    check_cxx_compiler_flag("-msse3" CXX_FLAG_SSE3)
    check_cxx_compiler_flag("-mssse3" CXX_FLAG_SSSE3)
    check_cxx_compiler_flag("-msse4.1" CXX_FLAG_SSE41)
    check_cxx_compiler_flag("-msse4.2" CXX_FLAG_SSE42)
    check_cxx_compiler_flag("-mavx" CXX_FLAG_AVX)
    check_cxx_compiler_flag("-mavx2" CXX_FLAG_AVX2)
    
    if(CXX_FLAG_MARCH_NATIVE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -march=native")
    endif()
    if(CXX_FLAG_MTUNE_NATIVE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mtune=native")
    endif()
    if(CXX_FLAG_SSE)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse")
    endif()
    if(CXX_FLAG_SSE2)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse2")
    endif()
    if(CXX_FLAG_SSE3)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse3")
    endif()
    if(CXX_FLAG_SSSE3)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mssse3")
    endif()
    if(CXX_FLAG_SSE41)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.1")
    endif()
    if(CXX_FLAG_SSE42)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")
    endif()
    if(CXX_FLAG_AVX)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx")
    endif()
    if(CXX_FLAG_AVX2)
        set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -mavx2")
    endif()
    
    set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wextra -Werror")
    endif()
veaceslavdoina commented 2 weeks ago

We are shipping two binaries right now codex and crdl (Circuit download tool)

https://github.com/codex-storage/nim-codex/blob/17f0988fc754b85d9f9cd7f6b7f947a1e36ec39e/.github/workflows/release.yml#L84-L87