-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflake.nix
98 lines (80 loc) · 2.83 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
{
inputs = {
nixpkgs.url = "github:NixOS/nixpkgs/nixpkgs-unstable";
flake-utils.url = "github:numtide/flake-utils";
nixpkgs-ruby = {
url = "github:bobvanderlinden/nixpkgs-ruby";
inputs.nixpkgs.follows = "nixpkgs";
inputs.flake-utils.follows = "flake-utils";
};
};
outputs = { self, nixpkgs, flake-utils, nixpkgs-ruby }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = import nixpkgs {
system = system;
config.allowUnfree = true;
overlays = [nixpkgs-ruby.overlays.default];
};
rubyVersion = builtins.head (builtins.split "\n" (builtins.readFile ./.ruby-version));
ruby = pkgs."ruby-${rubyVersion}";
chrome = pkgs.writeShellScriptBin "chrome" ''
binary=$(find ${pkgs.google-chrome.outPath} -type f -name 'google-chrome-stable')
exec $binary "$@"
'';
postgresql = pkgs.postgresql_16;
pg-start = pkgs.writeScriptBin "pg-start" ''
${pg-environment-variables}
if [ ! -d $PGDATA ]; then
mkdir -p $PGDATA
${postgresql}/bin/initdb $PGDATA --auth=trust
fi
${postgresql}/bin/postgres -k $PGHOST -c listen_addresses=''' -c unix_socket_directories=$PGHOST
'';
pg-environment-variables = ''
export PGDATA=$PWD/.nix/postgres/data
export PGHOST=$PWD/.nix/postgres
export DB_USER=""
'';
postgresqlBuildFlags = with pkgs; [
"--with-pg-config=${lib.getDev postgresql_16}/bin/pg_config"
];
psychBuildFlags = with pkgs; [
"--with-libyaml-include=${libyaml.dev}/include"
"--with-libyaml-lib=${libyaml.out}/lib"
];
lint = pkgs.writeScriptBin "lint" ''
changed_files=$(git diff --name-only --diff-filter=ACM --merge-base main)
bundle exec rubocop --autocorrect-all --force-exclusion $changed_files Gemfile
'';
lint-all = pkgs.writeScriptBin "lint-all" ''
bundle exec rubocop --autocorrect-all
'';
in {
devShells.default = pkgs.mkShell {
shellHook = ''
export GEM_HOME=$PWD/.nix/ruby/$(${ruby}/bin/ruby -e "puts RUBY_VERSION")
mkdir -p $GEM_HOME
export GEM_PATH=$GEM_HOME
export PATH=$GEM_HOME/bin:$PATH
export BUNDLE_BUILD__PSYCH="${
builtins.concatStringsSep " " psychBuildFlags
}"
export BUNDLE_BUILD__PG="${
builtins.concatStringsSep " " postgresqlBuildFlags
}"
${pg-environment-variables}
'';
buildInputs = [
chrome
lint
lint-all
pg-start
pkgs.rufo
pkgs.yarn
postgresql
ruby
];
};
});
}