This commit is contained in:
Nox Sluijtman 2023-10-20 14:19:31 +02:00
parent d45b12a9f6
commit 3f3cd0c357
8 changed files with 161 additions and 124 deletions

138
flake.nix
View file

@ -1,118 +1,38 @@
{
description = "An over-engineered Hello World in bash";
{ description = "A few random scripts";
inputs = {
nixpkgs.url = github:nixos/nixpkgs/nixos-23.05;
flake-utils.url = github:numtide/flake-utils;
};
outputs = { self, nixpkgs, flake-utils }:
flake-utils.lib.eachDefaultSystem ( system:
let pkgs = import nixpkgs { inherit system; };
in{
packages = rec {
default = pkgs.stdenvNoCC.mkDerivation rec {
pname = "irs";
version = "0.1";
# Nixpkgs / NixOS version to use.
inputs.nixpkgs.url = "nixpkgs/nixos-21.05";
src = ./src;
outputs = { self, nixpkgs }:
let
buildInputs = with pkgs; [
coreutils
scdoc
];
# to work with older version of flakes
lastModifiedDate = self.lastModifiedDate or self.lastModified or "19700101";
buildPhase = ''
# Generate a user-friendly version number.
version = builtins.substring 0 8 lastModifiedDate;
for page in $(find manpages -type f); do
scdoc < $page > $(basename $page .scd)
done
# System types to support.
supportedSystems = [ "x86_64-linux" "x86_64-darwin" "aarch64-linux" "aarch64-darwin" ];
# Helper function to generate an attrset '{ x86_64-linux = f "x86_64-linux"; ... }'.
forAllSystems = nixpkgs.lib.genAttrs supportedSystems;
# Nixpkgs instantiated for supported system types.
nixpkgsFor = forAllSystems (system: import nixpkgs { inherit system; overlays = [ self.overlay ]; });
in
{
# A Nixpkgs overlay.
overlay = final: prev: {
hello = with final; stdenv.mkDerivation rec {
name = "hello-${version}";
unpackPhase = ":";
installPhase =
''
mkdir -p $out/bin
cp hello $out/bin/
'';
};
'';
installPhase = ''
mkdir -p $out/{share/man/man1,bin}
cp bin/* $out/bin/
cp *.1 $out/share/man/man1
'';
};
# Provide some binary packages for selected system types.
packages = forAllSystems (system:
{
inherit (nixpkgsFor.${system}) hello;
});
# The default package for 'nix build'. This makes sense if the
# flake provides only one package or there is a clear "main"
# package.
defaultPackage = forAllSystems (system: self.packages.${system}.hello);
# A NixOS module, if applicable (e.g. if the package provides a system service).
nixosModules.hello =
{ pkgs, ... }:
{
nixpkgs.overlays = [ self.overlay ];
environment.systemPackages = [ pkgs.hello ];
#systemd.services = { ... };
};
# Tests run by 'nix flake check' and by Hydra.
checks = forAllSystems
(system:
with nixpkgsFor.${system};
{
inherit (self.packages.${system}) hello;
# Additional tests, if applicable.
test = stdenv.mkDerivation {
name = "hello-test-${version}";
buildInputs = [ hello ];
unpackPhase = "true";
buildPhase = ''
echo 'running some integration tests'
[[ $(hello) = 'Hello Nixers!' ]]
'';
installPhase = "mkdir -p $out";
};
}
// lib.optionalAttrs stdenv.isLinux {
# A VM test of the NixOS module.
vmTest =
with import (nixpkgs + "/nixos/lib/testing-python.nix") {
inherit system;
};
makeTest {
nodes = {
client = { ... }: {
imports = [ self.nixosModules.hello ];
};
};
testScript =
''
start_all()
client.wait_for_unit("multi-user.target")
client.succeed("hello")
'';
};
}
);
};
});
}