Skip to content

Commit

Permalink
🎨 Format nix files
Browse files Browse the repository at this point in the history
  • Loading branch information
phlmn committed Jan 19, 2025
1 parent 5470bf0 commit b8ba1ef
Show file tree
Hide file tree
Showing 4 changed files with 166 additions and 129 deletions.
173 changes: 97 additions & 76 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@
flake-utils.url = "github:numtide/flake-utils";
};

outputs = {
outputs =
{
nixpkgs,
uv2nix,
pyproject-nix,
Expand All @@ -38,7 +39,8 @@
pythonPkgName = "python311";
in
{
overlays.default = (final: prev:
overlays.default = (
final: prev:
let
pkgs = import nixpkgs {
system = final.system;
Expand All @@ -48,11 +50,25 @@
in
{
transcribee-worker = import ./nix/pkgs/worker.nix {
inherit pkgs lib python uv2nix pyproject-nix pyproject-build-systems;
inherit
pkgs
lib
python
uv2nix
pyproject-nix
pyproject-build-systems
;
};

transcribee-backend = import ./nix/pkgs/backend.nix {
inherit pkgs lib python uv2nix pyproject-nix pyproject-build-systems;
inherit
pkgs
lib
python
uv2nix
pyproject-nix
pyproject-build-systems
;
};

transcribee-frontend = import ./nix/pkgs/frontend.nix {
Expand All @@ -63,91 +79,96 @@
commitDate = self.lastModified;
};
};
});
}
);

nixosModules.default = {
nixpkgs.overlays = [ self.overlays.default ];
};
} //
(flake-utils.lib.eachDefaultSystem
(system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
python = pkgs."${pythonPkgName}";

ld_packages = [
pkgs.file # provides libmagic

# for ctranslate2
pkgs.stdenv.cc.cc.lib
}
// (flake-utils.lib.eachDefaultSystem (
system:
let
pkgs = import nixpkgs {
inherit system;
overlays = [ self.overlays.default ];
};
python = pkgs."${pythonPkgName}";

ld_packages = [
pkgs.file # provides libmagic

# for ctranslate2
pkgs.stdenv.cc.cc.lib
];
in
{
packages = {
backend = pkgs.transcribee-backend;
worker = pkgs.transcribee-worker;
frontend = pkgs.transcribee-frontend;
};

formatter = pkgs.nixfmt-rfc-style;

devShells.default = pkgs.mkShell {
packages = [
python
pkgs.uv
python.pkgs.black
pkgs.poethepoet

pkgs.overmind
pkgs.wait4x
pkgs.pre-commit

pkgs.nodejs_20

# nix tooling
pkgs.nixpkgs-fmt

# required by whispercppy
pkgs.cmake

# required by pre-commit
pkgs.git
pkgs.ruff

# required by psycopg2
pkgs.openssl

pkgs.ffmpeg

# for automerge-py
pkgs.libiconv
pkgs.rustc
pkgs.cargo

pkgs.icu.dev

# Our database
pkgs.postgresql_14

# Our database2 ?
pkgs.redis

pkgs.glibcLocales
];
in
{
packages = {
backend = pkgs.transcribee-backend;
worker = pkgs.transcribee-worker;
frontend = pkgs.transcribee-frontend;
};

devShells.default = pkgs.mkShell {
packages = [
python
pkgs.uv
python.pkgs.black
pkgs.poethepoet

pkgs.overmind
pkgs.wait4x
pkgs.pre-commit

pkgs.nodejs_20

# nix tooling
pkgs.nixpkgs-fmt

# required by whispercppy
pkgs.cmake

# required by pre-commit
pkgs.git
pkgs.ruff

# required by psycopg2
pkgs.openssl

pkgs.ffmpeg

# for automerge-py
pkgs.libiconv
pkgs.rustc
pkgs.cargo

pkgs.icu.dev

# Our database
pkgs.postgresql_14

# Our database2 ?
pkgs.redis

pkgs.glibcLocales
];

shellHook = ''
shellHook =
''
unset PYTHONPATH
export UV_PYTHON_DOWNLOADS=never
export TRANSCRIBEE_DYLD_LIBRARY_PATH=${pkgs.lib.makeLibraryPath ld_packages}
export LD_LIBRARY_PATH=$LD_SEARCH_PATH:$TRANSCRIBEE_DYLD_LIBRARY_PATH
'' + pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
''
+ pkgs.lib.optionalString pkgs.stdenv.isDarwin ''
export CPPFLAGS="-I${pkgs.libcxx.dev}/include/c++/v1"
# `dyld` needs to find the libraries
export DYLD_LIBRARY_PATH=$LD_LIBRARY_PATH:$DYLD_LIBRARY_PATH
'';
};
}
));
};
}
));
}
5 changes: 3 additions & 2 deletions nix/pkgs/backend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ let
pkgs.postgresql_14
];

buildInputs = (old.buildInputs or []) ++ [
buildInputs = (old.buildInputs or [ ]) ++ [
pkgs.openssl
];
});
Expand All @@ -45,4 +45,5 @@ let
]
);

in pythonSet.mkVirtualEnv "transcribee-backend-env" workspace.deps.default
in
pythonSet.mkVirtualEnv "transcribee-backend-env" workspace.deps.default
112 changes: 63 additions & 49 deletions nix/pkgs/frontend.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,58 +4,72 @@
versionInfo,
...
}:
pkgs.buildNpmPackage (lib.fix (self: {
pname = "transcribee-frontend";
version = "0.1.0";
src = ../../frontend;
pkgs.buildNpmPackage (
lib.fix (self: {
pname = "transcribee-frontend";
version = "0.1.0";
src = ../../frontend;

nativeBuildInputs = [ pkgs.git ];
nativeBuildInputs = [ pkgs.git ];

npmDeps = pkgs.importNpmLock {
npmRoot = self.src;
packageSourceOverrides = let
gitDeps = (lib.attrsets.filterAttrs (name: pkgInfo:
(lib.hasPrefix "node_modules/" name)
&& (lib.hasPrefix "git" (pkgInfo.resolved or "")))
(lib.importJSON (self.src + "/package-lock.json")).packages);
in lib.attrsets.mapAttrs (name: pkgInfo:
let
src = builtins.fetchGit {
url = "https" + lib.removePrefix "git+ssh" pkgInfo.resolved;
rev = lib.last (lib.splitString "#" pkgInfo.resolved);
allRefs = true;
};
pname = lib.removePrefix "node_modules/" name;
thePkg = pkgs.buildNpmPackage {
inherit src pname;
version = pkgInfo.version;
npmDeps = pkgs.importNpmLock { npmRoot = src; };
npmConfigHook = pkgs.importNpmLock.npmConfigHook;
installPhase = ''
mkdir $out
npm pack --pack-destination=$out
mv $out/*.tgz $out/package.tgz
'';
};
in "${thePkg}/package.tgz") gitDeps;
};
npmDeps = pkgs.importNpmLock {
npmRoot = self.src;
packageSourceOverrides =
let
gitDeps = (
lib.attrsets.filterAttrs (
name: pkgInfo:
(lib.hasPrefix "node_modules/" name) && (lib.hasPrefix "git" (pkgInfo.resolved or ""))
) (lib.importJSON (self.src + "/package-lock.json")).packages
);
in
lib.attrsets.mapAttrs (
name: pkgInfo:
let
src = builtins.fetchGit {
url = "https" + lib.removePrefix "git+ssh" pkgInfo.resolved;
rev = lib.last (lib.splitString "#" pkgInfo.resolved);
allRefs = true;
};
pname = lib.removePrefix "node_modules/" name;
thePkg = pkgs.buildNpmPackage {
inherit src pname;
version = pkgInfo.version;
npmDeps = pkgs.importNpmLock { npmRoot = src; };
npmConfigHook = pkgs.importNpmLock.npmConfigHook;
installPhase = ''
mkdir $out
npm pack --pack-destination=$out
mv $out/*.tgz $out/package.tgz
'';
};
in
"${thePkg}/package.tgz"
) gitDeps;
};

preBuild = let
versionExports = ([ ]
++ (lib.optional (versionInfo ? commitHash) ''export COMMIT_HASH="${versionInfo.commitHash}"'')
++ (lib.optional (versionInfo ? commitDate) ''export COMMIT_DATE="$(date -d @${builtins.toString versionInfo.commitDate} --iso-8601=s)"'')
);
in ''
${lib.concatStringsSep "\n" versionExports}
'';
preBuild =
let
versionExports = (
[ ]
++ (lib.optional (versionInfo ? commitHash) ''export COMMIT_HASH="${versionInfo.commitHash}"'')
++ (lib.optional (
versionInfo ? commitDate
) ''export COMMIT_DATE="$(date -d @${builtins.toString versionInfo.commitDate} --iso-8601=s)"'')
);
in
''
${lib.concatStringsSep "\n" versionExports}
'';

installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';
installPhase = ''
runHook preInstall
cp -r dist $out
runHook postInstall
'';

npmBuildScript = "build";
npmBuildScript = "build";

npmConfigHook = pkgs.importNpmLock.npmConfigHook;
}))
npmConfigHook = pkgs.importNpmLock.npmConfigHook;
})
)
5 changes: 3 additions & 2 deletions nix/pkgs/worker.nix
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ let
pyicu = prev.pyicu.overrideAttrs (old: {
nativeBuildInputs = old.nativeBuildInputs ++ [
pkgs.icu.dev
(final.resolveBuildSystem {})
(final.resolveBuildSystem { })
];
});
};
Expand All @@ -58,4 +58,5 @@ let
]
);

in pythonSet.mkVirtualEnv "transcribee-worker-env" workspace.deps.default
in
pythonSet.mkVirtualEnv "transcribee-worker-env" workspace.deps.default

0 comments on commit b8ba1ef

Please sign in to comment.