NixOSにArtemisをインストール

NixOSにArtemisを導入したので手順を書き残しておきます。(備忘録なのでかなり適当)

インストールするArtemisはdevelopブランチです。

NixOS自身の環境整備方法については割愛します。

大まかな手順は以下の通りです。

  • home.nixの設定
  • flake.nixの設定
  • 設定を反映
  • artemisをインストール
  • root/artemisの環境設定

home.nixの設定

ユーザー環境向けの環境構築ツールhome-managerにてartemisに必要なあれこれをインストールします。

~/.config/home-maneger/home.nix内のhome.packages以下に必要なパッケージを入れます。

  # The home.packages option allows you to install Nix packages into your
  # environment.
  home.packages = [ 
    # # Adds the 'hello' command to your environment. It prints a friendly
    # # "Hello, world!" when run.
    # pkgs.hello

    # # It is sometimes useful to fine-tune packages, for example, by applying
    # # overrides. You can do that directly here, just don't forget the
    # # parentheses. Maybe you want to install Nerd Fonts with a limited number of
    # # fonts?
    # (pkgs.nerdfonts.override { fonts = [ "FantasqueSansMono" ]; })

    # # You can also create simple shell scripts directly inside your
    # # configuration. For example, this adds a command 'my-hello' to your
    # # environment:
    # (pkgs.writeShellScriptBin "my-hello" ''
    #   echo "Hello, ${config.home.username}!"
    # '')

    pkgs.git
    pkgs.tmux
    pkgs.root
    pkgs.yaml-cpp
    pkgs.cmake
    pkgs.zlib
  ];  

flake.nixの設定

rootやC++などを導入したシェルを立ち上げるための設定をflake.nixに書きます。

こちらに関してはどこに作っても良いです。

私の場合は~/nix/に作成しました。

  description = "Example C++ development environment for Zero to Nix";

  # Flake inputs
  inputs = {
    nixpkgs.url = "github:NixOS/nixpkgs"; # also valid: "nixpkgs"
  };

  # Flake outputs
  outputs = { self, nixpkgs }:
    let
      # Systems supported
      allSystems = [
        "x86_64-linux" # 64-bit Intel/AMD Linux
      ];

      # Helper to provide system-specific attributes
      forAllSystems = f: nixpkgs.lib.genAttrs allSystems (system: f {
        pkgs = import nixpkgs { inherit system; };
      });
    in
    {
      # Development environment output
      devShells = forAllSystems ({ pkgs }: {
        default = pkgs.mkShell {
          # The Nix packages provided in the environment
          packages = with pkgs; [
            gcc
            cmake
            root
            yaml-cpp
            zlib
          ];
        };
      });
    };
}

設定を反映

まずはhome-managerを使ってパッケージをインストールします。以下のコマンドを実行します。

home-manager switch

次に必要なパッケージが導入済みのシェルを立ち上げます。

先ほどflake.nixを作成したディレクトリにて以下を実行します。

nix develop -c $SHELL

Artemisをインストール

あとはartemisをインストールするだけです。

コマンド自体は公式のもので問題ないですが、2023/08/20現在だと最新版のdevelopブランチでは大量のエラーが発生します。

forkして修正したバーションを使用します。リンクはここ

git clone https://github.com/FumiHubCNS/artemis.git -b develop
cd artemis
mkdir build
cd build
cmake -DCMAKE_INSTALL_PREFIX=~/install ..
make -j16
make install

これにてビルドができました。

root/artemisの環境

rootとartemisの環境設定ですが、ともにthisroot.sh、thisartemis.shにて設定できます。

そしてthisartemis.shの中にはthisroot.shを実行する箇所があるので原理的にはうまくいきます。

しかしデフォルトだと、うまく設定できていなかったので手動で書き足しておきます。

thisroot.shについてはrootと同じ場所にあるので、which rootで確認できます。

あとはsource ~/install/bin/thisartemis.shを実行するだけで起動できるようになります。

試しに~/github/artemis/exampleartemisを起動し、zoneコマンドでTCanvasが生成されたら正しくインストールできていると思います。