WIP
This commit is contained in:
27
flake.lock
generated
Normal file
27
flake.lock
generated
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
{
|
||||||
|
"nodes": {
|
||||||
|
"nixpkgs": {
|
||||||
|
"locked": {
|
||||||
|
"lastModified": 1696419054,
|
||||||
|
"narHash": "sha256-EdR+dIKCfqL3voZUDYwcvgRDOektQB9KbhBVcE0/3Mo=",
|
||||||
|
"owner": "nixos",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"rev": "7131f3c223a2d799568e4b278380cd9dac2b8579",
|
||||||
|
"type": "github"
|
||||||
|
},
|
||||||
|
"original": {
|
||||||
|
"owner": "nixos",
|
||||||
|
"ref": "nixpkgs-unstable",
|
||||||
|
"repo": "nixpkgs",
|
||||||
|
"type": "github"
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": {
|
||||||
|
"inputs": {
|
||||||
|
"nixpkgs": "nixpkgs"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"root": "root",
|
||||||
|
"version": 7
|
||||||
|
}
|
||||||
41
flake.nix
41
flake.nix
@@ -1,7 +1,14 @@
|
|||||||
{
|
{
|
||||||
description = "A very basic flake";
|
description = "A very basic flake";
|
||||||
|
|
||||||
outputs = { self, nixpkgs }: {
|
#nixpkgs for testing framework
|
||||||
|
inputs.nixpkgs.url = "github:nixos/nixpkgs/nixpkgs-unstable";
|
||||||
|
|
||||||
|
outputs = { self, nixpkgs, ... }: let
|
||||||
|
# expose systems for `x86_64-linux` and `aarch64-linux`
|
||||||
|
forAllSystems = nixpkgs.lib.genAttrs [ "x86_64-linux" ];
|
||||||
|
in
|
||||||
|
{
|
||||||
|
|
||||||
packages.x86_64-linux.tasklist = nixpkgs.legacyPackages.x86_64-linux.buildGoModule rec {
|
packages.x86_64-linux.tasklist = nixpkgs.legacyPackages.x86_64-linux.buildGoModule rec {
|
||||||
pname = "tasklist";
|
pname = "tasklist";
|
||||||
@@ -10,25 +17,26 @@
|
|||||||
src = ./.;
|
src = ./.;
|
||||||
};
|
};
|
||||||
|
|
||||||
nixosModules.malobeo-tasklist = { config, ... }:
|
nixosModules.malobeo-tasklist = { config, lib, pkgs, ... }:
|
||||||
let
|
let
|
||||||
cfg = config.services.malobeo-tasklist;
|
cfg = config.services.malobeo-tasklist;
|
||||||
tasklist-pkg = self.packages.x86_64-linux.tasklist;
|
tasklist-pkg = self.packages.x86_64-linux.tasklist;
|
||||||
|
pkgs = nixpkgs.legacyPackages."x86_64-linux";
|
||||||
in
|
in
|
||||||
{
|
{
|
||||||
options = {
|
options = {
|
||||||
services.malobeo-tasklist = {
|
services.malobeo-tasklist = {
|
||||||
enable = nixpkgs.lib.mkOption {
|
enable = lib.mkOption {
|
||||||
default = false;
|
default = false;
|
||||||
type = nixpkgs.types.bool;
|
type = lib.types.bool;
|
||||||
description = nixpkgs.lib.mdDoc ''
|
description = lib.mdDoc ''
|
||||||
Enables tasklist
|
Enables tasklist
|
||||||
'';
|
'';
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
config = nixpkgs.lib.mkIf cfg.enable {
|
config = lib.mkIf cfg.enable {
|
||||||
environment.systemPackages = [ tasklist-pkg ];
|
environment.systemPackages = [ tasklist-pkg ];
|
||||||
|
|
||||||
users.users = {
|
users.users = {
|
||||||
@@ -47,14 +55,33 @@
|
|||||||
Restart = "on-failure";
|
Restart = "on-failure";
|
||||||
};
|
};
|
||||||
|
|
||||||
|
preStart = ''
|
||||||
|
mkdir -m 0770 -p "/var/lib/malobeo-tasklist"
|
||||||
|
cp ${tasklist-pkg}/forms.html /var/lib/malobeo-tasklist
|
||||||
|
chmod -R 0770 /var/lib/malobeo-tasklist
|
||||||
|
'';
|
||||||
|
#chown "malobeo-tasklist:malobeo-tasklist" "/var/lib/malobeo-tasklist"
|
||||||
|
|
||||||
wantedBy = [ "default.target" ];
|
wantedBy = [ "default.target" ];
|
||||||
|
|
||||||
environment = {
|
environment = {
|
||||||
USER = "malobeo-tasklist";
|
USER = "malobeo-tasklist";
|
||||||
HOME = /var/lib/malobeo-tasklist;
|
HOME = "/var/lib/malobeo-tasklist";
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
|
checks = forAllSystems (system: let
|
||||||
|
checkArgs = {
|
||||||
|
# reference to nixpkgs for the current system
|
||||||
|
pkgs = nixpkgs.legacyPackages.${system};
|
||||||
|
# this gives us a reference to our flake but also all flake inputs
|
||||||
|
inherit self;
|
||||||
|
};
|
||||||
|
in {
|
||||||
|
# import our test
|
||||||
|
malobeo-tasklist = import ./test.nix checkArgs;
|
||||||
|
});
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
20
lib.nix
Normal file
20
lib.nix
Normal file
@@ -0,0 +1,20 @@
|
|||||||
|
# tests/lib.nix
|
||||||
|
# The first argument to this function is the test module itself
|
||||||
|
test:
|
||||||
|
# These arguments are provided by `flake.nix` on import, see checkArgs
|
||||||
|
{ pkgs, self}:
|
||||||
|
let
|
||||||
|
inherit (pkgs) lib;
|
||||||
|
# this imports the nixos library that contains our testing framework
|
||||||
|
nixos-lib = import (pkgs.path + "/nixos/lib") {};
|
||||||
|
in
|
||||||
|
(nixos-lib.runTest {
|
||||||
|
hostPkgs = pkgs;
|
||||||
|
# This speeds up the evaluation by skipping evaluating documentation (optional)
|
||||||
|
defaults.documentation.enable = lib.mkDefault false;
|
||||||
|
# This makes `self` available in the NixOS configuration of our virtual machines.
|
||||||
|
# This is useful for referencing modules or packages from your own flake
|
||||||
|
# as well as importing from other flakes.
|
||||||
|
node.specialArgs = { inherit self; };
|
||||||
|
imports = [ test ];
|
||||||
|
}).config.result
|
||||||
22
test.nix
Normal file
22
test.nix
Normal file
@@ -0,0 +1,22 @@
|
|||||||
|
# ./tests/hello-world-server.nix
|
||||||
|
(import ./lib.nix) {
|
||||||
|
name = "from-nixos";
|
||||||
|
nodes = {
|
||||||
|
# `self` here is set by using specialArgs in `lib.nix`
|
||||||
|
node1 = { self, pkgs, ... }: {
|
||||||
|
imports = [ self.nixosModules.malobeo-tasklist ];
|
||||||
|
|
||||||
|
services.malobeo-tasklist.enable = true;
|
||||||
|
environment.systemPackages = [ pkgs.curl ];
|
||||||
|
};
|
||||||
|
};
|
||||||
|
# This is the test code that will check if our service is running correctly:
|
||||||
|
testScript = ''
|
||||||
|
start_all()
|
||||||
|
# wait for our service to start
|
||||||
|
node1.wait_for_unit("malobeo-tasklist")
|
||||||
|
output = node1.succeed("curl localhost:8000/index.html")
|
||||||
|
# Check if our webserver returns the expected result
|
||||||
|
assert "Hello world" in output, f"'{output}' does not contain 'Hello world'"
|
||||||
|
'';
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user