nix: simpler refactor into files, add scripts
This commit is contained in:
parent
082e5bf210
commit
f1c784c79c
7 changed files with 69 additions and 53 deletions
1
.envrc
Normal file
1
.envrc
Normal file
|
@ -0,0 +1 @@
|
||||||
|
use flake
|
2
.gitignore
vendored
2
.gitignore
vendored
|
@ -1,2 +1,4 @@
|
||||||
/target/
|
/target/
|
||||||
/.db/
|
/.db/
|
||||||
|
/.vagrant/
|
||||||
|
/.direnv/
|
||||||
|
|
|
@ -51,11 +51,11 @@
|
||||||
]
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1696126582,
|
"lastModified": 1696644659,
|
||||||
"narHash": "sha256-uo4cn/d2rHPy/fpKZKFBOaVO531zs/Doxz43imrpqZM=",
|
"narHash": "sha256-l/DgT519At8HhXDQHz3+H8AjaEbrsb7Xkqgj+JNHV6k=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "fc6fe50d9a4540a1111731baaa00f207301fdeb7",
|
"rev": "126829788e99c188be4eeb805f144d73d8a00f2c",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
69
flake.nix
69
flake.nix
|
@ -11,57 +11,26 @@
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
|
outputs = { self, nixpkgs, flake-utils, rust-overlay }: flake-utils.lib.eachDefaultSystem (system:
|
||||||
let
|
let
|
||||||
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
pkgs = import nixpkgs { inherit system overlays; };
|
||||||
|
overlays = [ (import ./nix/overlay.nix) (import rust-overlay) ];
|
||||||
overlays = [
|
scripts = pkgs.callPackage ./nix/scripts.nix { };
|
||||||
(final: prev: {
|
|
||||||
elixir = prev.beam.packages.erlang_26.elixir_1_15;
|
|
||||||
elixir-ls = prev.beam.packages.erlang_26.elixir-ls.override { elixir = final.elixir; };
|
|
||||||
protoc-gen-elixir = prev.callPackage ./protoc-gen-elixir.nix { elixir = final.elixir; };
|
|
||||||
})
|
|
||||||
|
|
||||||
(import rust-overlay)
|
|
||||||
];
|
|
||||||
in
|
in
|
||||||
flake-utils.lib.eachSystem supportedSystems (system:
|
{
|
||||||
let
|
devShells.default = with pkgs; mkShell {
|
||||||
pkgs = import nixpkgs { inherit system overlays; };
|
packages = [
|
||||||
in
|
elixir
|
||||||
{
|
elixir-ls
|
||||||
devShells.default = with pkgs; mkShell {
|
rustToolchain
|
||||||
packages = [
|
protobuf
|
||||||
elixir
|
protoc-gen-elixir
|
||||||
elixir-ls
|
scripts.prymn_db
|
||||||
protobuf
|
] ++ lib.optionals stdenv.isLinux [ inotify-tools ];
|
||||||
protoc-gen-elixir
|
|
||||||
rust-bin.stable.latest.default
|
|
||||||
postgresql
|
|
||||||
] ++ lib.optionals stdenv.isLinux [ inotify-tools ];
|
|
||||||
|
|
||||||
inputsFrom = [
|
shellHook = ''
|
||||||
protoc-gen-elixir
|
export PROJECT_ROOT_DIR="$PWD"
|
||||||
];
|
'';
|
||||||
|
};
|
||||||
shellHook = ''
|
});
|
||||||
export PGDATA=$PWD/.db
|
|
||||||
export PGHOST=/tmp
|
|
||||||
export DB_LOG=$PWD/.db/log
|
|
||||||
|
|
||||||
if [ ! -d $PGDATA ]; then
|
|
||||||
initdb $PGDATA --auth=trust
|
|
||||||
fi
|
|
||||||
|
|
||||||
if ! pg_ctl status >/dev/null; then
|
|
||||||
pg_ctl start -l $DB_LOG -o "-c unix_socket_directories=$PGHOST"
|
|
||||||
fi
|
|
||||||
|
|
||||||
user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'")
|
|
||||||
if [ $user_exists != "1" ]; then
|
|
||||||
createuser -s -h $PGHOST postgres
|
|
||||||
fi
|
|
||||||
'';
|
|
||||||
};
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
11
nix/overlay.nix
Normal file
11
nix/overlay.nix
Normal file
|
@ -0,0 +1,11 @@
|
||||||
|
final: prev: {
|
||||||
|
rustToolchain = final.rust-bin.stable.latest.default.override {
|
||||||
|
targets = [ "x86_64-unknown-linux-musl" "aarch64-unknown-linux-musl" ];
|
||||||
|
};
|
||||||
|
|
||||||
|
elixir = prev.beam.packages.erlang_26.elixir_1_15;
|
||||||
|
|
||||||
|
elixir-ls = prev.beam.packages.erlang_26.elixir-ls.override { elixir = final.elixir; };
|
||||||
|
|
||||||
|
protoc-gen-elixir = prev.callPackage ./protoc-gen-elixir.nix { elixir = final.elixir; };
|
||||||
|
}
|
33
nix/scripts.nix
Normal file
33
nix/scripts.nix
Normal file
|
@ -0,0 +1,33 @@
|
||||||
|
{ writeShellApplication, postgresql, ... }:
|
||||||
|
|
||||||
|
{
|
||||||
|
prymn_db = writeShellApplication {
|
||||||
|
name = "prymn_db";
|
||||||
|
|
||||||
|
runtimeInputs = [ postgresql ];
|
||||||
|
|
||||||
|
text = ''
|
||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -e
|
||||||
|
|
||||||
|
export PGDATA=$PROJECT_ROOT_DIR/.db
|
||||||
|
export PGHOST=/tmp
|
||||||
|
export DB_LOG=$PROJECT_ROOT_DIR/.db/log
|
||||||
|
|
||||||
|
if [ ! -d "$PGDATA" ]; then
|
||||||
|
initdb "$PGDATA" --auth=trust
|
||||||
|
fi
|
||||||
|
|
||||||
|
if ! pg_ctl status >/dev/null; then
|
||||||
|
pg_ctl start -l "$DB_LOG" -o "-c unix_socket_directories=$PGHOST"
|
||||||
|
echo "starting your dev database..."
|
||||||
|
fi
|
||||||
|
|
||||||
|
user_exists=$(psql --csv -t -d postgres -c "SELECT count(*) FROM pg_user WHERE usename='postgres'")
|
||||||
|
if [ "$user_exists" != "1" ]; then
|
||||||
|
createuser -s -h "$PGHOST" postgres
|
||||||
|
fi
|
||||||
|
'';
|
||||||
|
};
|
||||||
|
}
|
Loading…
Reference in a new issue