This commit is contained in:
Borodinov Ilya 2024-10-21 23:09:12 +03:00
commit 643f58adcf
Signed by: noth
GPG key ID: 75503B2EF596D1BD
4 changed files with 190 additions and 0 deletions

13
flake.nix Normal file
View file

@ -0,0 +1,13 @@
{
description = "ГОЙДА_OS - переделка NixOS на runit";
inputs = {
nixpkgs.url = "github:nixos/nixpkgs/nixos-unstable";
};
outputs = { self, nixpkgs }: {
lib = {
makeSystem = import ./make-system.nix { inherit nixpkgs; };
};
};
}

66
make-system.nix Normal file
View file

@ -0,0 +1,66 @@
{ nixpkgs }:
{
modules,
system ? builtins.currentSystem,
platform ? null,
crossSystem ? null,
}:
let
pkgs = import nixpkgs {
inherit system;
platform = platform;
config = { };
};
pkgsModule =
{ config, ... }:
{
_file = ./default.nix;
key = ./default.nix;
config = {
nixpkgs.pkgs = (
import nixpkgs {
inherit system crossSystem;
config = config.nixpkgs.config;
overlays = config.nixpkgs.overlays;
}
);
nixpkgs.localSystem =
{
inherit system;
}
// pkgs.lib.optionalAttrs (crossSystem != null) {
inherit crossSystem;
};
};
};
baseModules = [
./base.nix
./system-path.nix
./stage-1.nix
./stage-2.nix
./runit.nix
(nixpkgs + "/nixos/modules/system/etc/etc.nix")
(nixpkgs + "/nixos/modules/system/activation/activation-script.nix")
(nixpkgs + "/nixos/modules/misc/nixpkgs.nix")
(nixpkgs + "/nixos/modules/system/boot/kernel.nix")
(nixpkgs + "/nixos/modules/misc/assertions.nix")
(nixpkgs + "/nixos/modules/misc/lib.nix")
(nixpkgs + "/nixos/modules/config/sysctl.nix")
pkgsModule
];
other = {
_module.check = true;
_module.args = { };
};
in
pkgs.lib.evalModules {
prefix = [ ];
modules =
modules
++ baseModules
++ [
pkgsModule
other
];
}

62
runit.nix Normal file
View file

@ -0,0 +1,62 @@
{
pkgs,
lib,
config,
...
}:
let
compat = pkgs.runCommand "runit-compat" { } ''
mkdir -p $out/bin/
cat << EOF > $out/bin/poweroff
#!/bin/sh
exec runit-init 0
EOF
cat << EOF > $out/bin/reboot
#!/bin/sh
exec runit-init 6
EOF
chmod +x $out/bin/{poweroff,reboot}
'';
in
{
environment.systemPackages = [ compat ];
environment.etc = lib.mkMerge [
{
"runit/1".source = pkgs.writeScript "1" ''
#!${pkgs.runtimeShell}
mkdir /bin/
ln -s ${pkgs.runtimeShell} /bin/sh
${lib.optionalString (config.networking.timeServers != [ ]) ''
${pkgs.ntp}/bin/ntpdate ${toString config.networking.timeServers}
''}
# disable DPMS on tty's
echo -ne "\033[9;0]" > /dev/tty0
touch /etc/runit/stopit
chmod 0 /etc/runit/stopit
'';
"runit/2".source = pkgs.writeScript "2" ''
#!${pkgs.runtimeShell}
exec runsvdir -P /etc/service
'';
"runit/3".source = pkgs.writeScript "3" ''
#!${pkgs.runtimeShell}
echo and down we go
'';
"service/nix-daemon/run".source = pkgs.writeScript "nix-daemon" ''
#!${pkgs.runtimeShell}
nix-daemon
'';
}
(lib.mkIf config.not-os.rngd {
"service/rngd/run".source = pkgs.writeScript "rngd" ''
#!${pkgs.runtimeShell}
export PATH=$PATH:${pkgs.rng-tools}/bin
exec rngd -r /dev/hwrng
'';
})
];
}

49
services/default.nix Normal file
View file

@ -0,0 +1,49 @@
{ lib, config, ... }:
let
cfg = config.runit;
in
{
options = {
runit.services = lib.mkOption {
type = lib.types.attrsOf (
lib.types.submodule {
run = lib.mkOption {
type = lib.types.string;
description = "The command to run. Equivalent to ExecStart in systemd";
};
check = lib.mkOption {
type = lib.types.optional lib.types.string;
description = "The command to run to check if the service is running.";
};
finish = lib.mkOption {
type = lib.types.optional lib.types.string;
description = "The command to run when the service is stopped.";
};
conf = lib.mkOption {
type = lib.types.optional lib.types.string;
description = "The command to run to configure the service.";
};
}
);
default = { };
};
};
config = {
environment.etc = lib.mkMerge lib.mapAttrsToList (
name: value:
{
"service/${name}/run".source = value.run;
}
// lib.optionalAttrs (value.check != null) {
"service/${name}/check".source = value.check;
}
// lib.optionalAttrs (value.finish != null) {
"service/${name}/finish".source = value.finish;
}
// lib.optionalAttrs (value.conf != null) {
"service/${name}/conf".source = value.conf;
}
) cfg.services;
};
}