Skip to content

Commit

Permalink
refactor: apply nixfmt
Browse files Browse the repository at this point in the history
  • Loading branch information
mirkolenz committed Apr 15, 2024
1 parent 2bf1d2e commit f2cdb2a
Show file tree
Hide file tree
Showing 22 changed files with 258 additions and 247 deletions.
21 changes: 12 additions & 9 deletions flake-modules/config.nix
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@
system,
lib',
...
}: let
}:
let
specialArgs = {
inherit inputs self lib';
};
in {
in
{
flake = {
systemConfigs.default = inputs.system-manager.lib.makeSystemConfig {
extraSpecialArgs = specialArgs;
Expand All @@ -27,13 +29,14 @@ in {
inherit system pkgs specialArgs;
modules = [
../modules
({modulesPath, ...}: {
# use virtual machine profile, otherwise file systems need to be defined
imports = [
"${modulesPath}/virtualisation/lxc-container.nix"
];
system.stateVersion = "23.11";
})
(
{ modulesPath, ... }:
{
# use virtual machine profile, otherwise file systems need to be defined
imports = [ "${modulesPath}/virtualisation/lxc-container.nix" ];
system.stateVersion = "23.11";
}
)
];
};
};
Expand Down
24 changes: 13 additions & 11 deletions flake-modules/default.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
lib,
lib',
...
}: let
}:
let
system = "x86_64-linux";
pkgs = import inputs.nixpkgs {
inherit system;
Expand All @@ -13,24 +14,25 @@
};
overlays = lib.singleton (
final: prev: {
apptainer = prev.apptainer.override {
enableNvidiaContainerCli = false;
};
apptainer = prev.apptainer.override { enableNvidiaContainerCli = false; };
system-manager = inputs.system-manager.packages.${system}.default;
}
);
};
in {
in
{
imports = lib'.flocken.getModules ./.;
systems = lib.singleton system;
_module.args = {
inherit system pkgs;
};
perSystem = {config, ...}: {
_module.args = {
inherit pkgs;
perSystem =
{ config, ... }:
{
_module.args = {
inherit pkgs;
};
packages.default = config.packages.install;
checks = config.packages;
};
packages.default = config.packages.install;
checks = config.packages;
};
}
23 changes: 9 additions & 14 deletions flake-modules/images.nix
Original file line number Diff line number Diff line change
@@ -1,17 +1,12 @@
{...}: {
perSystem = {
config,
pkgs,
...
}: {
packages = {
image-base = pkgs.callPackage ../images/base.nix {};
image-jupyter = pkgs.callPackage ../images/jupyter.nix {
base = config.packages.image-base;
};
image-poetry = pkgs.callPackage ../images/poetry.nix {
base = config.packages.image-base;
{ ... }:
{
perSystem =
{ config, pkgs, ... }:
{
packages = {
image-base = pkgs.callPackage ../images/base.nix { };
image-jupyter = pkgs.callPackage ../images/jupyter.nix { base = config.packages.image-base; };
image-poetry = pkgs.callPackage ../images/poetry.nix { base = config.packages.image-base; };
};
};
};
}
92 changes: 44 additions & 48 deletions flake-modules/scripts.nix
Original file line number Diff line number Diff line change
@@ -1,52 +1,48 @@
{ lib, self, ... }:
{
lib,
self,
...
}: {
perSystem = {
pkgs,
config,
...
}: let
manager = lib.getExe' pkgs.system-manager "system-manager";
in {
packages = {
manager = pkgs.system-manager;
install = pkgs.writeShellApplication {
name = "system-manager-rebuild";
text = ''
set -x #echo on
exec ${manager} "''${1:-switch}" --flake ${self} "''${@:2}"
'';
};
uninstall = pkgs.writeShellApplication {
name = "system-manager-uninstall";
text = ''
set -x #echo on
exec ${manager} deactivate "''$@"
'';
};
setup = pkgs.writeShellApplication {
name = "system-manager-setup";
text = ''
# only root possible
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root" >&2
exit 1
fi
set -x #echo on
# set up nix
cp -f ${../etc/nix.conf} /etc/nix/nix.conf
systemctl restart nix-daemon
# set up cuda support for oci engines like podman
nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml
chmod -R 755 /etc/cdi
# set compute mode to exclusive process (https://stackoverflow.com/a/50056586)
nvidia-smi -c 3
# disable default motd
chmod -x /etc/update-motd.d/*
'';
perSystem =
{ pkgs, config, ... }:
let
manager = lib.getExe' pkgs.system-manager "system-manager";
in
{
packages = {
manager = pkgs.system-manager;
install = pkgs.writeShellApplication {
name = "system-manager-rebuild";
text = ''
set -x #echo on
exec ${manager} "''${1:-switch}" --flake ${self} "''${@:2}"
'';
};
uninstall = pkgs.writeShellApplication {
name = "system-manager-uninstall";
text = ''
set -x #echo on
exec ${manager} deactivate "''$@"
'';
};
setup = pkgs.writeShellApplication {
name = "system-manager-setup";
text = ''
# only root possible
if [ "$(id -u)" -ne 0 ]; then
echo "This script must be run as root" >&2
exit 1
fi
set -x #echo on
# set up nix
cp -f ${../etc/nix.conf} /etc/nix/nix.conf
systemctl restart nix-daemon
# set up cuda support for oci engines like podman
nvidia-ctk cdi generate --output=/etc/cdi/nvidia.yaml
chmod -R 755 /etc/cdi
# set compute mode to exclusive process (https://stackoverflow.com/a/50056586)
nvidia-smi -c 3
# disable default motd
chmod -x /etc/update-motd.d/*
'';
};
};
};
};
}
17 changes: 8 additions & 9 deletions flake.nix
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,13 @@
};
};

outputs = inputs @ {
self,
nixpkgs,
flake-parts,
...
}:
outputs =
inputs@{
self,
nixpkgs,
flake-parts,
...
}:
flake-parts.lib.mkFlake {
inherit inputs;
specialArgs = {
Expand All @@ -30,7 +31,5 @@
flocken = inputs.flocken.lib;
};
};
} {
imports = [./flake-modules];
};
} { imports = [ ./flake-modules ]; };
}
18 changes: 11 additions & 7 deletions images/base.nix
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,10 @@
gcc,
nix-ld,
name ? "base",
contents ? [],
entrypoint ? ["/bin/sh"],
cmd ? [],
env ? {},
contents ? [ ],
entrypoint ? [ "/bin/sh" ],
cmd ? [ ],
env ? { },
}:
dockerTools.streamLayeredImage {
inherit name;
Expand All @@ -28,7 +28,8 @@ dockerTools.streamLayeredImage {
# https://unix.stackexchange.com/a/415028
# the existing LD_LIBRARY_PATH is only appended if it is not empty
exportLibraryPath = ''export LD_LIBRARY_PATH="''${NIX_LD_LIBRARY_PATH}''${LD_LIBRARY_PATH:+:''${LD_LIBRARY_PATH}}"'';
wrapLibraryPath = pkg:
wrapLibraryPath =
pkg:
writeShellScriptBin (lib.getName pkg) ''
${exportLibraryPath}
exec ${lib.getExe pkg} "$@"
Expand All @@ -50,7 +51,7 @@ dockerTools.streamLayeredImage {
(lib.getBin gcc)
# https://github.com/Mic92/nix-ld/wiki/Using-with-docker-images
# https://github.com/Mic92/nix-ld/issues/60
(runCommand "nix-ld" {} ''
(runCommand "nix-ld" { } ''
install -D -m755 ${nix-ld}/libexec/nix-ld $out/lib64/$(basename ${stdenv.cc.bintools.dynamicLinker})
'')
]
Expand All @@ -64,7 +65,10 @@ dockerTools.streamLayeredImage {
inherit entrypoint cmd;
env = lib.mapAttrsToList (k: v: "${k}=${v}") (
{
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [stdenv.cc.cc zlib];
NIX_LD_LIBRARY_PATH = lib.makeLibraryPath [
stdenv.cc.cc
zlib
];
NIX_LD = stdenv.cc.bintools.dynamicLinker;
SHELL = "/bin/sh";
PIP_DISABLE_PIP_VERSION_CHECK = "1";
Expand Down
45 changes: 24 additions & 21 deletions images/jupyter.nix
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
writeShellScriptBin,
python3,
base,
}: let
}:
let
venvPath = "./.venv";

venvSetup = writeShellScriptBin "venv" ''
Expand All @@ -26,30 +27,32 @@
fi
'';

jupyterArgs = lib.cli.toGNUCommandLineShell {} {
jupyterArgs = lib.cli.toGNUCommandLineShell { } {
ip = "0.0.0.0";
allow-root = true;
no-browser = true;
"ServerApp.terminado_settings" = ''shell_command=["/bin/sh"]'';
};

entrypoint = base.passthru.wrapLibraryPath (writeShellScriptBin "entrypoint" ''
${lib.getExe venvSetup}
exec ${venvPath}/bin/jupyter lab ${jupyterArgs} "$@"
'');
entrypoint = base.passthru.wrapLibraryPath (
writeShellScriptBin "entrypoint" ''
${lib.getExe venvSetup}
exec ${venvPath}/bin/jupyter lab ${jupyterArgs} "$@"
''
);
in
base.override {
entrypoint = [(lib.getExe entrypoint)];
env = {
VIRTUAL_ENV = venvPath;
PATH = lib.concatStringsSep ":" [
"${venvPath}/bin"
"/usr/local/sbin"
"/usr/local/bin"
"/usr/sbin"
"/usr/bin"
"/sbin"
"/bin"
];
};
}
base.override {
entrypoint = [ (lib.getExe entrypoint) ];
env = {
VIRTUAL_ENV = venvPath;
PATH = lib.concatStringsSep ":" [
"${venvPath}/bin"
"/usr/local/sbin"
"/usr/local/bin"
"/usr/sbin"
"/usr/bin"
"/sbin"
"/bin"
];
};
}
21 changes: 10 additions & 11 deletions images/poetry.nix
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,15 @@
lib,
poetry,
base,
}: let
}:
let
poetryWrapper = base.passthru.wrapLibraryPath poetry;
in
base.override {
name = "poetry";
contents = [
poetryWrapper
];
entrypoint = [(lib.getExe poetryWrapper)];
env = {
POETRY_VIRTUALENVS_IN_PROJECT = "1";
};
}
base.override {
name = "poetry";
contents = [ poetryWrapper ];
entrypoint = [ (lib.getExe poetryWrapper) ];
env = {
POETRY_VIRTUALENVS_IN_PROJECT = "1";
};
}
6 changes: 4 additions & 2 deletions modules/apptainer.nix
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
lib,
inputs,
...
}: let
}:
let
apptainer = pkgs.writeShellApplication {
name = "apptainer";
text = ''
Expand All @@ -16,7 +17,8 @@
exec ${lib.getExe pkgs.apptainer} "$@"
'';
};
in {
in
{
environment = {
systemPackages = [
apptainer
Expand Down
Loading

0 comments on commit f2cdb2a

Please sign in to comment.