【问题标题】:How to add labels to NixOS generations如何为 NixOS 代添加标签
【发布时间】:2016-05-06 15:34:21
【问题描述】:

当我启动我的机器时,它会在列表中显示所有代,但将它们命名为“第 49 代”、“第 50 代”等。

有没有办法给世代添加标签,这样我以后可以很容易地看到发生了什么变化?我想要一个可选的提交消息之类的东西,所以它可能是“第 49 代 - 切换到 KDE5”、“第 50 代 - 切换回 gnome3”。

【问题讨论】:

    标签: nixos


    【解决方案1】:

    /boot/grub/grub.conf 当前构建于:

    nixos/modules/system/boot/loader/grub/install-grub.pl

    # Emit submenus for all system profiles.
    sub addProfile {
        my ($profile, $description) = @_;
    
        # Add entries for all generations of this profile.
        $conf .= "submenu \"$description\" {\n" if $grubVersion == 2;
    
        sub nrFromGen { my ($x) = @_; $x =~ /\/\w+-(\d+)-link/; return $1; }
    
        my @links = sort
            { nrFromGen($b) <=> nrFromGen($a) }
            (glob "$profile-*-link");
    
        my $curEntry = 0;
        foreach my $link (@links) {
            last if $curEntry++ >= $configurationLimit;
            my $date = strftime("%F", localtime(lstat($link)->mtime));
            my $version =
                -e "$link/nixos-version"
                ? readFile("$link/nixos-version")
                : basename((glob(dirname(Cwd::abs_path("$link/kernel")) . "/lib/modules/*"))[0]);
            addEntry("NixOS - Configuration " . nrFromGen($link) . " ($date - $version)", $link);
        }
    
        $conf .= "}\n" if $grubVersion == 2;
    }
    

    这是 grub.conf 中的单个条目:

    menuentry "NixOS - Configuration 38 (2016-01-29 - 16.03pre75806.77f8f35)" {
    search --set=drive1 --fs-uuid d931bd85-8f35-4ae9-a36b-c1ac51ad7b57
      linux ($drive1)//kernels/56fkcbxnwzi0kh6vg677a4cd4zcabm55-linux-4.1.15-bzImage systemConfig=/nix/store/2sybsl278s5a8kzhplwcz5jbhbsqwdci-nixos-system-lenovo-t530-16.03pre75806.77f8f35 init=/nix/store/2sybsl278s5a8kzhplwcz5jbhbsqwdci-nixos-system-lenovo-t530-16.03pre75806.77f8f35/init loglevel=4
      initrd ($drive1)//kernels/r33fajk0kaxlfmg922c2hy4rak5cj90z-initrd-initrd
    }
    

    然而,nixos-rebuild 支持 --profile-name,引用手册页:

       --profile-name, -p
           Instead of using the Nix profile /nix/var/nix/profiles/system to keep track of
           the current and previous system configurations, use
           /nix/var/nix/profiles/system-profiles/name. When you use GRUB 2, for every
           system profile created with this flag, NixOS will create a submenu named “NixOS
           - Profile 'name'” in GRUB’s boot menu, containing the current and previous
           configurations of this profile.
    
           For instance, if you want to test a configuration file named test.nix without
           affecting the default system profile, you would do:
    
               $ nixos-rebuild switch -p test -I nixos-config=./test.nix
    
           The new configuration will appear in the GRUB 2 submenu “NixOS - Profile
           'test'”.
    

    总结:希望这就是你要找的。​​strong>

    【讨论】:

    • 这似乎是我想要的。但是,我不再使用 NixOS,因此无法验证您的答案。
    • 我认为这不是他要找的东西。据我了解,这些配置文件名称就像单代分支。他想要的是在树干上标记所有世代。 (我也是)
    【解决方案2】:

    NIXOS_LABEL="changed-some-settings" nixos-rebuild switch

    【讨论】:

      【解决方案3】:

      system.nixos.label

      您可以在配置或环境中设置它(使用NIXOS_LABEL)。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2010-09-05
        • 2021-05-16
        • 2012-12-18
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多