nix: add postgres and multiple system support
This commit is contained in:
parent
4bc159d698
commit
082e5bf210
4 changed files with 60 additions and 61 deletions
1
.gitignore
vendored
1
.gitignore
vendored
|
@ -1 +1,2 @@
|
||||||
/target/
|
/target/
|
||||||
|
/.db/
|
||||||
|
|
|
@ -1,15 +0,0 @@
|
||||||
version: "3"
|
|
||||||
|
|
||||||
services:
|
|
||||||
database:
|
|
||||||
image: "postgres:latest"
|
|
||||||
environment:
|
|
||||||
POSTGRES_DB: postgres
|
|
||||||
POSTGRES_PASSWORD: postgres
|
|
||||||
ports:
|
|
||||||
- 5432:5432
|
|
||||||
volumes:
|
|
||||||
- db_data:/var/lib/postgresql/data/
|
|
||||||
|
|
||||||
volumes:
|
|
||||||
db_data:
|
|
37
flake.lock
37
flake.lock
|
@ -5,11 +5,11 @@
|
||||||
"systems": "systems"
|
"systems": "systems"
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1681202837,
|
"lastModified": 1694529238,
|
||||||
"narHash": "sha256-H+Rh19JDwRtpVPAWp64F+rlEtxUWBAQW28eAi3SRSzg=",
|
"narHash": "sha256-zsNZZGTGnMOf9YpHKJqMSsa0dXbfmxeoJ7xHlrt+xmY=",
|
||||||
"owner": "numtide",
|
"owner": "numtide",
|
||||||
"repo": "flake-utils",
|
"repo": "flake-utils",
|
||||||
"rev": "cfacdce06f30d2b68473a46042957675eebb3401",
|
"rev": "ff7b65b44d01cf9ba6a71320833626af21126384",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
@ -34,39 +34,28 @@
|
||||||
"type": "github"
|
"type": "github"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"nixpkgs_2": {
|
|
||||||
"locked": {
|
|
||||||
"lastModified": 1681358109,
|
|
||||||
"narHash": "sha256-eKyxW4OohHQx9Urxi7TQlFBTDWII+F+x2hklDOQPB50=",
|
|
||||||
"owner": "NixOS",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"rev": "96ba1c52e54e74c3197f4d43026b3f3d92e83ff9",
|
|
||||||
"type": "github"
|
|
||||||
},
|
|
||||||
"original": {
|
|
||||||
"owner": "NixOS",
|
|
||||||
"ref": "nixpkgs-unstable",
|
|
||||||
"repo": "nixpkgs",
|
|
||||||
"type": "github"
|
|
||||||
}
|
|
||||||
},
|
|
||||||
"root": {
|
"root": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
|
"flake-utils": "flake-utils",
|
||||||
"nixpkgs": "nixpkgs",
|
"nixpkgs": "nixpkgs",
|
||||||
"rust-overlay": "rust-overlay"
|
"rust-overlay": "rust-overlay"
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
"rust-overlay": {
|
"rust-overlay": {
|
||||||
"inputs": {
|
"inputs": {
|
||||||
"flake-utils": "flake-utils",
|
"flake-utils": [
|
||||||
"nixpkgs": "nixpkgs_2"
|
"flake-utils"
|
||||||
|
],
|
||||||
|
"nixpkgs": [
|
||||||
|
"nixpkgs"
|
||||||
|
]
|
||||||
},
|
},
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1696039808,
|
"lastModified": 1696126582,
|
||||||
"narHash": "sha256-7TbAr9LskWG6ISPhUdyp6zHboT7FsFrME5QsWKybPTA=",
|
"narHash": "sha256-uo4cn/d2rHPy/fpKZKFBOaVO531zs/Doxz43imrpqZM=",
|
||||||
"owner": "oxalica",
|
"owner": "oxalica",
|
||||||
"repo": "rust-overlay",
|
"repo": "rust-overlay",
|
||||||
"rev": "a4c3c904ab29e04a20d3a6da6626d66030385773",
|
"rev": "fc6fe50d9a4540a1111731baaa00f207301fdeb7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
44
flake.nix
44
flake.nix
|
@ -3,13 +3,17 @@
|
||||||
|
|
||||||
inputs = {
|
inputs = {
|
||||||
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
|
||||||
rust-overlay.url = "github:oxalica/rust-overlay";
|
flake-utils.url = "github:numtide/flake-utils";
|
||||||
|
rust-overlay = {
|
||||||
|
url = "github:oxalica/rust-overlay";
|
||||||
|
inputs.nixpkgs.follows = "nixpkgs";
|
||||||
|
inputs.flake-utils.follows = "flake-utils";
|
||||||
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
outputs = { self, nixpkgs, rust-overlay }:
|
outputs = { self, nixpkgs, flake-utils, rust-overlay }:
|
||||||
let
|
let
|
||||||
#supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
supportedSystems = [ "x86_64-linux" "aarch64-linux" "x86_64-darwin" "aarch64-darwin" ];
|
||||||
system = "x86_64-linux";
|
|
||||||
|
|
||||||
overlays = [
|
overlays = [
|
||||||
(final: prev: {
|
(final: prev: {
|
||||||
|
@ -20,24 +24,44 @@
|
||||||
|
|
||||||
(import rust-overlay)
|
(import rust-overlay)
|
||||||
];
|
];
|
||||||
|
in
|
||||||
pkgs = import nixpkgs {
|
flake-utils.lib.eachSystem supportedSystems (system:
|
||||||
inherit system overlays;
|
let
|
||||||
};
|
pkgs = import nixpkgs { inherit system overlays; };
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
devShells.${system}.default = with pkgs; mkShell {
|
devShells.default = with pkgs; mkShell {
|
||||||
packages = [
|
packages = [
|
||||||
elixir
|
elixir
|
||||||
elixir-ls
|
elixir-ls
|
||||||
protobuf
|
protobuf
|
||||||
protoc-gen-elixir
|
protoc-gen-elixir
|
||||||
rust-bin.stable.latest.default
|
rust-bin.stable.latest.default
|
||||||
|
postgresql
|
||||||
] ++ lib.optionals stdenv.isLinux [ inotify-tools ];
|
] ++ lib.optionals stdenv.isLinux [ inotify-tools ];
|
||||||
|
|
||||||
inputsFrom = [
|
inputsFrom = [
|
||||||
protoc-gen-elixir
|
protoc-gen-elixir
|
||||||
];
|
];
|
||||||
|
|
||||||
|
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
|
||||||
|
'';
|
||||||
};
|
};
|
||||||
};
|
});
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue