-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
flake.nix
155 lines (144 loc) · 5.11 KB
/
flake.nix
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
{
description = "creates a dev container for triplestore";
inputs = {
flake-utils.url = "github:numtide/flake-utils"; # Utility functions for Nix flakes
nixpkgs.url = "github:NixOS/nixpkgs/nixos-unstable"; # Main Nix package repository
rust-overlay.url = "github:oxalica/rust-overlay?rev=260ff391290a2b23958d04db0d3e7015c8417401";
rust-overlay.inputs.nixpkgs.follows = "nixpkgs";
rust-overlay.inputs.flake-utils.follows = "flake-utils";
};
outputs = { self, flake-utils, nixpkgs, rust-overlay, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ rust-overlay.overlays.default];
};
# This is needed since VSCode Devcontainers need the following files in order to function.
baseInfo = with pkgs; [
# Set up shadow file with user information
(writeTextDir "etc/shadow" ''
root:!x:::::::
'')
# Set up passwd file with user information
(writeTextDir "etc/passwd" ''
root:x:0:0::/root:${runtimeShell}
'')
# Set up group file with user information
(writeTextDir "etc/group" ''
root:x:0:
'')
# Set up gshadow file with user information
(writeTextDir "etc/gshadow" ''
root:x::
'')
# Set up os-release file with NixOS information, since it is nix the check requirements
# step for the dev container creation will skip.
(writeTextDir "etc/os-release" ''
NAME="NixOS"
ID=nixos
VERSION="unstable"
VERSION_CODENAME=unstable
PRETTY_NAME="NixOS (unstable)"
HOME_URL="https://nixos.org/"
SUPPORT_URL="https://nixos.org/nixos/manual/"
BUG_REPORT_URL="https://github.com/NixOS/nixpkgs/issues"
'')
];
myEnv = pkgs.buildEnv {
name = "my-env";
paths = with pkgs; [
# -- Basic Required Files --
bash # Basic bash to run bare essnetial code
coreutils-full # Essential GNU utilities (ls, cat, etc.)
# -- Needed for VSCode dev container --
gnutar # GNU version of tar for archiving
gzip # Compression utility
gnugrep # GNU version of grep for searching text
gnused # GNU version of sed for text processing
pkgs.stdenv.cc.cc.lib # Standard C library needed for linking C++ programs
# -- OpenSSL --
cacert
openssl
openssl.dev
# -- Development tools --
code-server
which
curl
lsof
strace
ripgrep
tree
tree-sitter
nix
git
fzf
fd
eza
deterministic-uname
findutils
gnugrep
getent
gawk
ps
# -- Compilers, Etc. --
gcc
grc
cmake
gnumake
libclang
python3
# -- Rust --
(lib.meta.hiPrio rust-bin.nightly.latest.default)
rustup
pkg-config
];
pathsToLink = [
"/bin"
"/etc/ssl/certs"
];
};
in
{
packages.default = pkgs.dockerTools.buildImage {
name = "triplestore-dev";
tag = "latest";
copyToRoot = [ myEnv ] ++ baseInfo;
config = {
WorkingDir = "/workspace";
Env = [
# Add certificates to allow for cargo to download files
"SSL_CERT_FILE=/etc/ssl/certs/ca-bundle.crt"
"SSL_CERT_DIR=/etc/ssl/certs"
"CARGO_HTTP_CAINFO=/etc/ssl/certs/ca-bundle.crt"
"CC=gcc" # Set GCC as the default C compiler
"CXX=g++" # Set G++ as the default C++ compiler
# Library path for dynamic linking
"LD_LIBRARY_PATH=${pkgs.stdenv.cc.cc.lib}/lib"
# Add openssl to pkg config to ensure that it loads for cargo build
"PKG_CONFIG_PATH=${pkgs.openssl.dev}/lib/pkgconfig"
# Setting PATH to include essential binaries
"PATH=/bin:/usr/bin:${myEnv}/bin:/root/.cargo/bin"
"USER=root" # Setting user to root
"COREUTILS=${pkgs.coreutils-full}"
"CMAKE=/bin/cmake"
"CMAKE_MAKE_PROGRAM=/bin/make"
"LIBCLANG_PATH=${pkgs.libclang.lib}/lib/"
];
Volumes = { };
Cmd = [ "/bin/bash" ];
};
extraCommands = ''
# Link the env binary (needed for the check requirements script)
mkdir -p usr/bin/
ln -n bin/env usr/bin/env
# Link the dynamic linker/loader (needed for Node within vscode server)
mkdir -p lib64
ln -s ${pkgs.glibc}/lib/ld-linux-x86-64.so.2 lib64/ld-linux-x86-64.so.2
# Create /tmp dir
mkdir -p tmp
'';
};
}
);
}